Replace multiple if statements with a switch case

This commit is contained in:
rickyjon 2019-11-12 09:34:19 +11:00
parent e9999ec202
commit ede8511a22
4 changed files with 154 additions and 175 deletions

View File

@ -1,77 +1,83 @@
#!/bin/bash
# ____ _____
# ____ _____
# | _ \_ _| Derek Taylor (DistroTube)
# | | | || | http://www.youtube.com/c/DistroTube
# | |_| || | http://www.gitlab.com/dwt1/
# |____/ |_|
# | |_| || | http://www.gitlab.com/dwt1/
# |____/ |_|
#
# Dmenu script for editing some of my more frequently edited config files.
declare options=(" awesome
bash
bspwm
dwm
emacs
herbstluftwm
i3
polybar
qtile
st
sxhkd
vim
xmobar
xmonad
zsh
quit ")
declare options=("awesome
bash
bspwm
dwm
emacs
herbstluftwm
i3
polybar
qtile
st
sxhkd
vim
xmobar
xmonad
zsh
quit")
choice=$(echo -e "${options[@]}" | dmenu -i -p 'Edit a config file: ')
if [ "$choice" == ' quit ' ]; then
echo "Program terminated."
fi
if [ "$choice" == ' awesome ' ]; then
exec emacsclient -c '~/.config/awesome/rc.lua'
fi
if [ "$choice" == ' bash ' ]; then
exec emacsclient -c '~/.bashrc'
fi
if [ "$choice" == ' bspwm ' ]; then
exec emacsclient -c '~/.config/bspwm/bspwmrc'
fi
if [ "$choice" == ' dwm ' ]; then
exec emacsclient -c '~/dwm/config.h'
fi
if [ "$choice" == ' emacs ' ]; then
exec emacsclient -c '~/.emacs.d/init.el'
fi
if [ "$choice" == ' herbstluftwm ' ]; then
exec emacsclient -c '~/.config/herbstluftwm/autostart'
fi
if [ "$choice" == ' i3 ' ]; then
exec emacsclient -c '~/.i3/config'
fi
if [ "$choice" == ' polybar ' ]; then
exec emacsclient -c '~/.config/polybar/config'
fi
if [ "$choice" == ' qtile ' ]; then
exec emacsclient -c '~/.config/qtile/config.py'
fi
if [ "$choice" == ' st ' ]; then
exec emacsclient -c '~/st/config.h'
fi
if [ "$choice" == ' sxhkd ' ]; then
exec emacsclient -c '~/.config/sxhkd/sxhkdrc'
fi
if [ "$choice" == ' vim ' ]; then
exec emacsclient -c '~/.vimrc'
fi
if [ "$choice" == ' xmobar ' ]; then
exec emacsclient -c '~/.config/xmobar/xmobarrc2'
fi
if [ "$choice" == ' xmonad ' ]; then
exec emacsclient -c '~/.xmonad/xmonad.hs'
fi
if [ "$choice" == ' zsh ' ]; then
exec emacsclient -c '~/.zshrc'
fi
case "$choice" in
quit)
echo "Program terminated." && exit 1
;;
awesome)
choice="HOME/.config/awesome/rc.lua"
;;
bash)
choice="HOME/.bashrc"
;;
bspwm)
choice="HOME/.config/bspwm/bspwmrc"
;;
dwm)
choice="HOME/dwm/config.h"
;;
emacs)
choice="HOME/.emacs.d/init.el"
;;
herbstluftwm)
choice="HOME/.config/herbstluftwm/autostart"
;;
i3)
choice="HOME/.i3/config"
;;
polybar)
choice="HOME/.config/polybar/config"
;;
qtile)
choice="HOME/.config/qtile/config.py"
;;
st)
choice="HOME/st/config.h"
;;
sxhkd)
choice="HOME/.config/sxhkd/sxhkdrc"
;;
vim)
choice="HOME/.vimrc"
;;
xmobar)
choice="HOME/.config/xmobar/xmobarrc2"
;;
xmonad)
choice="HOME/.xmonad/xmonad.hs"
;;
zsh)
choice="HOME/.zshrc"
;;
*)
exit 1
;;
esac
emacsclient -c "$choice"

