add scripts

This commit is contained in:
frosty 2024-06-23 06:44:57 -04:00
parent 4ca7658494
commit 63c0674445
17 changed files with 407 additions and 0 deletions

14
.local/bin/cpumon Executable file
View file

@ -0,0 +1,14 @@
#!/bin/sh
initial_values=$(awk '/cpu /{print $2+$4,$2+$4+$5}' /proc/stat)
sleep 2
current_values=$(awk '/cpu /{print $2+$4,$2+$4+$5}' /proc/stat)
set -- $initial_values
initial_user_sys=$1
initial_total=$2
set -- $current_values
current_user_sys=$1
current_total=$2
awk "BEGIN {print ($current_user_sys - $initial_user_sys) / ($current_total - $initial_total) * 100}"

7
.local/bin/diskusage Executable file
View file

@ -0,0 +1,7 @@
#!/bin/sh
location=${1:-/}
[ -d "$location" ] || exit
df -h "$location" | awk ' /[0-9]/ {print $3 "/" $2}'

111
.local/bin/epicshot Executable file
View file

@ -0,0 +1,111 @@
#!/bin/sh
# Copyright (c) 2024 frosty <passedgoandgot200@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
set -eu
VERSION="1.0.0"
# shellcheck disable=SC1091
[ -f "${XDG_CONFIG_HOME:-$HOME/.config}/user-dirs.dirs" ] && . "${XDG_CONFIG_HOME:-$HOME/.config}/user-dirs.dirs"
OUTPUT_DIRECTORY=${XDG_SCREENSHOTS_DIR:-${XDG_PICTURES_DIR:-$HOME}}
FILENAME_BASE="screenshot"
FILENAME_DATE_FORMAT="%Y-%m-%d_%H-%M-%S"
QUIET=
COPY=
OVERLAY=
SAVE=
err() {
echo "$@" >&2
}
die() {
err "${0##*/}: $1"
exit 1
}
notify() {
notify-send "${0##*/}" "$@"
}
screenshot_select() {
maim -qsu "$@"
}
screenshot_full() {
maim -qu "$@"
}
usage() {
err "usage: ${0##*/} [-hVqcos] [TYPE] [FILE]"
err
err " -h show this message and exit"
err " -V show version information and exit"
err " -q suppress program output"
err " -c copy image to clipboard"
err " -o overlay image on screen"
err " -s save image to disk"
}
version() {
err "${0##*/} v$VERSION"
err
err "Copyright (c) 2024 frosty <passedgoandgot200@gmail.com>"
err
err "This program is free software: you can redistribute it and/or modify"
err "it under the terms of the GNU General Public License as published by"
err "the Free Software Foundation, either version 3 of the License, or"
err "(at your option) any later version."
}
while getopts :hVqcos opt; do
case "$opt" in
h) usage; exit 0 ;;
V) version; exit 0 ;;
q) QUIET=1 ;;
c) COPY=1 ;;
o) OVERLAY=1 ;;
s) SAVE=1 ;;
*) die "invalid option: -$OPTARG" ;;
esac
done
shift $((OPTIND - 1))
SCREENSHOT_TYPE=${1:-select}
FILE_PATH=${2:-}
case "$SCREENSHOT_TYPE" in
select|full) ;;
*) usage; exit 1 ;;
esac
if [ -n "$SAVE" ]; then
FILE_PATH=${FILE_PATH:-$OUTPUT_DIRECTORY/$FILENAME_BASE-$(date "+$FILENAME_DATE_FORMAT").png}
else
FILE_PATH="/tmp/${0##*/}-$(date '+%s').png"
fi
screenshot_"$SCREENSHOT_TYPE" "$FILE_PATH" || exit 0
[ -z "$QUIET" ] && notify "Screenshot taken"
[ -n "$COPY" ] && xclip -sel clip -t image/png "$FILE_PATH"
[ -n "$OVERLAY" ] && feh --class no-decor -x "$FILE_PATH"
[ -z "$SAVE" ] && rm "$FILE_PATH"

39
.local/bin/genbar Executable file
View file

