• i3 or i3-gaps
  • dmenu
  • rofi
  • dunstify
  • kitty
  • zsh
  • mpc
  • putty
  • qutebrowser
  • xdotool
  • warp
  • feh
  • expressvpn
  • pcmanfm
  • pyradio
  • arecord
  • aplay
  • The necessary fonts

dmenu / rofi

Select an SSH session (requires putty)

In your i3-gaps ( or i3 ) configuration file, put the following line:

  • bindsym $alt+Ctrl+s exec ~/scripts/putty.sh
#!/bin/bash

OLD_IFS="$IFS"
IFS=$'\n' win_array=($(ls --ignore="Default*" ~/.config/putty/sessions))
IFS="$OLD_IFS"

win_length=${#win_array[@]}

# echo $win_length

for i in "${!win_array[@]}"; do
  win_array[$i]=${win_array[$i]//"%20"/" "}
  win_array[$i]=${win_array[$i]//"%28"/"("}
  win_array[$i]=${win_array[$i]//"%29"/")"}
done

# for i in "${!win_array[@]}"; do
#    echo ${win_array[${i}]};
# done

choice=$(printf '%s\n' "${win_array[@]}" | rofi -dmenu -i -p "Putty Session") "$@" || exit

echo $choice

putty -load "$choice"

exit 0

Select a Web search engine

In your i3-gaps ( or i3 ) configuration file, put the following line:

  • bindsym $alt+Ctrl+slash exec ~/scripts/search.sh
#!/usr/bin/env bash
# # Script name: dmsearch
# Description: Search various search engines (inspired by surfraw).
# Dependencies: dmenu and a web browser
# GitLab: https://www.gitlab.com/dwt1/dmscripts
# Contributors: Derek Taylor
# Defining our web browser.

BROWSER="qutebrowser"

# An array of search engines.  You can edit this list to add/remove # search engines. The format must be: "engine_name - url".
# The url format must allow for the search keywords at the end of the url.
# For example: https://www.amazon.com/s?k=XXXX searches Amazon for 'XXXX'.

declare -a options=(
"startpage - https://www.startpage.com/sp/search?query="
"amazon - https://www.amazon.com/s?k="
"archpkg - https://archlinux.org/packages/?sort=&q="
"archwiki - https://wiki.archlinux.org/index.php?search="
"bbcnews - https://www.bbc.co.uk/search?q="
"bing - https://www.bing.com/search?q="
"cnn - https://www.cnn.com/search?q="
"ebay - https://www.ebay.com/sch/i.html?&_nkw="
"github - https://github.com/search?q="
"gitlab - https://gitlab.com/search?search="
"google - https://www.google.com/search?q="
"reddit - https://www.reddit.com/search/?q="
"slashdot - https://slashdot.org/index2.pl?fhfilter="
"stockquote - https://finance.yahoo.com/quote/"
"thesaurus - https://www.thesaurus.com/misspelling?term="
"translate - https://translate.google.com/?sl=auto&tl=en&text="
"webster - https://www.merriam-webster.com/dictionary/"
"wikipedia - https://en.wikipedia.org/wiki/"
"youtube - https://www.youtube.com/results?search_query="
)

# Picking a search engine.

while [ -z "$engine" ]; do
    enginelist=$(printf '%s\n' "${options[@]}" | rofi -dmenu -i -p 'Search Engine') || exit
    engineurl=$(echo "$enginelist" | awk '{print $NF}')
    engine=$(echo "$enginelist" | awk '{print $1}')
done

# Searching the chosen engine.

while [ -z "$query" ]; do
    query=$(echo -e "" | rofi -dmenu -i -p "Search For") || exit
done

# Display search results in web browser

$BROWSER "$engineurl""$query"

Switch to a directory (requires kitty, zsh, warp, pcmanf)

In your i3-gaps ( or i3 ) configuration file, put the following line:

  • bindsym $alt+Ctrl+period exec /home/karmst/scripts/warp.sh
#!/bin/bash

d_program()
{
  if [[ $cmd != '' ]];
  then
    {
      printf '%s\n' "terminal"
      printf '%s\n' "pcmanfm"
    } | dmenu -l 20 -c -b -fn 'SauceCodePro Nerd Font-16' -sb "#0f61a9" -h 30 -bw 3 -i -p '' ${dmenu_args[@]}
  fi
}

shell_window="zsh"
my_term="kitty"
post_term="--directory"

window=$(xdotool search --name $shell_window)

cmd=$(cat ~/.warprc | sed 's/\(.\+\)\(:\)\(.\+\)/\1/' | sort | rofi -dmenu -sort -l 15 -sb "#0f61a9" -fn 'SauceCodePro Nerd Font-16' -c -i -p "Directory")

if [ -n $cmd ];
then
  url=$(grep "$cmd:" ~/.warprc | sed 's/\(.\+\)\(:\)\(.\+\)/\3/')

  program=$(d_program)

  if [[ ($window != '') &&  ($program == 'terminal') ]]; then
    i3-msg '[title=$shell_window] focus'
    sleep 0.25
    xdotool search --name $shell_window key ctrl+u
    sleep 0.25
    xdotool search --name $shell_window key BackSpace
    xdotool search --name $shell_window type cd " $url"
    xdotool search --name $shell_window key KP_Enter
    xdotool search --name $shell_window type dirt
    xdotool search --name $shell_window key KP_Enter
  fi

  if [[ ($window == '') &&  ($program == 'terminal') ]]; then
      $my_term $post_term $url
      sleep 2
      xdotool search --name $shell_window type dirt
      xdotool search --name $shell_window key KP_Enter
  fi

  if [[ $program == 'pcmanfm' ]]; then
    pcmanfm -n --role="PCManFM" $url
  fi
fi

exit 0

Open a Web Bookmark (requires qutebrowser)

In your i3-gaps ( or i3 ) configuration file, put the following line:

  • bindsym $alt+Ctrl+slash exec ~/scripts/bmarks.sh</li>
#!/usr/bin/env bash
#
# Based on a script by Derek Taylor.
# GitLab: https://www.gitlab.com/dwt1/dmscripts
#
# The script has been greatly expanded upon!

BROWSER=qutebrowser
#BROWSER=librewolf

MYFILE="$HOME/.config/qutebrowser/personal"

# Defining location of bookmarks file
BMFILE="$HOME/.config/qutebrowser/bookmarks/urls"

# Defining location of quickmarks file
QMFILE="$HOME/.config/qutebrowser/quickmarks"

# Defining location of history database
HISTDB="$HOME/.local/share/qutebrowser/history.sqlite"

# A separator that will appear in between quickmarks, bookmarks and history urls.
SEPARATOR="----------"

# Read array of options to choose.
readarray -t bmarks < "$BMFILE"
readarray -t qmarks < "$QMFILE"
readarray -t mymarks < "$MYFILE"

# Sort the bookmark, quickmark and history lists so that the url is the last field.
# We will awk print the last field later.
# History list is formed by grep'ing "http" from the history table.

mylist=$(printf '%s\n' "${mymarks[@]}" | awk '{out=""; for(i=1;i < NF;i++){out=out" "$i}; print "[P]" out "  " $NF}' | sort | uniq)

#bmlist=$(printf '%s\n' "${bmarks[@]}" | awk '{print $2 " " $1}' OFS="(^.+?) " | sort | uniq)
bmlist=$(printf '%s\n' "${bmarks[@]}" | awk '{out=$2; for(i=3;i<=NF;i++){out=out" "$i}; print "[B] " out "  " $1}' | sort | uniq)

# qmlist=$(printf '%s\n' "${qmarks[@]}" | awk '{print "[Q] "$1 "  -> "$NF}' | sort | uniq)
qmlist=$(printf '%s\n' "${qmarks[@]}" | awk '{out=""; for(i=1;i < NF;i++){out=out" "$i}; print "[Q]" out "  " $NF}' | sort | uniq)

SQL="SELECT h.title, h.url FROM history as h where url like 'http%' ORDER BY h.atime DESC;"

histlist=$(printf '%s\n' "$(sqlite3 "$HISTDB" "${SQL}")" | awk -F "|" '{print "[H] "$1"  "$NF}' | sort | uniq)

# Piping the above lists into dmenu.
# We use "printf '%s\n'" to format the array one item to a line.
# The urls are listed quickmarks first, then the SEPARATOR, and then bookmarks.
choice=$(printf '%s\n' "$SEPARATOR" "$mylist" "$SEPARATOR" "$qmlist" "$SEPARATOR" "$bmlist" "$SEPARATOR" "$histlist" "$SEPARATOR" | rofi -dmenu -i -l 25 -p "Open URL ($BROWSER)") "$@" || exit

# What to do if the separator is chosen from the list.
# We simply launch qutebrowser without any url arguments.
# shellcheck disable=SC2154
if [ "$choice" == "$SEPARATOR" ]; then
    $BROWSER
# What to do when/if we choose a url to view.
elif [ "$choice" ]; then
  url=$(echo "${choice}" | awk '{print $NF}') || exit
  $BROWSER "$url"
# What to do if we just escape without choosing anything.
else
    echo "Program terminated." && exit 0
fi

Music (requires mpc)

Play Songs

In your i3-gaps ( or i3 ) configuration file, put the following line:

  • bindsym $alt+Ctrl+m exec ~/scripts/rofi-random.sh
#!/bin/bash

selection=$(echo -e "clear\nkiller\nrandom\nquery\nnewsboat\nmusic_player\nradio_player" | dmenu -c -l 7 -b -bw 3 -fn 'Droid Sans Mono-16' -sb "#0f61a9" -i -p "")

case $selection in
    clear)
        ($HOME/scripts/play_music.sh c) ;;
    random)
        (   random=$(echo -e "" | dmenu -c -b -fn 'Droid Sans Mono-16' -bw 3 -sb "#0f61a9" -i -p "")
            $HOME/scripts/play_music.sh $random
             songs=`mpc playlist`
             dunstify -t 10000 "$songs"
        ) ;;
    query)
        (
            search=$(echo -e "" | dmenu -c -b -bw 3 -fn 'Droid Sans Mono-16' -sb "#0f61a9" -i -p "")
            $HOME/scripts/play_music.sh q $search
            songs=`mpc playlist`
            dunstify -t 10000 "$songs"
        );;
    newsboat)
        (
            kitty -e newsboat
        );;
    music_player)
        (
#          kitty -e $HOME/scripts/musak.sh
           kitty -e ncmpcpp
        ) ;;
    radio_player)
       (
          kitty -e pyradio --use-player vlc
       ) ;;
    killer)
       (
          killall mpv
       );;
