Make history keep more than it shows; Add gopher search - dsearch - Simple script to launch and remember search queries using dmenu. DIR Log DIR Files DIR Refs --- DIR commit ed67d43c8c4711b9283823305d322c25fa28c65d DIR parent 5d470c08913b17c0bd430c078b6f35602f00af51 HTML Author: Scarlett McAllister <no+reply@roygbyte.com> Date: Fri, 1 Sep 2023 18:11:10 -0300 Make history keep more than it shows; Add gopher search Diffstat: M dsearch | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) --- DIR diff --git a/dsearch b/dsearch @@ -4,7 +4,7 @@ # Author: Roygbyte # Description: Smol script to easily and quickly launch a search query. # Date: April, 2023 -# Version: 0.1 +# Version: 0.2 # # Installation # ========= @@ -23,7 +23,8 @@ # By default, it uses urxvt to dispatch W3M and Lynx. HISTORY="/home/$USER/bin/.search-history" -HISTORY_COUNT=10 +HISTORY_TO_KEEP=10000 +HISTORY_TO_SHOW=10 DMENU_OPTIONS=" -b -fn Iosevka-18 -nb #000000 -nf #FFFFFF -sb #0000FF" function add_history_item() { @@ -34,11 +35,11 @@ function add_history_item() { # Use awk to print out a new history file. Current search is added to top of list. # Then the current search term is omitted in any other occurances in the list. # Awk, we love it. It makes using more complicated software feel awk-ward. - cat $HISTORY | head -n $HISTORY_COUNT| awk -v search_term="$SEARCH_TERM" 'BEGIN {print search_term;} !match($0, search_term) { print $0; }' > "$HISTORY.temp" + cat $HISTORY | head -n $HISTORY_TO_KEEP| awk -v search_term="$SEARCH_TERM" 'BEGIN {print search_term;} !match($0, search_term) { print $0; }' > "$HISTORY.temp" mv "$HISTORY.temp" $HISTORY } -SEARCH_TERM=$(cat $HISTORY | dmenu -p "Search" -l $HISTORY_COUNT $DMENU_OPTIONS) +SEARCH_TERM=$(cat $HISTORY | dmenu -p "Search" -l $HISTORY_TO_SHOW $DMENU_OPTIONS) if [ -z $SEARCH_TERM ]; then # Exit on ESC, producing empty string @@ -47,19 +48,21 @@ fi add_history_item "$SEARCH_TERM" -SEARCH_URL="https://duckduckgo.com/?q=$SEARCH_TERM" -SEARCH_HANDLER=$(echo -e "Firefox\nW3M\nLynx\nSurf\nYewTube" | dmenu -p "With" $DMENU_OPTIONS) +WEB_SEARCH_URL="https://duckduckgo.com/?q=$SEARCH_TERM" +GOPHER_SEARCH_URL="gopher://gopher.icu/7/quarry?$SEARCH_TERM" +SEARCH_HANDLER=$(echo -e "Gopher\nFirefox\nW3M\nLynx\nSurf\nYewTube" | dmenu -p "With" $DMENU_OPTIONS) if [ -z $SEARCH_HANDLER ]; then exit; fi case $SEARCH_HANDLER in - Firefox) firefox "$SEARCH_URL" ;; - W3M) urxvt -e w3m "$SEARCH_URL" ;; - Lynx) urxvt -e lynx "$SEARCH_URL" ;; - #Lynx) urxvt -e tmux -c "lynx \"$SEARCH_URL"\" ;; - Surf) surf -B -g -f -a @ "$SEARCH_URL" ;; + Gopher) urxvt -e lynx "$GOPHER_SEARCH_URL" ;; + Firefox) firefox "$WEB_SEARCH_URL" ;; + W3M) urxvt -e w3m "$WEB_SEARCH_URL" ;; + Lynx) urxvt -e lynx "$WEB_SEARCH_URL" ;; + #Lynx) urxvt -e tmux -c "lynx \"$WEB_SEARCH_URL"\" ;; + Surf) surf -B -g -f -a @ "$WEB_SEARCH_URL" ;; YewTube) firefox "https://yewtu.be/search?q=$SEARCH_TERM" ;; esac