diff --git a/comp b/comp index 0f994ba..164f105 100755 --- a/comp +++ b/comp @@ -2,11 +2,11 @@ # General handler for compiling files file=$(readlink -f "$1") -base=$(echo "$file" | sed 's/\..*//') +base=${file%.*} #bang=$(sed -n "1p" "$file") case "$1" in - *".md") pandoc "$file" -o "$base".pdf ;; - *".php") php -S "$file" ;; + *.md) pandoc "$file" -o "$base".pdf ;; + *.php) php -S "$file" ;; *) echo "Can't compile" ;; esac diff --git a/cpdragon b/cpdragon index 1bbaccd..e8717e9 100755 --- a/cpdragon +++ b/cpdragon @@ -1,9 +1,9 @@ #!/bin/sh -files=$(dragon-drag-and-drop -t -x) -for file in $files -do - path=${file#file://} - name=$(basename "$path") - cp "$path" "$(pwd)/$name" -done +while IFS= read line; do + path=${line##file://} + name=${path##*/} + cp "$path" "$name" +done << EOF +$(dragon-drag-and-drop -t -x) +EOF diff --git a/crf b/crf index 0d09c17..687f529 100755 --- a/crf +++ b/crf @@ -1,3 +1,3 @@ #!/bin/sh # Script to generate a templte react class -printf "import React from \"react\";\n\nconst $1 = () => {\n\treturn
;\n};\n\nexport default $1;" > $(pwd)/$2/$1.js +printf "import React from \"react\";\n\nconst $1 = () => {\n\treturn ;\n};\n\nexport default $1;" > "$2/$1.js" diff --git a/dlfile b/dlfile index 367912e..2b139ce 100755 --- a/dlfile +++ b/dlfile @@ -1,29 +1,21 @@ #!/bin/sh # Provides the ability to download a file by dropping it into a window -url=$(dragon-drag-and-drop -t -x) +url="$(dragon-drag-and-drop -t -x)" -if [ -n "$url" ]; then - printf "File Name: " - name="" - while [ -z $name ] || [ -e $name ] - do +[ -n "$url" ] || exit 1 + +name="" +while [ -z "$name" ] || [ -e "$name" ] +do + printf "File Name: " read -r name if [ -e "$name" ]; then - printf "File already exists, overwrite (y|n): " - read -r ans - - if [ "$ans" = "y" ]; then - break - else - printf "File Name: " - fi + printf "File already exists, overwrite (y|n): " + read -r ans + [ "$ans" = "y" ] && break fi - done - - # Download the file with curl - [ -n "$name" ] && curl -o "$name" "$url" || exit 1 -else - exit 1 -fi +done +# Download the file with curl +[ -n "$name" ] && curl -s -o "$name" "$url" || exit 1 diff --git a/encode b/encode index 5e30810..eda34ad 100755 --- a/encode +++ b/encode @@ -1,4 +1,4 @@ #!/bin/sh # Performs HTML encoding on a string for special characters up to ASCII -echo "$1" | sed 's/%/%25/g;s/\s/%20/g;s/!/%21/g;s/"/%22/g;s/#/%22/g;s/\$/%24/g;s/&/%26/g;s/\x27/%27/g;s/)/%29/g;s/(/%28/g;s/\*/%2A/g;s/\+/%2B/g;s/,/%2C/g;s/-/%2D/g;s/\./%2E/g;s/\//%2F/g;s/:/%3A/g;s/;/%3B/g;s/%3C/g;s/=/%3D/g;s/>/%3E/g;s/\?/%3F/g;s/@/%40/g;s/]/%5D/g;s/\\/%5C/g;s/\[/%5B/g;s/\^/%5E/g;s/_/%5F/g;s/`/%60/g;s/}/%7D/g;s/|/%7C/g;s/{/%7B/g;s/~/%7E/g' +sed 's/%/%25/g;s/\s/%20/g;s/!/%21/g;s/"/%22/g;s/#/%22/g;s/\$/%24/g;s/&/%26/g;s/\x27/%27/g;s/)/%29/g;s/(/%28/g;s/\*/%2A/g;s/\+/%2B/g;s/,/%2C/g;s/-/%2D/g;s/\./%2E/g;s/\//%2F/g;s/:/%3A/g;s/;/%3B/g;s/%3C/g;s/=/%3D/g;s/>/%3E/g;s/\?/%3F/g;s/@/%40/g;s/]/%5D/g;s/\\/%5C/g;s/\[/%5B/g;s/\^/%5E/g;s/_/%5F/g;s/`/%60/g;s/}/%7D/g;s/|/%7C/g;s/{/%7B/g;s/~/%7E/g' diff --git a/extramonitor b/extramonitor index 2e096d4..4a4e682 100755 --- a/extramonitor +++ b/extramonitor @@ -4,9 +4,9 @@ intern="$2" extern="$3" -case "$1" in - "disconnect") xrandr --output "$extern" --off --output "$intern" --auto ;; - "extra") xrandr --output "$extern" --set audio force-dvi --mode 1920x1080 && xrandr --output "$intern" --auto --output "$extern" --right-of "$intern" ;; - "duplicate") xrandr --output "$extern" --set audio force-dvi --mode 1920x1080 && xrandr --output "$intern" --auto --output "$extern" --same-as "$intern" ;; +case $1 in + disconnect) xrandr --output "$extern" --off --output "$intern" --auto ;; + extra) xrandr --output "$extern" --set audio force-dvi --mode 1920x1080 && xrandr --output "$intern" --auto --output "$extern" --right-of "$intern" ;; + duplicate) xrandr --output "$extern" --set audio force-dvi --mode 1920x1080 && xrandr --output "$intern" --auto --output "$extern" --same-as "$intern" ;; *) notify-send "Multi Monitor" "Unknown Operation" ;; esac diff --git a/mepapemaker.sh b/mepapemaker.sh index 414da25..f711b18 100755 --- a/mepapemaker.sh +++ b/mepapemaker.sh @@ -1,6 +1,6 @@ #!/usr/bin/bash -pape=$1 +pape="$1" # Get the width of the wallpaper height=$(magick convert "$pape" -format "%h" info:) diff --git a/mkscript b/mkscript index f9da5ed..0fd0eae 100755 --- a/mkscript +++ b/mkscript @@ -1,26 +1,21 @@ #!/bin/sh # Simple script to generate a script file in my scripts directory -printf "File Name: " - # Set a name for the script +ans= while [ -z "$ans" ]; do - read -r ans - - if [ -z "$ans" ]; then printf "File Name: " - fi + read -r ans done file=$HOME/scripts/$ans -if [ -d "$HOME/scripts" ]; then - if [ -e "$HOME/scripts/$ans" ]; then +[ -d "$HOME/scripts" ] && exit +if [ -e "$HOME/scripts/$ans" ]; then $EDITOR "$file" - else - echo "#!/bin/sh" >> "$file" +else + echo '#!/bin/sh' >> "$file" chmod +x "$file" $EDITOR "$file" - fi fi diff --git a/mntandroid b/mntandroid index b1fb81a..ebed58a 100755 --- a/mntandroid +++ b/mntandroid @@ -1,12 +1,7 @@ #!/bin/sh # Mount and unmount an android device to the $HOME/cell folder -dir=$HOME/cell - -# Make the cell directory if it doesn't exist -if [ -d "$dir" ]; then - mkdir "$dir" -fi +mkdir -p "$HOME/cell" if [ "$(find "$dir" -maxdepth 1 | wc -l)" -gt 1 ]; then fusermount -u "$dir" && notify-send "Android Mount" "Device Unmounted" diff --git a/mvdragon b/mvdragon index dd3dc12..ee1b1b1 100755 --- a/mvdragon +++ b/mvdragon @@ -1,10 +1,9 @@ #!/bin/sh -files=$(dragon-drag-and-drop -t -x) - -for file in $files -do - path=${file#file://} - name=$(basename "$path") - mv "$path" "$(pwd)/$name" -done +while IFS= read line; do + path=${line##file://} + name=${path##*/} + mv "$path" "$name" +done << EOF +$(dragon-drag-and-drop -t -x) +EOF diff --git a/opnbrow b/opnbrow index b754a71..62ce0de 100755 --- a/opnbrow +++ b/opnbrow @@ -2,17 +2,17 @@ # Handler script for opening a link in a browser handle_default() { - if [ ! -z "$1" ]; then + if command -v "$1" >/dev/null; then $1 "$2" - elif [ ! -z "$BROWSER" ]; then - $BROWSER $2 + elif [ -n "$BROWSER" ]; then + $BROWSER "$2" fi } -if [ "$2" ]; then - # Special handling for browsers that support tabbing - case "$1" in - "firefox") firefox --new-tab "$2" ;; - *) handle_default ;; - esac -fi +[ "$2" ] || exit + +# Special handling for browsers that support tabbing +case $1 in + firefox) firefox --new-tab "$2" ;; + *) handle_default "$@" ;; +esac diff --git a/opout b/opout index 69056c9..57226a5 100755 --- a/opout +++ b/opout @@ -2,9 +2,12 @@ # opout: "open output": A general handler for opening a file's intended output. # I find this useful especially running from vim. -basename="$(echo "$1" | sed 's/\.[^\/.]*$//')" +# Avoid extension-less hidden filenames from being read as null. +basename_nodot=${1#.} -case "$1" in +basename=${basename_nodot%.*} + +case $1 in *.tex|*.md|*.rmd|*.ms|*.me|*.mom) setsid "$READER" "$basename".pdf >/dev/null 2>&1 & ;; *.html) setsid "$BROWSER" --new-window "$basename".html >/dev/null 2>&1 & ;; esac diff --git a/prompt b/prompt index a7d8814..65546a5 100755 --- a/prompt +++ b/prompt @@ -2,6 +2,4 @@ # Opens a basic yes/no prompt with dmenu # This is useful for confirming whether an action should be taken -if [ "$(printf "No\nYes" | dmenu -i -p "$1" -fn "JetBrains Mono Medium-10")" = "Yes" ]; then - $2 -fi +[ "$(printf 'No\nYes' | dmenu -i -p "$1" -fn 'JetBrains Mono Medium-10')" = 'Yes' ] && "$2" diff --git a/pyshell b/pyshell index 4c9a5e2..58865f8 100755 --- a/pyshell +++ b/pyshell @@ -1,2 +1,3 @@ #!/bin/sh -echo "" | dmenu -i -p "Python" | xargs -0 -I % python -c "import random;print(%)" | xargs -I % notify-send "Result" "%" +notify-send 'Result' \ + "$(printf '' | dmenu -p 'Python' | xargs -I % python -c "import random; print(%)")" diff --git a/sch b/sch index c338214..e5a1572 100755 --- a/sch +++ b/sch @@ -2,19 +2,19 @@ # Opens a dmenu prompt for selecting a search engine and providing a search query # To avoid issues with spaces and special characters html encoding is applied to the query +hist=$HOME/.config/search/search_history + url=$(sort ~/.config/search/search | sed 's/:.*//' | dmenu -i -p "Search Engine" | xargs -I % grep "%:" ~/.config/search/search | sed 's/.*://') -search=$(sort ~/.config/search/search_history | dmenu -i -p "Search") +search=$(sort "$hist" | dmenu -i -p "Search") # Echo to history file -if [ ! "$(grep -q "$search" < ~/.config/search/search_history)" ]; then - if [ "$(wc -l < ~/.config/search/search_history)" -gt 500 ]; then - sed -i "1s/^/$search\n/;$ d" ~/.config/search/search_history +if ! grep -q "$search" "$hist"; then + if [ $(wc -l "$hist") -gt 500 ]; then + sed -i "1s/^/$search\n/;$ d" "$hist" else - echo "$search" >> ~/.config/search/search_history + echo "$search" >> "$hist" fi fi # Open browser if search query provided -if [ -n "$search" ] && [ "$search" != "" ]; then - opnbrow "$1" "$url$(encode "$search")" -fi +[ -n "$search" ] && opnbrow "$1" "$url$(encode "$search")" diff --git a/screenshot b/screenshot index 699e046..c0e4c60 100755 --- a/screenshot +++ b/screenshot @@ -3,15 +3,14 @@ output=$HOME/pictures/screenshots/"$(date +%s_%h%d_%H:%M:%S).png" menu() { - echo "" | dmenu -p "How Long?" | xargs -I _ sleep "_" + printf '' | dmenu -p "How Long?" | xargs -I _ sleep "_" } -case "$1" in - "full") maim "$output" || exit;; - "select") maim -s "$output" || exit ;; - "fulltime") menu && maim "$output" || exit ;; - "selecttime") menu && maim -s "$output" || exit ;; - +case $1 in + full) maim "$output" || exit;; + select) maim -s "$output" || exit ;; + fulltime) menu && maim "$output" || exit ;; + selecttime) menu && maim -s "$output" || exit ;; esac -notify-send "Maim" "Screenshot Taken" +notify-send Maim 'Screenshot Taken' diff --git a/stripspace b/stripspace index 8f06a9d..682b8e9 100755 --- a/stripspace +++ b/stripspace @@ -1,4 +1,4 @@ #!/bin/sh # Renames a file by stripping out the spaces -newname=$(echo "$1" | sed 's/ /-/g') +newname="$(printf "$1" | tr ' ' '-')" mv "$1" "$newname" diff --git a/toggletouch b/toggletouch index 1422cfe..35961c3 100755 --- a/toggletouch +++ b/toggletouch @@ -3,7 +3,7 @@ id="$(xinput list | grep -Eo 'Touchpad.*id=[0-9]*' | grep -Eo '[0-9]*')" mode="$(echo "$id" | xargs -I % xinput --list-props % | grep 'Device Enabled' | grep -Eo ':.*[0|1]' | grep -Eo '[0|1]')" -if [ "$mode" -eq "1" ]; then +if [ $mode -eq 1 ]; then xinput set-prop "$id" "Device Enabled" 0 && notify-send "Touchpad" "Touchpad has been disabled" else xinput set-prop "$id" "Device Enabled" 1 && notify-send "Touchpad" "Touchpad has been enabled"