@ -0,0 +1,39 @@
#!/bin/sh
LOW_USED_COLOR="#b8bb26"
MEDIUM_USED_COLOR="#fabd2f"
HIGH_USED_COLOR="#fb4934"
DEFAULT_USED_COLOR="#d5c4a1"
UNUSED_COLOR="#a88984"
usage=$1
width=$2
usage_color=$3
command -v "$1" >/dev/null && usage=$($1)
low_used=$((width * 30 / 100))
medium_used=$((width * 60 / 100))
num_used_chars=$(echo "scale=0; ($usage * $width) / 100" | bc -l)
if [ -n "$usage_color" ]; then
case "$num_used_chars" in
[0-$low_used]) used_color="$LOW_USED_COLOR" ;;
[$low_used-$medium_used]) used_color="$MEDIUM_USED_COLOR" ;;
*) used_color="$HIGH_USED_COLOR" ;;
esac
else
used_color="$DEFAULT_USED_COLOR"
fi
i=1
while [ "$i" -le "$width" ]; do
if [ "$i" -le "$num_used_chars" ]; then
bar="$bar<fc=$used_color>#</fc>"
else
bar="$bar<fc=$UNUSED_COLOR>:</fc>"
fi
i=$((i + 1))
done
echo "$bar"

8
.local/bin/initialize_pipes Executable file
View file

@ -0,0 +1,8 @@
#!/bin/sh
PIPES="nowplaying volume"
for pipe in $PIPES; do
echo "" >"/tmp/pipe-$pipe"
pipe_"$pipe" &
done

8
.local/bin/memmon Executable file
View file

@ -0,0 +1,8 @@
#!/bin/sh
total_mem=$(($(grep MemTotal /proc/meminfo | awk '{print $2}') / 1024))
free_mem=$(($(grep MemAvailable /proc/meminfo | awk '{print $2}') / 1024))
used_mem=$((total_mem - free_mem))
awk "BEGIN {print ($used_mem / $total_mem) * 100}"

3
.local/bin/nowplaying Executable file
View file

@ -0,0 +1,3 @@
#!/bin/sh
playerctl metadata | sed -nE 's/^.*xesam:albumArtist +([^ ]+.*)$/\1/p; s/^.*xesam:title +([^ ].*)$/ - \1/p' | tr -d '\n'

8
.local/bin/pipe_nowplaying Executable file
View file

@ -0,0 +1,8 @@
#!/bin/sh
TEXT_COLOR="#fe8019"
PIPE_FILE="/tmp/pipe-nowplaying"
[ -p "$PIPE_FILE" ] || mkfifo "$PIPE_FILE"
playerctl metadata --format "<fc=$TEXT_COLOR>{{artist}} - {{title}}</fc>" >"$PIPE_FILE"

7
.local/bin/pipe_volume Executable file
View file

@ -0,0 +1,7 @@
#!/bin/sh
PIPE_FILE="/tmp/pipe-volume"
[ -p "$PIPE_FILE" ] || mkfifo "$PIPE_FILE"
volume=$(wpctl get-volume @DEFAULT_AUDIO_SINK@ | awk '/Volume/ { print int($NF * 100) }')
genbar "$volume" 10 1 >"$PIPE_FILE"

9
.local/bin/run-i3lock Executable file
View file

@ -0,0 +1,9 @@
#!/bin/sh
die() {
echo "${0##*/}: $1" >&2
exit 1
}
[ -f "$XDG_CACHE_HOME/lock.png" ] || die "file not found"
i3lock -i "$XDG_CACHE_HOME/lock.png"

89
.local/bin/screenlayout Executable file
View file

@ -0,0 +1,89 @@
#!/bin/sh
err() {
echo "$1" >&2
}
die() {
err "${0##*/}: $1"
exit 1
}
usage() {
if [ -n "$1" ]; then
err "${0##*/}: $1"
err
fi
err "usage: ${0##*/} [-hqrde] SCRIPT"
err
err " -h show this message and exit"
err " -q suppress output and notifications"
err " -r restore the previous script as your screen layout"
err " -d reset screen layout to X default"
err " -e edit previous screen layout script in your EDITOR"
exit 0
}
restore() {
[ -f "$XDG_DATA_HOME/screenlayout" ] || die "previous script not found"
. "$XDG_DATA_HOME/screenlayout"
exit 0
}
default() {
xrandr --auto
[ -z "$QUIET" ] && notify-send -u low "System" "Screen layout set to default."
exit 0
}
edit() {
[ -z "$EDITOR" ] && die "\$EDITOR is not set"
[ -f "$XDG_DATA_HOME/screenlayout" ] || die "previous script not found"
$EDITOR "$XDG_DATA_HOME/screenlayout"
exit 0
}
while getopts ":hqrde" opt; do
case $opt in
h) usage ;;
q) QUIET=1 ;;
r) restore ;;
d) default ;;
e) edit ;;
\?) usage "invalid option -- '$OPTARG'" ;;
:) usage "option requires an argument -- '$OPTARG'" ;;
esac
done
shift $((OPTIND - 1))
if [ "$1" = "-" ]; then
while IFS= read -r line; do
script="$line"
done
else
script="$1"
fi
[ -n "$script" ] || usage "SCRIPT was not provided"
[ -d "$script" ] && die "$script: is a directory"
[ -f "$script" ] || die "$script: no such file"
case "$(file -b --mime-type "$script")" in
text/x-shellscript) ;;
*) die "$script: unsupported file type" ;;
esac
ln -sf "$script" "$XDG_DATA_HOME/screenlayout"
. "$XDG_DATA_HOME/screenlayout"
[ -z "$QUIET" ] && notify-send -u low "System" "Screen layout set to <b>${script##*/}</b>."

