From de53599c719bdc3a85e5a1e44e22ebc9a8e5b4c2 Mon Sep 17 00:00:00 2001 From: ghuter Date: Tue, 3 Mar 2020 11:29:52 +0100 Subject: [PATCH 01/14] Some minor modifications --- comp | 8 ++++---- cpdragon | 14 +++++++------- crf | 2 +- dlfile | 34 +++++++++++++--------------------- encode | 2 +- extramonitor | 8 ++++---- mepapemaker.sh | 2 +- mkscript | 19 +++++++------------ mntandroid | 7 +------ mvdragon | 15 +++++++-------- opnbrow | 20 ++++++++++---------- opout | 4 ++-- prompt | 5 ++--- pyshell | 2 +- sch | 6 ++---- screenshot | 15 +++++++-------- stripspace | 2 +- toggletouch | 2 +- 18 files changed, 72 insertions(+), 95 deletions(-) diff --git a/comp b/comp index 0f994ba..cb57fb0 100755 --- a/comp +++ b/comp @@ -1,12 +1,12 @@ #!/bin/sh # General handler for compiling files -file=$(readlink -f "$1") -base=$(echo "$file" | sed 's/\..*//') +file="$(readlink -f "$1")" +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..02289b8 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 -r 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..4f888ef 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 -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//%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//%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..274c3a1 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..f8b668d 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 +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..3010914 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 +dir=$HOME/cell; mkdir -p "$dir" 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..4ca1faf 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 -r 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..22d78aa 100755 --- a/opout +++ b/opout @@ -2,9 +2,9 @@ # 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/\.[^\/.]*$//')" +basename="${1%.*}" -case "$1" in +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..2e77aa7 100755 --- a/prompt +++ b/prompt @@ -2,6 +2,5 @@ # 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..f5769de 100755 --- a/pyshell +++ b/pyshell @@ -1,2 +1,2 @@ #!/bin/sh -echo "" | dmenu -i -p "Python" | xargs -0 -I % python -c "import random;print(%)" | xargs -I % notify-send "Result" "%" +printf '' | dmenu -i -p 'Python' | xargs -I % python -c "import random;print(%)" | xargs -I % notify-send 'Result' "%" diff --git a/sch b/sch index c338214..0cdab3d 100755 --- a/sch +++ b/sch @@ -6,7 +6,7 @@ url=$(sort ~/.config/search/search | sed 's/:.*//' | dmenu -i -p "Search Engine" search=$(sort ~/.config/search/search_history | dmenu -i -p "Search") # Echo to history file -if [ ! "$(grep -q "$search" < ~/.config/search/search_history)" ]; then +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 else @@ -15,6 +15,4 @@ if [ ! "$(grep -q "$search" < ~/.config/search/search_history)" ]; then 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..eafb25a 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" From edfa478bfcec3af4212846955a1b22342c1a1ee5 Mon Sep 17 00:00:00 2001 From: ghuter Date: Tue, 3 Mar 2020 15:50:28 +0100 Subject: [PATCH 02/14] Update screenshot Co-Authored-By: Terminal for Life <31768530+terminalforlife@users.noreply.github.com> --- screenshot | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/screenshot b/screenshot index eafb25a..c0e4c60 100755 --- a/screenshot +++ b/screenshot @@ -7,9 +7,9 @@ menu() { } case $1 in - full) maim "$output" || exit;; - select) maim -s "$output" || exit ;; - fulltime) menu && maim "$output" || exit ;; + full) maim "$output" || exit;; + select) maim -s "$output" || exit ;; + fulltime) menu && maim "$output" || exit ;; selecttime) menu && maim -s "$output" || exit ;; esac From 75b2e68b897a1bfc8fe0a256451a51123c557b91 Mon Sep 17 00:00:00 2001 From: ghuter Date: Tue, 3 Mar 2020 15:59:36 +0100 Subject: [PATCH 03/14] Update comp --- comp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/comp b/comp index cb57fb0..164f105 100755 --- a/comp +++ b/comp @@ -1,8 +1,8 @@ #!/bin/sh # General handler for compiling files -file="$(readlink -f "$1")" -base="${file%.*}" +file=$(readlink -f "$1") +base=${file%.*} #bang=$(sed -n "1p" "$file") case "$1" in From 5dbd9c9ebbdbc9e0dc2de37a090bee21c5a3ea79 Mon Sep 17 00:00:00 2001 From: ghuter Date: Tue, 3 Mar 2020 16:01:16 +0100 Subject: [PATCH 04/14] Update cpdragon --- cpdragon | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cpdragon b/cpdragon index 02289b8..e8717e9 100755 --- a/cpdragon +++ b/cpdragon @@ -1,8 +1,8 @@ #!/bin/sh -while IFS= read -r line; do - path="${line##file://}" - name="${path##*/}" +while IFS= read line; do + path=${line##file://} + name=${path##*/} cp "$path" "$name" done << EOF $(dragon-drag-and-drop -t -x) From ff314bf92708d9a01f11956374beab11841e3d97 Mon Sep 17 00:00:00 2001 From: ghuter Date: Tue, 3 Mar 2020 16:03:16 +0100 Subject: [PATCH 05/14] Update dlfile --- dlfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dlfile b/dlfile index 4f888ef..2b139ce 100755 --- a/dlfile +++ b/dlfile @@ -18,4 +18,4 @@ do done # Download the file with curl -[ -n "$name" ] && curl -o "$name" "$url" || exit 1 +[ -n "$name" ] && curl -s -o "$name" "$url" || exit 1 From 5fce3e20e4696b49aba7f18d1a8d5efc1af71479 Mon Sep 17 00:00:00 2001 From: ghuter Date: Tue, 3 Mar 2020 16:07:05 +0100 Subject: [PATCH 06/14] Update extramonitor Co-Authored-By: Terminal for Life <31768530+terminalforlife@users.noreply.github.com> --- extramonitor | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extramonitor b/extramonitor index 274c3a1..4a4e682 100755 --- a/extramonitor +++ b/extramonitor @@ -6,7 +6,7 @@ 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" ;; + 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 From 6d0b8cb95e9be32c3c826f82fe4f6340a56b85b6 Mon Sep 17 00:00:00 2001 From: ghuter Date: Tue, 3 Mar 2020 16:07:57 +0100 Subject: [PATCH 07/14] Update mkscript --- mkscript | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mkscript b/mkscript index f8b668d..0fd0eae 100755 --- a/mkscript +++ b/mkscript @@ -9,7 +9,7 @@ do read -r ans done -file="$HOME/scripts/$ans" +file=$HOME/scripts/$ans [ -d "$HOME/scripts" ] && exit if [ -e "$HOME/scripts/$ans" ]; then From ff5ea5c7c098fe9591e465a5d65d6ae2f966b6a6 Mon Sep 17 00:00:00 2001 From: ghuter Date: Tue, 3 Mar 2020 16:09:12 +0100 Subject: [PATCH 08/14] Update mntandroid --- mntandroid | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mntandroid b/mntandroid index 3010914..ebed58a 100755 --- a/mntandroid +++ b/mntandroid @@ -1,7 +1,7 @@ #!/bin/sh # Mount and unmount an android device to the $HOME/cell folder -dir=$HOME/cell; mkdir -p "$dir" +mkdir -p "$HOME/cell" if [ "$(find "$dir" -maxdepth 1 | wc -l)" -gt 1 ]; then fusermount -u "$dir" && notify-send "Android Mount" "Device Unmounted" From 39b79be289534cb3869385eb7b17956e14275c9c Mon Sep 17 00:00:00 2001 From: ghuter Date: Tue, 3 Mar 2020 16:10:44 +0100 Subject: [PATCH 09/14] Update mvdragon --- mvdragon | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mvdragon b/mvdragon index 4ca1faf..ee1b1b1 100755 --- a/mvdragon +++ b/mvdragon @@ -1,8 +1,8 @@ #!/bin/sh -while IFS= read -r line; do - path="${line##file://}" - name="${path##*/}" +while IFS= read line; do + path=${line##file://} + name=${path##*/} mv "$path" "$name" done << EOF $(dragon-drag-and-drop -t -x) From a2a6cd90ae35c3d31c2e1ffd333baae293e9a201 Mon Sep 17 00:00:00 2001 From: ghuter Date: Tue, 3 Mar 2020 16:12:17 +0100 Subject: [PATCH 10/14] Update opout Co-Authored-By: Terminal for Life <31768530+terminalforlife@users.noreply.github.com> --- opout | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/opout b/opout index 22d78aa..57226a5 100755 --- a/opout +++ b/opout @@ -2,7 +2,10 @@ # opout: "open output": A general handler for opening a file's intended output. # I find this useful especially running from vim. -basename="${1%.*}" +# Avoid extension-less hidden filenames from being read as null. +basename_nodot=${1#.} + +basename=${basename_nodot%.*} case $1 in *.tex|*.md|*.rmd|*.ms|*.me|*.mom) setsid "$READER" "$basename".pdf >/dev/null 2>&1 & ;; From a495e67992c5b521c66f5db5cfa423c0abab8528 Mon Sep 17 00:00:00 2001 From: ghuter Date: Tue, 3 Mar 2020 16:12:39 +0100 Subject: [PATCH 11/14] Update prompt Co-Authored-By: Terminal for Life <31768530+terminalforlife@users.noreply.github.com> --- prompt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/prompt b/prompt index 2e77aa7..65546a5 100755 --- a/prompt +++ b/prompt @@ -2,5 +2,4 @@ # Opens a basic yes/no prompt with dmenu # This is useful for confirming whether an action should be taken -[ "$(printf "No\nYes" | dmenu -i -p "$1" -fn "JetBrains Mono Medium-10")" = "Yes" ] && "$2" - +[ "$(printf 'No\nYes' | dmenu -i -p "$1" -fn 'JetBrains Mono Medium-10')" = 'Yes' ] && "$2" From 5e0cecc00b0b39a53863ebae44d9ffdf5368f48c Mon Sep 17 00:00:00 2001 From: ghuter Date: Tue, 3 Mar 2020 16:18:52 +0100 Subject: [PATCH 12/14] Update pyshell --- pyshell | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyshell b/pyshell index f5769de..58865f8 100755 --- a/pyshell +++ b/pyshell @@ -1,2 +1,3 @@ #!/bin/sh -printf '' | dmenu -i -p 'Python' | xargs -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(%)")" From b7ee797b7df3062f7a2ed004bbd96c9b16ce1436 Mon Sep 17 00:00:00 2001 From: ghuter Date: Tue, 3 Mar 2020 16:20:51 +0100 Subject: [PATCH 13/14] Update sch --- sch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sch b/sch index 0cdab3d..e3b392d 100755 --- a/sch +++ b/sch @@ -6,7 +6,7 @@ url=$(sort ~/.config/search/search | sed 's/:.*//' | dmenu -i -p "Search Engine" search=$(sort ~/.config/search/search_history | dmenu -i -p "Search") # Echo to history file -if ! grep -q "$search" < ~/.config/search/search_history; then +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 else From c017c8b3606c181efa80069bafd0a6fb59f5719b Mon Sep 17 00:00:00 2001 From: ghuter Date: Tue, 3 Mar 2020 16:24:58 +0100 Subject: [PATCH 14/14] Update sch --- sch | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/sch b/sch index e3b392d..e5a1572 100755 --- a/sch +++ b/sch @@ -2,15 +2,17 @@ # 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