View File

@ -1,62 +1,36 @@
#!/bin/bash
# ____ _____
# ____ _____
# | _ \_ _| Derek Taylor (DistroTube)
# | | | || | http://www.youtube.com/c/DistroTube
# | |_| || | http://www.gitlab.com/dwt1/
# |____/ |_|
# | |_| || | http://www.gitlab.com/dwt1/
# |____/ |_|
#
# Dmenu script for reddio - a command line Reddit viewer.
declare -a options=(" r/archlinux
r/commandline
r/DistroTube
r/GopherHoles
r/linux
r/linuxmasterrace
r/unixporn
r/linux4noobs
r/vim
quit ")
declare -a options=("r/archlinux
r/commandline
r/DistroTube
r/GopherHoles
r/linux
r/linuxmasterrace
r/unixporn
r/linux4noobs
r/vim
quit")
choice=$(echo -e "${options[@]}" | dmenu -l 10 -i -p 'Last 10 Posts From Reddit: ')
if [ "$choice" == ' quit ' ]; then
echo "Program terminated."
fi
if [ "$choice" == ' r/archlinux ' ]; then
reddio print -l 15 r/archlinux | sed 's/\x1b\[[0-9;]*m//g' | dmenu -l 15 -i -p 'r/archlinux'
exec st -e $SHELL -c 'reddio print -l 10 r/archlinux;$SHELL'
fi
if [ "$choice" == ' r/commandline ' ]; then
reddio print -l 15 r/archlinux | sed 's/\x1b\[[0-9;]*m//g' | dmenu -l 15 -i -p 'r/commandline'
exec st -e $SHELL -c 'reddio print -l 10 r/commandline;$SHELL'
fi
if [ "$choice" == ' r/DistroTube ' ]; then
reddio print -l 15 r/archlinux | sed 's/\x1b\[[0-9;]*m//g' | dmenu -l 15 -i -p 'r/DistroTube'
exec st -e $SHELL -c 'reddio print -l 10 r/DistroTube;$SHELL'
fi
if [ "$choice" == ' r/GopherHoles ' ]; then
reddio print -l 15 r/archlinux | sed 's/\x1b\[[0-9;]*m//g' | dmenu -l 15 -i -p 'r/GopherHoles'
exec st -e $SHELL -c 'reddio print -l 10 r/GopherHoles;$SHELL'
fi
if [ "$choice" == ' r/linux ' ]; then
reddio print -l 15 r/archlinux | sed 's/\x1b\[[0-9;]*m//g' | dmenu -l 15 -i -p 'r/linux'
exec st -e $SHELL -c 'reddio print -l 10 r/linux;$SHELL'
fi
if [ "$choice" == ' r/linuxmasterrace ' ]; then
reddio print -l 15 r/archlinux | sed 's/\x1b\[[0-9;]*m//g' | dmenu -l 15 -i -p 'r/linuxmasterrace'
exec st -e $SHELL -c 'reddio print -l 10 r/linuxmasterrace;$SHELL'
fi
if [ "$choice" == ' r/unixporn ' ]; then
reddio print -l 15 r/archlinux | sed 's/\x1b\[[0-9;]*m//g' | dmenu -l 15 -i -p 'r/unixporn'
exec st -e $SHELL -c 'reddio print -l 10 r/unixporn;$SHELL'
fi
if [ "$choice" == ' r/linux4noobs ' ]; then
reddio print -l 15 r/archlinux | sed 's/\x1b\[[0-9;]*m//g' | dmenu -l 15 -i -p 'r/linux4noobs'
exec st -e $SHELL -c 'reddio print -l 10 r/linux4noobs;$SHELL'
fi
if [ "$choice" == ' r/vim ' ]; then
reddio print -l 15 r/archlinux | sed 's/\x1b\[[0-9;]*m//g' | dmenu -l 15 -i -p 'r/vim'
exec st -e $SHELL -c 'reddio print -l 10 r/vim;$SHELL'
fi
case "$choice" in
quit)
echo "Program terminated." && exit 1
;;
r/*)
reddio print -l 15 "$choice" | sed 's/\x1b\[[0-9;]*m//g' \
| dmenu -l 15 -i -p "$choice"
exec st -e $SHELL -c "reddio print -l 10 $choice;$SHELL"
;;
*)
exit 1
;;
esac

View File

@ -1,49 +1,43 @@
#!/bin/bash
# ____ _____
# ____ _____
# | _ \_ _| Derek Taylor (DistroTube)
# | | | || | http://www.youtube.com/c/DistroTube
# | |_| || | http://www.gitlab.com/dwt1/
# |____/ |_|
# | |_| || | http://www.gitlab.com/dwt1/
# |____/ |_|
#
# Dmenu script for launching system monitoring programs.
declare -a options=(" htop
glances
gtop
iftop
iotop
iptraf-ng
nmon
s-tui
quit ")
declare -a options=("htop
glances
gtop
iftop
iotop
iptraf-ng
nmon
s-tui
quit")
choice=$(echo -e "${options[@]}" | dmenu -l -i -p 'System monitors: ')
if [ "$choice" == ' quit ' ]; then
echo "Program terminated."
fi
if [ "$choice" == ' htop ' ]; then
exec st -e htop
fi
if [ "$choice" == ' glances ' ]; then
exec st -e glances
fi
if [ "$choice" == ' gtop ' ]; then
exec st -e gtop
fi
if [ "$choice" == ' iftop ' ]; then
exec st -e gksu iftop
fi
if [ "$choice" == ' iotop ' ]; then
exec st -e gksu iotop
fi
if [ "$choice" == ' iptraf-ng ' ]; then
exec st -e gksu iptraf-ng
fi
if [ "$choice" == ' nmon ' ]; then
exec st -e nmon
fi
if [ "$choice" == ' s-tui ' ]; then
exec st -e s-tui
fi
case $choice in
quit)
echo "Program terminated." && exit 1
;;
htop| \
glances| \
gtop| \
nmon| \
s-tui)
exec st -e $choice
;;
iftop| \
iotop| \
iptraf-ng)
exec st -e gksu $choice
;;
*)
exit 1
;;
esac

View File

@ -1,30 +1,35 @@
#!/bin/bash
# ____ _____
# ____ _____
# | _ \_ _| Derek Taylor (DistroTube)
# | | | || | http://www.youtube.com/c/DistroTube
# | |_| || | http://www.gitlab.com/dwt1/
# |____/ |_|
# | |_| || | http://www.gitlab.com/dwt1/
# |____/ |_|
#
# Dmenu script for launching trading programs.
declare -a options=(" tastyworks
tastytrade
thinkorswim
quit ")
declare -a options=("tastyworks
tastytrade
thinkorswim
quit")
choice=$(echo -e "${options[@]}" | dmenu -l -i -p 'System monitors: ')
if [ "$choice" == ' quit ' ]; then
echo "Program terminated."
fi
if [ "$choice" == ' tastyworks ' ]; then
case $choice in
quit)
echo "Program terminated." && exit 1
;;
tastyworks)
exec /opt/tastyworks/tastyworks
fi
if [ "$choice" == ' tastytrade ' ]; then
;;
tastytrade)
exec firefox tastytrade.com
fi
if [ "$choice" == ' thinkorswim ' ]; then
exec /home/dt/thinkorswim/thinkorswim
fi
;;
thinkorswim)
exec "$HOME/thinkorswim/thinkorswim"
;;
*)
exit 1
;;
esac