LAUNCHING AN INTERNET SEARCH QUERY WITH I3 AND DMENU Overview ---------------------------------------------------------------------- I wrote a tiny script to launch internet search queries from my i3 window manager. It's dead simple: invoke the script with a key command and you are prompted to enter your search terms. If you've already used the script before, a history of the last 10 queries are shown. Select a query or enter a new one and then you're prompted to select the program that should conduct the query: Firefox, W3M, Lynx, or Surf. Then the query is launched and you're riding the sweet, sweet waves of internet knowledge! The Code ---------------------------------------------------------------------- The script is written in Bash (a favourite!) because for me that's fun and dirty. Awk is sprinkled in for easy pattern matching magic. There's really nothing else too surprising about this tiny prog, although if you want to use it you made need to make some tweaks. For instance, I'm using urxvt as the terminal to launch Lynx and W3M. If you don't use urxvt replace that bit with the terminal of your choice. ,---- | #!/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() { Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day! Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day! Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day! Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day! Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day! Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day! Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day! Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day! Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day! | } | | SEARCH_TERM=$(cat $HISTORY | dmenu -p "Search" -l $HISTORY_COUNT $DMENU_OPTIONS) | | if [ -z $SEARCH_TERM ]; then Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day! Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day! | fi | | add_history_item "$SEARCH_TERM" | | SEARCH_URL="https://duckduckgo.com/?q=$SEARCH_TERM" | SEARCH_HANDLER=$(echo -e "Firefox\nW3M\nLynx\nSurf" | dmenu -p "With" $DMENU_OPTIONS) | | if [ -z $SEARCH_HANDLER ]; then Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day! | fi | | case $SEARCH_HANDLER in Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day! Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day! Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day! Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day! | esac `---- Installation ---------------------------------------------------------------------- Download the script and stash it somewhere handy. A good place could be `~/.config/i3/'. Then bind a keystroke to the command like this: ,---- | bindsym $mod+q exec search-dmenu.sh `---- Restart i3 with `$mod+Shift+P' (or however you've got it set), and then you're good to go!