esac

play_music.sh

#!/bin/bash

answer=$1
artist=$2

if [ ${#answer} = 0 && ${#artist} = 0 ]
then
  read -p "Clear all songs (c) :: Play all songs (a) :: Number of songs (number) :: Query for songs (q) -> " answer
fi

clear

allsongs=`mpc listall | wc -l`

if [ -z $answer ]
then
  answer=0
fi

case $answer in
'x')
  read -p "Enter search term: " artist
  songs=`mpc listall | grep -i "$artist" | wc -l`
  mpc clear; mpc listall | grep -i "$artist" | shuf | mpc add; mpc play; mpc playlist
  printf "\nShuffling $songs songs\n\n"
  ;;
'0')
  printf "\nNothing to see here!\n\n"
  ;;
'c')
  mpc clear
  printf "\nQueue is now clear\n\n"
  ;;
'a')
  mpc clear; mpc listall | shuf -n $allsongs | mpc add; mpc play; mpc playlist
  printf "\nShuffling $allsongs songs\n\n"
  ;;
'q')
  if [ ${#artist} = 0 ]
  then
      read -p "Enter search term: " artist
  else
     list1=$(mpc listall | grep -i "$artist")
     list2=`mpc search artist $artist`
  fi

  if [ ${#list1} -ge 1 ]
    then
      list=`echo -e "$list1\n$list2"`
    else
      list=`echo -e "$list2"`
  fi

  songs=`echo -e "$list" | wc -l`

  if [ ${#list} -ge 1 ]
    then
      mpc clear; echo -e "$list" | shuf | mpc add; mpc play; mpc playlist
      printf "\nShuffling $songs songs\n\n"
  fi
  ;;
*)
  mpc clear; mpc listall | shuf -n $answer | mpc add; mpc play; mpc playlist
  printf "\nShuffling $answer songs\n\n"
  ;;
esac

Radio

Play a radio station

In your i3-gaps ( or i3 ) configuration file, put the following line:

  • bindsym $alt+Ctrl+r exec ~/scripts/radio.sh
#!/usr/bin/env bash

BROWSER=mpc
MYFILE="$HOME/.config/pyradio/stations.csv"

# Read array of options to choose.
readarray -t stations < "$MYFILE"

mylist=$(printf '%s\n' "${stations[@]}" | awk -F, '{out=""; for(i=1;i < NF;i++){out=out" "$i}; print out "  " $NF}' | sort | uniq)

# Piping the above lists into dmenu.
# We use "printf '%s\n'" to format the array one item to a line.
# The urls are listed quickmarks first, then the SEPARATOR, and then bookmarks.
choice=$(printf '%s\n' "$mylist" | rofi -dmenu -i -l 25 -p "Open URL ($BROWSER)") "$@" || exit

if [ "$choice" ]; then
  url=$(echo "${choice}" | awk '{print $NF}') || exit
  a=${url%$'\r'}

echo $a
mpc clear
mpc add $a
mpc play

#mpc clear && mpc add $a && mpc play

# What to do if we just escape without choosing anything.
else
    echo "Program terminated." && exit 0
fi

Play LBC Radio ( UK Radio Station )

In your i3-gaps ( or i3 ) configuration file, put the following line:

  • bindsym $alt+Ctrl+l exec ~/scripts/lbc.sh
#!/bin/bash

is_playing=$(mpc|awk '/LBC/ {print $2}')

if [[ ${#is_playing} -gt 0 ]]
  then
    mpc clear
  else
    mpc clear && mpc add http://media-ice.musicradio.com/LBCLondon && mpc play
fi

Miscellaneous

Test the microphone

In your i3-gaps ( or i3 ) configuration file, put the following line:

  • bindsym $alt+Ctrl+c exec ~/scripts/git/test_mic.sh
#!/bin/sh
file="test_mic.wav"
duration=5

dunstify "Recording for $duration seconds into $file"
arecord -d $duration $file
dunstify "Now playing $file"
aplay $file
dunstify "$file has been deleted"
rm $file

Random Wallpaper changer

In your i3-gaps ( or i3 ) configuration file, put the following line:

  • bindsym $alt+Ctrl+w exec ~/scripts/random_wp.sh
#!/bin/bash

feh --bg-scale "$(find ~/Pictures/wallpapers/* -type f |sort -R |tail -1)" &
exit 0

Toggle VPN (requires expressvpn)

In your i3-gaps ( or i3 ) configuration file, put the following line:

  • bindsym $alt+Ctrl+v exec ~/scripts/git/dmenu-vpn.sh
#!/bin/bash

# Witten by Keith Armstrong, Belkast Consulting
# The expressvpn service is reqired, and is expected to be running

d_vpns()
{

local vpns
mapfile -t vpns < <(expressvpn list all | awk '{print $1" "$4" "$2}')

vpns=("${vpns[@]:1}") # removed the 1st element
vpns=("${vpns[@]:1}") # removed the 1st element

if (( ${#vpns[@]} > 1 )) ; then
    {
        printf '%s\n' "status [ Get current status ]"
        printf '%s\n' "disconnect [ Disconnect from VPN ]"
        printf '%s\n' "${vpns[@]}" | sort -f
     } | dmenu -l 20 -c -b -fn 'Droid Sans Mono-16' -sb "#9900cc" -h 30 -bw 3 -i -p '' ${dmenu_args[@]}
fi
}

cmd=$(d_vpns | awk '{print $1}')

if [[ $cmd == 'disconnect' ]] || [[ -z $cmd ]];
then
  expressvpn disconnect
elif [[ $cmd == 'status' ]];
then
  varStatus=$(expressvpn status | sed 's/\x1B\[[0-9;]\{1,\}[A-Za-z]//g' | head -n 1)
  dunstify -t 5000 "$varStatus"
else
  expressvpn disconnect
  expressvpn connect $cmd
fi