scripts

Various scripts for UNIX-like systems
git clone https://git.tronto.net/scripts
Download | Log | Files | Refs | README

commit 581865ee0c8b8aea872f053d804a41fb5f416b17
parent c5d101ab2c9db3b1a001cb56953cb90b24f8fdcf
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Tue, 20 Jun 2023 23:01:09 +0200

Various shellcheck fixes (www.shellcheck.net)

Diffstat:
MTODO | 2++
Mbattery-checknow | 6+++---
Mclip | 31+++++++++++++++++++++----------
Mconfig-backup | 16++++++++--------
Mcth | 2+-
Mdmenu-bookmarks | 2+-
Mdmenu-dwm-sessionmanager | 16+++++++++++++---
Mdmenu-filepicker | 13+++++++++++--
Mdmenu-mail-aliases | 15++++++++++++---
Mdmenu-screenshot | 18+++++++++++++-----
Mdmenu-unmount | 17+++++++++++++----
Mdmenu-urlselect | 13+++++++++++--
Mdmenu-websearch | 2+-
Mffmpeg-screenrecord | 2+-
Mmail-compose | 2+-
Mmergepdf | 12++++++++++--
Mnotify | 1+
Mopen-file | 24+++++++++++++++++-------
Mopen-stdin | 2+-
Mopen-url | 11++++-------
Mpopup-cal12 | 2+-
Mpopup-terminal | 2+-
Msel | 37++++++++++++++++++++++++++++---------
Msfeed-browser | 29+++++++++++++++++++----------
Mshare | 8++++----
Mstatus | 8++++----
Mterminal | 2+-
Mtranslate | 2+-
Mtrash | 19++++++++++++-------
Mvirename | 6+++---
Mxedit | 2+-
Mxedit-filter | 2+-
Mxplumb | 10+++++-----
Mxwallpaper-random-notify | 6+++---
34 files changed, 229 insertions(+), 113 deletions(-)