3
.local/bin/screenlayouts-open Executable file
View file

@ -0,0 +1,3 @@
#!/bin/sh
find "$HOME/.local/bin/screenlayouts" -type f | rofi -dmenu -p screenlayout | screenlayout -

View file

@ -0,0 +1,5 @@
#!/bin/sh
xrandr \
--output eDP-1 --off \
--output HDMI-2 --primary --mode 1920x1080 --pos 0x0 --rotate normal

3
.local/bin/uppretty Executable file
View file

@ -0,0 +1,3 @@
#!/bin/sh
uptime -p | sed 's/up //; s/,//g'

3
.local/bin/volmon Executable file
View file

@ -0,0 +1,3 @@
#!/bin/sh
wpctl get-volume @DEFAULT_AUDIO_SINK@ | awk '/Volume/ { print int($NF * 100) }'

87
.local/bin/wallpaper Executable file
View file

@ -0,0 +1,87 @@
#!/bin/sh
LOCK_RESOLUTION="1920x1080"
LOCK_QUALITY=70
err() {
echo "$1" >&2
}
die() {
err "${0##*/}: $1"
exit 1
}
usage() {
if [ -n "$1" ]; then
err "${0##*/}: $1"
err
fi
err "usage: ${0##*/} [-hqr] [-e RESOLUTION] [-u QUALITY] IMAGE"
err
err " -h show this message and exit"
err " -q suppress output and notifications"
err " -r restore the previous image as your wallpaper"
err " -e <RESOLUTION> override lock screen RESOLUTION"
err " -u <QUALITY> override lock screen QUALITY"
exit 0
}
convert_lock() {
magick "$1" -resize "$LOCK_RESOLUTION"^ -gravity center -extent "$LOCK_RESOLUTION" -quality "$LOCK_QUALITY" "$XDG_CACHE_HOME/lock.png"
}
restore() {
[ -f "$XDG_DATA_HOME/wallpaper" ] || die "previous image not found"
previous="$(readlink -f "$XDG_DATA_HOME/wallpaper")"
case "${previous##*.}" in
png|jpg|jpeg) ;;
*) die "$previous: unsupported file type" ;;
esac
cmp -s "$previous" "$XDG_CACHE_HOME/lock.png" || convert_lock "$previous" &
xwallpaper --zoom "$XDG_DATA_HOME/wallpaper"
exit 0
}
while getopts ":hqre:u:" opt; do
case $opt in
h) usage ;;
q) QUIET=1 ;;
r) restore ;;
e) LOCK_RESOLUTION="$OPTARG" ;;
u) LOCK_QUALITY="$OPTARG" ;;
\?) usage "invalid option -- '$OPTARG'" ;;
:) usage "option requires an argument -- '$OPTARG'" ;;
esac
done
shift $((OPTIND - 1))
if [ "$1" = "-" ]; then
while IFS= read -r line; do
image="$line"
done
else
image="$1"
fi
[ -n "$image" ] || usage "IMAGE was not provided"
[ -d "$image" ] && die "$image: is a directory"
[ -f "$image" ] || die "$image: no such file"
case "${image##*.}" in
png|jpg|jpeg) ;;
*) die "$image: unsupported file type" ;;
esac
cmp -s "$image" "$XDG_CACHE_HOME/lock.png" || convert_lock "$image" &
ln -sf "$image" "$XDG_DATA_HOME/wallpaper"
xwallpaper --zoom "$XDG_DATA_HOME/wallpaper"
[ -z "$QUIET" ] && notify-send -u low "System" "Wallpaper set to <b>${image##*/}</b>."

3
.local/bin/wallpapers-open Executable file
View file

@ -0,0 +1,3 @@
#!/bin/sh
find "$HOME/pictures/wallpapers" -type f \( -name '*.png' -o -name '*.jpg' -o -name '*.jpeg' \) | shuf | nsxiv -iot | wallpaper -