URI: 
       Initial code - dsearch - Simple script to launch and remember search queries using dmenu.
   DIR Log
   DIR Files
   DIR Refs
       ---
   DIR commit 5d470c08913b17c0bd430c078b6f35602f00af51
  HTML Author: Scarlett McAllister <git@roygbyte.com>
       Date:   Wed, 14 Jun 2023 21:21:02 -0300
       
       Initial code
       
       Diffstat:
         A dsearch                             |      72 +++++++++++++++++++++++++++++++
       
       1 file changed, 72 insertions(+), 0 deletions(-)
       ---
   DIR diff --git a/dsearch b/dsearch
       @@ -0,0 +1,72 @@
       +#!/bin/bash
       +#
       +# Title: Untitled
       +# Author: Roygbyte
       +# Description: Smol script to easily and quickly launch a search query.
       +# Date: April, 2023
       +# Version: 0.1
       +#
       +# Installation
       +# =========
       +# Place file inside user's bin folder, i.e.: /home/someone/bin. Make the file executable with
       +# `chmod +x search-dmenu.sh`. Then, bind a key to the file in your i3 conf, e.g.:
       +# `bindsym $mod+q exec search-dmenu.sh`.
       +#
       +# Configuration
       +# ===========
       +# Variables of interest are `SEARCH_URL`, which defines the URL used for conduct the
       +# search query. By default, it's DuckDuckGo. `SEARCH_HANDLER`, which contains a string
       +# of new-line separated search handlers. By default, it includes FireFox, W3M, Lynx,
       +# and Suckless' Surf. If you change the search handlers, you may also need to change
       +# the case block to match. Oh: if you're running with the defaults, at least double-check
       +# that the case block dispatcher for the search handlers is using the right terminal for you.
       +# By default, it uses urxvt to dispatch W3M and Lynx.
       +
       +HISTORY="/home/$USER/bin/.search-history"
       +HISTORY_COUNT=10
       +DMENU_OPTIONS=" -b -fn Iosevka-18 -nb #000000 -nf #FFFFFF -sb #0000FF"
       +
       +function add_history_item() {
       +        SEARCH_TERM="$1" # Use $1, which is argument.
       +        if [ ! -a "$HISTORY" ]; then
       +                touch "$HISTORY"
       +        fi
       +        # 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"
       +        mv "$HISTORY.temp" $HISTORY
       +}
       +
       +SEARCH_TERM=$(cat $HISTORY | dmenu -p "Search" -l $HISTORY_COUNT $DMENU_OPTIONS)
       +
       +if [ -z $SEARCH_TERM ]; then
       +        # Exit on ESC, producing empty string
       +        exit;
       +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)
       +
       +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" ;;
       +        YewTube) firefox "https://yewtu.be/search?q=$SEARCH_TERM" ;;
       +esac
       +
       +         # Ugh, I would like to use something better for settingup the search handlers, like an array. But Idk.
       +         # declare -A SEARCH_HANDLERS
       +         # SEARCH_HANDLERS[0]="Firefox|firefox"
       +         # SEARCH_HANDLERS[1]="W3M|urxvt -e w3m"
       +
       +         # SEARCH_HANDLERS=([firefox]=firefox
       +         #                                 [w3m]="urxvt -e w3m") # Colud also declare the array with `declare -A SEARCH_HANDLERS`