diff --git a/TODO b/TODO @@ -3,6 +3,8 @@ * Refactor: review all scripts and adapt to common style Configuration file (read only at "make" time) for default apps etc.. +* Replace ls with find + * Find a proper copy-left license * add -- when dealing with files (sel, open-file, trash...) diff --git a/battery-checknow b/battery-checknow @@ -12,10 +12,10 @@ new=$(battery-status) level=$(echo "$new" | sed 's/%.*//') status=$(echo "$new" | awk '{print $2}') -[ "$status" = "Discharging" ] && [ $level -le $low ] && status="Low" -[ "$status" = "Discharging" ] && [ $level -le $crit ] && status="Critical" +[ "$status" = "Discharging" ] && [ "$level" -le "$low" ] && status="Low" +[ "$status" = "Discharging" ] && [ "$level" -le "$crit" ] && status="Critical" -if [ "$status" != "$(cat $file)" ] || [ "$status" = "Critical" ]; then +if [ "$status" != "$(cat "$file")" ] || [ "$status" = "Critical" ]; then $notify "Battery" "$(battery-status)" fi diff --git a/clip b/clip @@ -13,40 +13,51 @@ menu="dmenu -i -l 25" +usage() { + echo "Usage: clip [-m MENU]" +} + while getopts "m:" opt; do case "$opt" in m) menu="$OPTARG" ;; + *) + usage + exit 1 + ;; esac done -shift `expr $OPTIND - 1` +shift "$((OPTIND - 1))" dir="/tmp/clipdir" mkdir -p "$dir" -file1="$(mktemp -p $dir $(date +%s).XXXXX)" -file2="$(mktemp -p $dir $(date +%s)b.XXXX)" +file1="$(mktemp -p "$dir" "$(date +%s)".XXXXX)" +file2="$(mktemp -p "$dir" "$(date +%s)"b.XXXX)" +echo "created $file1" +echo "created $file2" xsel > "$file1" xsel -b > "$file2" # Avoid duplicates -for f in $dir/*; do +for f in "$dir"/*; do [ "$f" != "$file1" ] && if diff "$f" "$file1"; then rm "$file1"; fi [ "$f" != "$file2" ] && if diff "$f" "$file2"; then rm "$file2"; fi done list="$(mktemp)" -ls $dir > $list; +ls "$dir" > "$list"; lines="$(mktemp)" -for f in $dir/*; do - nlines=$(expr 1 + "$(wc -l $f | awk '{print $1}')") - fclean=$(echo $f | sed "s|$dir\/||") - printf "$fclean ($nlines) | $(head -n 1 $f)\n" >> "$lines" +for f in "$dir"/*; do + nlines="$(wc -l "$f" | awk '{print $1}')" + fclean="$(echo "$f" | sed "s|$dir\/||")" + printf '%s (%s) | %s\n' \ + "$fclean" "$((1+nlines))" "$(head -n 1 "$f")" >> "$lines" done -selected=$(sort -r $lines | $menu | awk '{print $1}') +selected=$(sort -r "$lines" | $menu | awk '{print $1}') if [ -n "$selected" ]; then xsel -ib < "$dir/$selected" fi diff --git a/config-backup b/config-backup @@ -9,19 +9,19 @@ config="colors fontconfig git imv msmtp zathura" src="dmenu dwm st st-lightbg" share="gmni" -mkdir -p $folder/config $folder/home $folder/share $folder/src +mkdir -p "$folder"/config "$folder"/home "$folder"/share "$folder"/src # copy -for i in $dotfiles; do cp -Rf $HOME/$i $folder/home/; done -for i in $config; do cp -Rf $HOME/.config/$i $folder/config/; done -for i in $src; do cp -Rf $HOME/.local/src/$i $folder/src/; done -for i in $share; do cp -Rf $HOME/.local/share/$i $folder/share/; done +for i in $dotfiles; do cp -Rf "$HOME"/"$i" "$folder"/home/; done +for i in $config; do cp -Rf "$HOME"/.config/"$i" "$folder"/config/; done +for i in $src; do cp -Rf "$HOME"/.local/src/"$i" "$folder"/src/; done +for i in $share; do cp -Rf "$HOME"/.local/share/"$i" "$folder"/share/; done # redact -rm $folder/config/git/credentials +rm "$folder"/config/git/credentials sed 's/^password .*/password REDACTED/' \ - < $folder/config/msmtp/config > $folder/config/msmtp/config.redacted -rm $folder/config/msmtp/config + < "$folder"/config/msmtp/config > "$folder"/config/msmtp/config.redacted +rm "$folder"/config/msmtp/config diff --git a/cth b/cth @@ -5,4 +5,4 @@ name=$1 shift -sed -n "/^$name/,/^}/ p" $@ +sed -n "/^$name/,/^}/ p" "$@" diff --git a/dmenu-bookmarks b/dmenu-bookmarks @@ -9,6 +9,6 @@ dir=$HOME/box/bookmarks picker="dmenu-filepicker" -echo "$($picker "$@" $dir)" | while read line; do +$picker "$@" "$dir" | while read -r line; do cat "$line" done | xargs open-url diff --git a/dmenu-dwm-sessionmanager b/dmenu-dwm-sessionmanager @@ -1,26 +1,36 @@ #!/bin/sh # Prompts menu to shutdown/reboot/close dwm -# Usage: dmenu-dwm-sessionmanager [-m menu] # Requires: dmenu (or equivalent), dwm (optional) +# Usage: dmenu-dwm-sessionmanager [-m menu] + menu="dmenu -i" prompt="Do you want to quit?" + +usage() { + echo "Usage: dmenu-dwm-sessionmanager [-m MENU]" +} + while getopts "m:" opt; do case "$opt" in m) menu="$OPTARG" ;; + *) + usage + exit 1 + ;; esac done -shift `expr $OPTIND - 1` +shift $((OPTIND - 1)) wmname="dwm" shutdown_cmd="sudo shutdown -h now" reboot_cmd="sudo reboot" closewm_cmd="pkill $wmname" -value=$(echo "Shutdown\nReboot\nQuit dwm" | $menu -p "$prompt") +value=$(printf 'Shutdown\nReboot\nQuit dwm\n' | $menu -p "$prompt") if [ "$value" = "Shutdown" ]; then $shutdown_cmd diff --git a/dmenu-filepicker b/dmenu-filepicker @@ -2,20 +2,29 @@ # A dmenu-based file picker (prints selected file to stdout) # Requires: dmenu (or similar) + # Usage: dmenu-filepicker [-m menu] [path] menu="dmenu -i -l 15" +usage() { + echo "Usage: dmenu-filepicker [-m MENU] [PATH]" +} + while getopts "m:" opt; do case "$opt" in m) menu="$OPTARG" ;; + *) + usage + exit 1 + ;; esac done -shift `expr $OPTIND - 1` +shift $((OPTIND - 1)) -fullpath=$(realpath ${@:-"$(pwd)"}) +fullpath=$(realpath "${@:-"$(pwd)"}") while true; do if [ "$sel" = "." ]; then diff --git a/dmenu-mail-aliases b/dmenu-mail-aliases @@ -2,9 +2,14 @@ # Select mail alias via dmenu # The email address must be the second word in a line of $aliasfile -# Usage: dmenu-mail-aliases [-m menu] # Requires: dmenu (or similar) +# Usage: dmenu-mail-aliases [-m menu] + +usage() { + echo "Usage: dmenu-mail-aliases [-m MENU]" +} + menu="dmenu -l 20" aliasfile="$HOME/.mblaze/aliases" @@ -13,8 +18,12 @@ while getopts "m:" opt; do m) menu="$OPTARG" ;; + *) + usage + exit 1 + ;; esac done -shift `expr $OPTIND - 1` +shift $((OPTIND - 1)) -$menu $menuopts <"$aliasfile" | awk '{print $NF}' +$menu <"$aliasfile" | awk '{print $NF}' diff --git a/dmenu-screenshot b/dmenu-screenshot @@ -1,9 +1,14 @@ #!/bin/sh # Screenshot utility -# Usage: dmenu-screenshot [-m menu] # Requires: dmenu (or similar), imagemagick +# Usage: dmenu-screenshot [-m menu] + +usage() { + echo "Usage: dmenu-screenshot [-m MENU]" +} + menu="dmenu -i" prompt="Select type of screenshot:" @@ -12,21 +17,24 @@ while getopts "m:" opt; do m) menu="$OPTARG" ;; + *) + usage + exit 1 + ;; esac done -shift `expr $OPTIND - 1` +shift $((OPTIND - 1)) folder="$HOME/pictures/screenshots" filename="screenshot_$(date +%Y-%m-%d-%H%M%S).png" filepath="${folder}/${filename}" -t=$(echo "Full\nSelection" | $menu -p "$prompt") -#op="" TODO: remove if not needed +t=$(printf 'Full\nSelection\n' | $menu -p "$prompt") if [ "$t" = "Full" ]; then op="-window root" else pkill xbanish # otherwise I can't use mouse to select area fi -[ -n "$t" ] && sleep 0.1 && import $op $filepath +[ -n "$t" ] && sleep 0.1 && import "$op" "$filepath" spawn xbanish # This can be removed if you don't use xbanish diff --git a/dmenu-unmount b/dmenu-unmount @@ -1,14 +1,20 @@ #!/bin/sh # Prompts selection for mounted devices and unmounts the selected one +# Requires: udevil, dmenu (or similar), notify-send or similar (optional) + # Usage: dmenu-unmount [-m menu] [-w writer] # Example: dmenu-unmount -m slmenu -w echo -# Requires: udevil, dmenu (or similar), notify-send or similar (optional) menu=dmenu #writeout=notify-send writeout="notify push" +usage() { + echo "Usage: dmenu-unmount [-m MENU] [-w WRITER]" + echo "Example: dmenu-unmount -m slmenu -w echo" +} + while getopts "m:w:" opt; do case "$opt" in m) @@ -17,9 +23,13 @@ while getopts "m:w:" opt; do w) writeout="$OPTARG" ;; + *) + usage + exit 1 + ;; esac done -shift `expr $OPTIND - 1` +shift $((OPTIND - 1)) listdev=$(grep "media" /proc/mounts | sed 's/\/media.*\///g' | \ awk '{print $1" ("$2")"}') @@ -31,11 +41,10 @@ else if [ -n "$seldev" ]; then udevil unmount "$seldev" failed=$(udevil info "$seldev" | grep mounted | awk '{print $3}') - if [ $failed -eq 1 ]; then + if [ "$failed" -eq 1 ]; then $writeout "Unmount FAILED" "Device is still mounted!" else $writeout "Device unmounted" fi fi fi -# notify-send "$(udisksctl unmount -b $seldev)" diff --git a/dmenu-urlselect b/dmenu-urlselect @@ -2,18 +2,27 @@ # Finds all URLs in stdin and prompts a dmenu choice, then writes the selected # url to stdout. -# Usage: dmenu-urlselect [-m menu] # Requires: dmenu (or similar), urlgrep +# Usage: dmenu-urlselect [-m menu] + menu="dmenu -i -l 20" +usage() { + echo "Usage: dmenu-urlselect [-m MENU]" +} + while getopts "m:" opt; do case "$opt" in m) menu="$OPTARG" ;; + *) + usage + exit 1 + ;; esac done -shift `expr $OPTIND - 1` +shift $((OPTIND - 1)) urlgrep | $menu diff --git a/dmenu-websearch b/dmenu-websearch @@ -5,4 +5,4 @@ menu=${MENU:-dmenu} -websearch $(echo "" | $menu -p "websearch:") +websearch "$(echo "" | $menu -p "websearch:")" diff --git a/ffmpeg-screenrecord b/ffmpeg-screenrecord @@ -5,4 +5,4 @@ outfile=${1:-output.mkv} -ffmpeg -f x11grab -i :0 -f pulse -i default $outfile +ffmpeg -f x11grab -i :0 -f pulse -i default "$outfile" diff --git a/mail-compose b/mail-compose @@ -3,4 +3,4 @@ # Open a mail composer. # Requires: mblaze, terminal -terminal mcom $@ +terminal mcom "$@" diff --git a/mergepdf b/mergepdf @@ -2,17 +2,25 @@ # Merge multiple pdf files into one # Requires: gs + # Usage: mergepdf [-o outname] file1.pdf file2.pdf ... outname=merged.pdf +usage() { + echo "Usage: mergepdf [-o OUTFILE] file1.pdf file2.pdf ..." +} + while getopts "o:" opt; do case "$opt" in o) outname="$OPTARG" ;; + *) + usage + ;; esac done -shift `expr $OPTIND - 1` +shift $((OPTIND - 1)) -gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=$outname $@ +gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile="$outname" "$@" diff --git a/notify b/notify @@ -32,5 +32,6 @@ case "$1" in ;; *) usage + exit 1 ;; esac diff --git a/open-file b/open-file @@ -2,9 +2,10 @@ # Inspired by https://github.com/salman-abedin/launch.sh # Launches files based on their mimetypes -# Usage: open-file [-m menu] [-s launcher] [-t mimetype] [files...] # Requires: dmenu_path or similar (fallback), dmenu-filepicker +# Usage: open-file [-m menu] [-s launcher] [-t mimetype] [files...] + menu="dmenu -i -l 15" # Change default apps here @@ -17,8 +18,12 @@ sheet="libreoffice" html="firefox --new-window" xedit="xedit" +usage() { + echo "Usage: open-file [-m MENU] [-s LAUNCHER] [-t MIMETYPE] [files...]" +} + openfile() { - f="$@" + f="$*" localmime="$mimetype" [ ! -f "$f" ] && echo "$f: bad argument" && exit 1 @@ -43,8 +48,9 @@ openfile() { application/vnd.openxmlformats-officedocument.wordprocessingml.*) prog="$word" ;; - application/ms-excel | application/vnd.oasis.opendocument.spreadsheet | \ - text/rtf | application/vnd.openxmlformats-officedocument.spreadsheetml.*) + application/ms-excel | \ + application/vnd.oasis.opendocument.spreadsheet | \ + application/vnd.openxmlformats-officedocument.spreadsheetml.*) prog="$sheet" ;; text/html | text/enriched) @@ -78,7 +84,7 @@ openfile() { esac if [ -n "$prog" ]; then - $launcher $prog "$f" + $launcher "$prog" "$f" else exit 1 fi @@ -95,10 +101,14 @@ while getopts "m:s:t:" opt; do t) mimetype="$OPTARG" ;; + *) + usage + exit 1 + ;; esac done -shift `expr $OPTIND - 1` +shift $((OPTIND - 1)) if [ -n "$1" ]; then while [ -n "$1" ]; do @@ -106,7 +116,7 @@ if [ -n "$1" ]; then shift done else - dmenu-filepicker -m "$menu" | while read line; do + dmenu-filepicker -m "$menu" | while read -r line; do openfile "$line" & done fi diff --git a/open-stdin b/open-stdin @@ -9,4 +9,4 @@ folder=${TMPDIR:-/tmp} tempfile=$(mktemp -p "$folder") -cat > "$tempfile" && open-file $@ "$tempfile" +cat > "$tempfile" && open-file "$@" "$tempfile" diff --git a/open-url b/open-url @@ -13,19 +13,16 @@ echo "$@" | xsel -ib case "$@" in mailto:*) - mail-compose $@ + mail-compose "$@" ;; *.jpg | *.jpeg | *.png) - spawn $imageviewer "$@" + spawn "$imageviewer" "$@" ;; *.gif) - spawn $imageviewer "$@" + spawn "$imageviewer" "$@" ;; -# https://www.youtube.com/watch\?v=*) -# spawn $VIDEOPLAYER "$1" -# ;; *) - spawn $browser "$@" + spawn "$browser" "$@" ;; esac diff --git a/popup-cal12 b/popup-cal12 @@ -3,4 +3,4 @@ # Popup terminal displaying cal -3 # Requires: st (suckless terminal) -st -T "stfloat" -g 69x36+620+250 -e sh -c 'cal $(date +%Y); read x' +st -T "stfloat" -g 69x36+620+250 -e sh -c "cal $(date +%Y); read x" diff --git a/popup-terminal b/popup-terminal @@ -2,4 +2,4 @@ # TODO maybe I want to run e.g. tmux in this? -st -T "stfloat" -g 85x25+550+300 tmux new-session $@ +st -T "stfloat" -g 85x25+550+300 tmux new-session "$@" diff --git a/sel b/sel @@ -1,6 +1,9 @@ #!/bin/sh # Allow bulk operations on a list of selected files. + +# Requires: dmenu (or similar), trash (optional), open-file (for open only) + # Usage: sel [-m menu] [command] # If no command is specified, shows the list of selected files # Commands: @@ -13,8 +16,6 @@ # open: open files using open-file # rm: remove selected files and clear selection -# Requires: dmenu (or similar), trash (optional), open-file (for open only) - # TODO: The usage of paste(1) is a bit of a hack, and for example it does # not work if filenames contain tab characters. Fix this. @@ -26,14 +27,32 @@ menu="" # default uses dmenu-filepicker default editor=${EDITOR:-vi} rm="trash rm" # replace with rm -r if you don't use trash +usage() { + echo "Usage: sel [-m MENU] [COMMAND]" + echo "If no COMMAND is specified, shows the list of selected files" + echo "Possible commands:" + echo " add [files...]: add files to selection" + echo " addall: add all files in the current folder to selection" + echo " clear: clear selection" + echo " cp: copy to current dir, possbily after editing filenames" + echo " edit: open selection in editor" + echo " mv: move to current dir, possbily after editing filenames" + echo " open: open files using open-file" + echo " rm: remove selected files and clear selection" +} + while getopts "m:" opt; do case "$opt" in m) menu="$OPTARG" ;; + *) + usage + exit 1 + ;; esac done -shift `expr $OPTIND - 1` +shift $((OPTIND - 1)) add() { shift 1 @@ -57,12 +76,12 @@ cphere() { file2=$(mktemp) sed 's/^.*\///' "$file" > "$file2" $editor "$file2" - if [ "$(wc -l $file | awk '{print $1}')" != \ - "$(wc -l $file2 | awk '{print $1}')" ]; then + if [ "$(wc -l "$file" | awk '{print $1}')" != \ + "$(wc -l "$file2" | awk '{print $1}')" ]; then echo "Error reading new file names" return 1 else - paste "$file" "$file2" | while read f; do + paste "$file" "$file2" | while read -r f; do fold=$(echo "$f" | sed 's/ .*//') fnew=$(echo "$f" | sed 's/.* //') cp -R "$fold" ./"$fnew" || return 1 @@ -71,13 +90,13 @@ cphere() { } open() { - while read f; do + while read -r f; do open-file "$f" done < "$file" } remove() { - while read f; do + while read -r f; do $rm "$f" done < "$file" } @@ -90,7 +109,7 @@ case "$1" in add "$@" ;; addall) - add * + add ./* ;; clear) clear diff --git a/sfeed-browser b/sfeed-browser @@ -11,20 +11,29 @@ # them before displaying the choice of feeds. Contact me if you are interested # in using it. -# Usage: sfeed-browser [-m menu] # Requires: sfeed, dmenu-file-picker (or similar), open-url (or similar) +# Usage: sfeed-browser [-m menu] + filepicker="dmenu-filepicker" # Try "nnn -p -" menu="dmenu -l 35 -i" urlopener=open-url sfd="$HOME/box/sfeed" showlast=10 +usage() { + echo "sfeed-browser [-m MENU]" +} + while getopts "m:" opt; do case "$opt" in m) menu="$OPTARG" ;; + *) + usage + exit 1 + ;; esac done @@ -34,34 +43,34 @@ fixurl() { } dirtofeedpaths() { - while read line; do - find "$line" | while read fname; do + while read -r line; do + find "$line" | while read -r fname; do [ -f "$fname" ] && echo "$fname" done done } pathstosfeedrc() { - printf "sfeedpath=\"$sfd/files\"\n\nfeeds() {\n" - while read line; do + printf 'sfeedpath="%s"\n\nfeeds() {\n' "$sfd/files" + while read -r line; do feedname=$(echo "$line" | sed 's/.*\///') - read feedurl <"$line" - printf "\tfeed \"$feedname\" \"$feedurl\"\n" + read -r feedurl <"$line" + printf '\tfeed "%s" "%s"\n' "$feedname" "$feedurl" done printf "}\n" } feedmenu() { - while read line; do + while read -r line; do feedname=$(echo "$line" | sed 's/.*\///') sfeed_plain "$sfd/files/$feedname" | head -$showlast done | $menu } openfeeds() { - while read line; do + while read -r line; do url=$(echo "$line" | sed 's/.*[\t ]//' | fixurl) - [ -n "$url" ] && echo $url + [ -n "$url" ] && echo "$url" done | xargs $urlopener } diff --git a/share b/share @@ -3,11 +3,11 @@ # One-liner to upload stuff to my webserver srv=tronto.net -dir=$(cat /dev/random | tr -cd 'a-z0-9' | fold -w 8 | head -n 1) +dir=$(tr -cd 'a-z0-9' < /dev/random | fold -w 8 | head -n 1) htp=https://share.tronto.net/$dir pth=/var/www/htdocs/share.tronto.net/$dir url=$srv:$pth -ssh tronto.net mkdir $pth -scp $@ $url/ -for i in $@; do echo "$htp/$i"; done +ssh tronto.net mkdir "$pth" +scp "$@" "$url"/ +for i in "$@"; do echo "$htp/$i"; done diff --git a/status b/status @@ -35,7 +35,7 @@ network="Network: $nwclean" noticount=$(notify show | wc -l) -printf "$network$sep$volume$sep$battery$sep$date$sep$time" -[ "$noticount" = "1" ] && printf "$sep$(notify show)" -[ "$noticount" -gt "1" ] && printf "${sep}Unread notifications: $noticount" -printf "\n" +printf '%s' "$network$sep$volume$sep$battery$sep$date$sep$time" +[ "$noticount" = "1" ] && printf '%s' "$sep$(notify show)" +[ "$noticount" -gt "1" ] && printf '%s' "${sep}Unread items: $noticount" +printf '\n' diff --git a/terminal b/terminal @@ -2,4 +2,4 @@ # My default terminal -st -e tmux new-session $@ +st -e tmux new-session "$@" diff --git a/translate b/translate @@ -7,5 +7,5 @@ from=$1 to=$2 shift 2 -text=$(echo $@ | sed 's/ /\%20/g') +text=$(echo "$@" | sed 's/ /\%20/g') open-url "${translator}?sl=${from}&tl=${to}&text=${text}&op=translate" diff --git a/trash b/trash @@ -4,25 +4,30 @@ # current date. # Usage: trash [rm FILE(s)|ls|empty] -# Pretty self-explanatory # ksh completion # set -A complete_trash_1 rm ls empty trashfolder=$XDG_DATA_HOME/mytrash +usage() { + echo "Usage: trash [rm FILES... | ls | empty]" +} + if [ -z "$1" ]; then - echo "usage: trash [rm FILE(s)|ls|empty]" -else + usage + exit 1 +fi + case "$1" in empty) # little check if [ -n "$trashfolder" ]; then - rm -rf $trashfolder/* + rm -rf "${trashfolder:?}"/* fi ;; ls) - ls $trashfolder + ls "$trashfolder" ;; rm) curdir=$(pwd | sed 's|.*/||') @@ -33,7 +38,7 @@ case "$1" in ;; *) - echo "$1: not a valid command" + usage + exit 1 ;; esac -fi diff --git a/virename b/virename @@ -10,11 +10,11 @@ editor=${EDITOR:-vi} ls | tee "$file" > "$file2" $editor "$file2" -if [ "$(wc -l $file | awk '{print $1}')" != \ - "$(wc -l $file2 | awk '{print $1}')" ]; then +if [ "$(wc -l "$file" | awk '{print $1}')" != \ + "$(wc -l "$file2" | awk '{print $1}')" ]; then echo "Error reading new file names" else - paste "$file" "$file2" | while read f; do + paste "$file" "$file2" | while read -r f; do fold=$(echo "$f" | sed 's/ .*//') fnew=$(echo "$f" | sed 's/.* //') if [ "$fold" != "$fnew" ]; then diff --git a/xedit b/xedit @@ -5,4 +5,4 @@ editor=${EDITOR:-${VISUAL:-vi}} -terminal $editor $@ +terminal "$editor" "$@" diff --git a/xedit-filter b/xedit-filter @@ -1,4 +1,4 @@ -#/!bin/sh +#!/bin/sh # Open stdin in a text editor and sends modified selection to stdout # Requires: xedit diff --git a/xplumb b/xplumb @@ -18,7 +18,7 @@ menu=${MENU:-dmenu} menuopts="-l 10" text=$(xsel | sed 's/\n/ /g') -if [ $(echo "$text" | wc -c) -ge 11 ]; then +if [ "${#text}" -ge 11 ]; then shorttext=$(echo "$text" | cut -b 1-10)... else shorttext="$text" @@ -29,7 +29,7 @@ choice() { $menu $menuopts -p "What to do with \"$shorttext\"?") if [ "$chosen" = "websearch" ]; then - websearch $text + websearch "$text" elif [ "$chosen" = "edit" ]; then f=$(mktemp) xsel > "$f" @@ -39,13 +39,13 @@ choice() { trymail() { addr=$(echo "$1" | addressgrep) - ( [ -n "$addr" ] && mail-compose $addr ) || return 1 + ( [ -n "$addr" ] && mail-compose "$addr" ) || return 1 } tryman() { number=$(echo "$1" | sed 's/[^1-8]//g') name=$(echo "$1" | sed 's/([1-8])//g' | sed 's/ //g') - if [ $(man -w "$number" "$name" | wc -l) = 1 ]; then + if [ "$(man -w "$number" "$name" | wc -l)" = 1 ]; then terminal -e man "$number" "$name" return 0 else @@ -55,7 +55,7 @@ tryman() { tryurl() { url=$(echo "$1" | urlgrep) - ( [ -n "$url" ] && $browser $url ) || return 1 + ( [ -n "$url" ] && "$browser" "$url" ) || return 1 } #open-file -s spawn "$text" || \ diff --git a/xwallpaper-random-notify b/xwallpaper-random-notify @@ -10,8 +10,8 @@ folder=~/pictures/wallpapers pic=$(ls $folder | sort -R | head -1) # Alternative: use feh -#feh --bg-fill --no-fehbg $folder/$pic -xwallpaper --zoom $folder/$pic +#feh --bg-fill --no-fehbg "$folder"/"$pic" +xwallpaper --zoom "$folder"/"$pic" # Uncomment to notify -#$notify "Background of the day" $pic +#$notify "Background of the day" "$pic"