usr

Modulate your userpace into POSIX-compliant shell scripts!
git clone git://clone.theohenson.com/usr.git
Log | Files | Refs | README

commit df785ab7a94f4cb80d4a6f6c0b6b0ab4ec7993df
parent 97671611794c7a4a3909fa4774753ee34cbfd9ca
Author: Theo Henson <[email protected]>
Date:   Fri, 18 Dec 2020 12:29:20 -0500

Improve scripts

Diffstat:
Mhome/.local/bin/opt/autorss | 3++-
Mhome/.local/bin/opt/cpusage | 7++++---
Mhome/.local/bin/opt/git_status_prompt | 28++++++++++++++--------------
Mhome/.local/bin/opt/lock | 2+-
Mhome/.local/bin/opt/lsearch | 6+++---
Mhome/.local/bin/opt/openup | 1+
Mhome/.local/bin/opt/randwall | 12++++++------
Mhome/.local/bin/opt/range | 6+++++-
Mhome/.local/bin/opt/runt | 3++-
Mhome/.local/bin/opt/spt-mute.sh | 5+++--
Mhome/.local/bin/opt/spt-vol.sh | 5+++--
Mhome/.local/bin/opt/time_bar | 4++--
Mhome/.local/bin/opt/tku | 9+++++++--
Mhome/.local/bin/opt/volume_bar | 8++++----
14 files changed, 57 insertions(+), 42 deletions(-)

diff --git a/home/.local/bin/opt/autorss b/home/.local/bin/opt/autorss @@ -1,7 +1,8 @@ #!/bin/sh +# Updates my RSS reader and sends a notification if there are new articles newsboat -x reload -MSG=`newsboat -x print-unread` +msg=`newsboat -x print-unread` if [[ `echo $MSG | awk '{print $1}'` -gt 0 ]]; then notify-send -a "newsboat" "updated rss" "$MSG" fi diff --git a/home/.local/bin/opt/cpusage b/home/.local/bin/opt/cpusage @@ -1,9 +1,10 @@ #!/bin/sh +# Prints the current CPU usage -USAGE=$(top -bn1 | grep "Cpu(s)" | \ +usage=$(top -bn1 | grep "Cpu(s)" | \ sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | \ awk '{print 100 - $1}') -NUM=$(echo "$USAGE" | sed "s/\..*//") +num=$(echo "$usage" | sed "s/\..*//") -echo "$NUM%" +echo "$num%" diff --git a/home/.local/bin/opt/git_status_prompt b/home/.local/bin/opt/git_status_prompt @@ -1,24 +1,24 @@ #!/bin/sh # Prints git information for my shell prompt -PROMPT="$" -WORKING="$(git rev-parse --is-inside-work-tree 2>/dev/null)" +prompt="$" +working="$(git rev-parse --is-inside-work-tree 2>/dev/null)" -if [ "$WORKING" ]; then - STATUS="$(git status -s)" - COLOR="\033[92m" - COMMIT="" - if [ "$STATUS" ]; then - COLOR="\033[91m" +if [ "$working" ]; then + status="$(git status -s)" + color="\033[92m" + commit="" + if [ "$status" ]; then + color="\033[91m" fi - COMMIT="$(git status | grep ahead)" - if [ "$COMMIT" ]; then - PROMPT="λ" + commit="$(git status | grep ahead)" + if [ "$commit" ]; then + prompt="λ" fi - BRANCH=$(git branch --no-color --show-current) - printf "${COLOR}$BRANCH \033[38;2;142;192;124m$PROMPT\033[0m " + branch=$(git branch --no-color --show-current) + printf "${color}$branch \033[38;2;142;192;124m$prompt\033[0m " else - printf "\033[38;2;142;192;124m$PROMPT\033[0m " + printf "\033[38;2;142;192;124m$prompt\033[0m " fi diff --git a/home/.local/bin/opt/lock b/home/.local/bin/opt/lock @@ -1,5 +1,5 @@ #!/bin/sh -# Locks my screen with i3lock +# Locks my screen with i3lock-color xargs i3lock -e \ --ringvercolor=45858888 \ diff --git a/home/.local/bin/opt/lsearch b/home/.local/bin/opt/lsearch @@ -1,8 +1,8 @@ #!/bin/sh # Script to easily do a web search with lynx -URL='lynx -vikeys -accept_all_cookies https://lite.duckduckgo.com/lite/?q=' +url='lynx -vikeys -accept_all_cookies https://lite.duckduckgo.com/lite/?q=' -SEARCH=$(echo [email protected] | sed 's/ /+/g') +search=$(echo [email protected] | sed 's/ /+/g') -eval "$URL$SEARCH" +eval "$url$search" diff --git a/home/.local/bin/opt/openup b/home/.local/bin/opt/openup @@ -1,3 +1,4 @@ #!/bin/sh +# Opens a file from $PATH in $EDITOR $EDITOR $(which $1) diff --git a/home/.local/bin/opt/randwall b/home/.local/bin/opt/randwall @@ -1,16 +1,16 @@ -#!/bin/bash +#!/bin/sh # Sets my wallpaper to a random image in my wallpaper directory -OLD=$(<$XDG_CACHE_HOME/oldwall) +old=$(cat "$XDG_CACHE_HOME"/oldwall) get_file () { - NEW=$(find $XDG_PICTURES_DIR/wall -type f -name "*" | shuf -n 1) + new=$(find "$XDG_PICTURES_DIR"/wall -type f -name '*' | shuf -n 1) } get_file -while [ "$OLD" = "$NEW" ]; do +while [ "$old" = "$new" ]; do get_file done -feh --no-fehbg --bg-fill $NEW -echo $NEW > $XDG_CACHE_HOME/oldwall +feh --no-fehbg --bg-fill "$new" +echo "$new" > "$XDG_CACHE_HOME"/oldwall diff --git a/home/.local/bin/opt/range b/home/.local/bin/opt/range @@ -1,12 +1,16 @@ #!/usr/bin/env python3 +# Acts like the Python range() function, but on the command-line + import sys if len(sys.argv) < 3: - print("bad args, run like this: {} <lower> <upper> [skip]".format(sys.argv[0])) + print('bad args, run like this: {} <lower> <upper> [skip]'.format(sys.argv[0])) exit(1) + elif len(sys.argv) > 3: for i in range(int(sys.argv[1]), int(sys.argv[2]), int(sys.argv[3])): print(i) + else: for i in range(int(sys.argv[1]), int(sys.argv[2])): print(i) diff --git a/home/.local/bin/opt/runt b/home/.local/bin/opt/runt @@ -1,5 +1,6 @@ #!/bin/sh -# Script to run commands many times +# Script to run a command a certain ammount of times (useful for benchmarking like 'time runt <command>') + j=1 while [ $j -le $1 ]; do $2 diff --git a/home/.local/bin/opt/spt-mute.sh b/home/.local/bin/opt/spt-mute.sh @@ -1,11 +1,12 @@ -#!/bin/bash +#!/bin/sh +# Mutes spotifyd app_name="librespot" current_sink_num='' sink_num_check='' app_name_check='' -pactl list sink-inputs |while read line; do \ +pactl list sink-inputs | while read -r line; do \ sink_num_check=$(echo "$line" |sed -rn 's/^Sink Input #(.*)/\1/p') if [ "$sink_num_check" != "" ]; then current_sink_num="$sink_num_check" diff --git a/home/.local/bin/opt/spt-vol.sh b/home/.local/bin/opt/spt-vol.sh @@ -1,11 +1,12 @@ -#!/bin/bash +#!/bin/sh +# Changes spotifyd's volume app_name="librespot" current_sink_num='' sink_num_check='' app_name_check='' -pactl list sink-inputs |while read line; do \ +pactl list sink-inputs | while read -r line; do \ sink_num_check=$(echo "$line" |sed -rn 's/^Sink Input #(.*)/\1/p') if [ "$sink_num_check" != "" ]; then current_sink_num="$sink_num_check" diff --git a/home/.local/bin/opt/time_bar b/home/.local/bin/opt/time_bar @@ -1,6 +1,6 @@ #!/bin/sh # Prints time/date information for dwmblocks -TIME=$(date +"%I:%M %m.%d.%y") +time=$(date +"%I:%M %m.%d.%y") -echo "$TIME" +echo "$time" diff --git a/home/.local/bin/opt/tku b/home/.local/bin/opt/tku @@ -1,5 +1,10 @@ #!/bin/sh -# Kills all tmux sessions that are not currently attached to +# Kills all tmux sessions that are not currently attached to and have a number as a name + tmux list-sessions | grep -v attached | while read -r session; do - tmux kill-session -t "${session%%:*}" + name="${session%%:*}" + case $name in + (*[!0-9]*|'') ;; + (*) tmux kill-session -t "$name" ;; + esac done diff --git a/home/.local/bin/opt/volume_bar b/home/.local/bin/opt/volume_bar @@ -1,8 +1,8 @@ #!/bin/sh # Prints volume information for dwmblocks -VOL=$(amixer -D pulse sget Master | grep 'Mono:' | awk -F'[][]' '{ print $2 }') -if ["$VOL" -eq ""]; then - VOL=$(amixer -D pulse sget Master | grep 'Left:' | awk -F'[][]' '{ print $2 }') +vol=$(amixer -D pulse sget Master | grep 'Mono:' | awk -F'[][]' '{ print $2 }') +if ["$vol" -eq ""]; then + vol=$(amixer -D pulse sget Master | grep 'Left:' | awk -F'[][]' '{ print $2 }') fi -echo "$VOL" +echo "$vol"