Replace multiple if statements with a switch case

This commit is contained in:
rickyjon
2019-11-12 19:42:23 +11:00
parent e9999ec202
commit ede8511a22
4 changed files with 154 additions and 175 deletions
+73 -67
View File
@@ -1,77 +1,83 @@
#!/bin/bash #!/bin/bash
# ____ _____ # ____ _____
# | _ \_ _| Derek Taylor (DistroTube) # | _ \_ _| Derek Taylor (DistroTube)
# | | | || | http://www.youtube.com/c/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. # Dmenu script for editing some of my more frequently edited config files.
declare options=(" awesome declare options=("awesome
bash bash
bspwm bspwm
dwm dwm
emacs emacs
herbstluftwm herbstluftwm
i3 i3
polybar polybar
qtile qtile
st st
sxhkd sxhkd
vim vim
xmobar xmobar
xmonad xmonad
zsh zsh
quit ") quit")
choice=$(echo -e "${options[@]}" | dmenu -i -p 'Edit a config file: ') choice=$(echo -e "${options[@]}" | dmenu -i -p 'Edit a config file: ')
if [ "$choice" == ' quit ' ]; then case "$choice" in
echo "Program terminated." quit)
fi echo "Program terminated." && exit 1
if [ "$choice" == ' awesome ' ]; then ;;
exec emacsclient -c '~/.config/awesome/rc.lua' awesome)
fi choice="HOME/.config/awesome/rc.lua"
if [ "$choice" == ' bash ' ]; then ;;
exec emacsclient -c '~/.bashrc' bash)
fi choice="HOME/.bashrc"
if [ "$choice" == ' bspwm ' ]; then ;;
exec emacsclient -c '~/.config/bspwm/bspwmrc' bspwm)
fi choice="HOME/.config/bspwm/bspwmrc"
if [ "$choice" == ' dwm ' ]; then ;;
exec emacsclient -c '~/dwm/config.h' dwm)
fi choice="HOME/dwm/config.h"
if [ "$choice" == ' emacs ' ]; then ;;
exec emacsclient -c '~/.emacs.d/init.el' emacs)
fi choice="HOME/.emacs.d/init.el"
if [ "$choice" == ' herbstluftwm ' ]; then ;;
exec emacsclient -c '~/.config/herbstluftwm/autostart' herbstluftwm)
fi choice="HOME/.config/herbstluftwm/autostart"
if [ "$choice" == ' i3 ' ]; then ;;
exec emacsclient -c '~/.i3/config' i3)
fi choice="HOME/.i3/config"
if [ "$choice" == ' polybar ' ]; then ;;
exec emacsclient -c '~/.config/polybar/config' polybar)
fi choice="HOME/.config/polybar/config"
if [ "$choice" == ' qtile ' ]; then ;;
exec emacsclient -c '~/.config/qtile/config.py' qtile)
fi choice="HOME/.config/qtile/config.py"
if [ "$choice" == ' st ' ]; then ;;
exec emacsclient -c '~/st/config.h' st)
fi choice="HOME/st/config.h"
if [ "$choice" == ' sxhkd ' ]; then ;;
exec emacsclient -c '~/.config/sxhkd/sxhkdrc' sxhkd)
fi choice="HOME/.config/sxhkd/sxhkdrc"
if [ "$choice" == ' vim ' ]; then ;;
exec emacsclient -c '~/.vimrc' vim)
fi choice="HOME/.vimrc"
if [ "$choice" == ' xmobar ' ]; then ;;
exec emacsclient -c '~/.config/xmobar/xmobarrc2' xmobar)
fi choice="HOME/.config/xmobar/xmobarrc2"
if [ "$choice" == ' xmonad ' ]; then ;;
exec emacsclient -c '~/.xmonad/xmonad.hs' xmonad)
fi choice="HOME/.xmonad/xmonad.hs"
if [ "$choice" == ' zsh ' ]; then ;;
exec emacsclient -c '~/.zshrc' zsh)
fi choice="HOME/.zshrc"
;;
*)
exit 1
;;
esac
emacsclient -c "$choice"
+26 -52
View File
@@ -1,62 +1,36 @@
#!/bin/bash #!/bin/bash
# ____ _____ # ____ _____
# | _ \_ _| Derek Taylor (DistroTube) # | _ \_ _| Derek Taylor (DistroTube)
# | | | || | http://www.youtube.com/c/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. # Dmenu script for reddio - a command line Reddit viewer.
declare -a options=(" r/archlinux declare -a options=("r/archlinux
r/commandline r/commandline
r/DistroTube r/DistroTube
r/GopherHoles r/GopherHoles
r/linux r/linux
r/linuxmasterrace r/linuxmasterrace
r/unixporn r/unixporn
r/linux4noobs r/linux4noobs
r/vim r/vim
quit ") quit")
choice=$(echo -e "${options[@]}" | dmenu -l 10 -i -p 'Last 10 Posts From Reddit: ') choice=$(echo -e "${options[@]}" | dmenu -l 10 -i -p 'Last 10 Posts From Reddit: ')
if [ "$choice" == ' quit ' ]; then case "$choice" in
echo "Program terminated." quit)
fi echo "Program terminated." && exit 1
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' r/*)
exec st -e $SHELL -c 'reddio print -l 10 r/archlinux;$SHELL' reddio print -l 15 "$choice" | sed 's/\x1b\[[0-9;]*m//g' \
fi | dmenu -l 15 -i -p "$choice"
if [ "$choice" == ' r/commandline ' ]; then exec st -e $SHELL -c "reddio print -l 10 $choice;$SHELL"
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 exit 1
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' esac
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
+33 -39
View File
@@ -1,49 +1,43 @@
#!/bin/bash #!/bin/bash
# ____ _____ # ____ _____
# | _ \_ _| Derek Taylor (DistroTube) # | _ \_ _| Derek Taylor (DistroTube)
# | | | || | http://www.youtube.com/c/DistroTube # | | | || | http://www.youtube.com/c/DistroTube
# | |_| || | http://www.gitlab.com/dwt1/ # | |_| || | http://www.gitlab.com/dwt1/
# |____/ |_| # |____/ |_|
# #
# Dmenu script for launching system monitoring programs. # Dmenu script for launching system monitoring programs.
declare -a options=(" htop declare -a options=("htop
glances glances
gtop gtop
iftop iftop
iotop iotop
iptraf-ng iptraf-ng
nmon nmon
s-tui s-tui
quit ") quit")
choice=$(echo -e "${options[@]}" | dmenu -l -i -p 'System monitors: ') choice=$(echo -e "${options[@]}" | dmenu -l -i -p 'System monitors: ')
if [ "$choice" == ' quit ' ]; then case $choice in
echo "Program terminated." quit)
fi echo "Program terminated." && exit 1
if [ "$choice" == ' htop ' ]; then ;;
exec st -e htop htop| \
fi glances| \
if [ "$choice" == ' glances ' ]; then gtop| \
exec st -e glances nmon| \
fi s-tui)
if [ "$choice" == ' gtop ' ]; then exec st -e $choice
exec st -e gtop ;;
fi iftop| \
if [ "$choice" == ' iftop ' ]; then iotop| \
exec st -e gksu iftop iptraf-ng)
fi exec st -e gksu $choice
if [ "$choice" == ' iotop ' ]; then ;;
exec st -e gksu iotop *)
fi exit 1
if [ "$choice" == ' iptraf-ng ' ]; then ;;
exec st -e gksu iptraf-ng esac
fi
if [ "$choice" == ' nmon ' ]; then
exec st -e nmon
fi
if [ "$choice" == ' s-tui ' ]; then
exec st -e s-tui
fi
+22 -17
View File
@@ -1,30 +1,35 @@
#!/bin/bash #!/bin/bash
# ____ _____ # ____ _____
# | _ \_ _| Derek Taylor (DistroTube) # | _ \_ _| Derek Taylor (DistroTube)
# | | | || | http://www.youtube.com/c/DistroTube # | | | || | http://www.youtube.com/c/DistroTube
# | |_| || | http://www.gitlab.com/dwt1/ # | |_| || | http://www.gitlab.com/dwt1/
# |____/ |_| # |____/ |_|
# #
# Dmenu script for launching trading programs. # Dmenu script for launching trading programs.
declare -a options=(" tastyworks declare -a options=("tastyworks
tastytrade tastytrade
thinkorswim thinkorswim
quit ") quit")
choice=$(echo -e "${options[@]}" | dmenu -l -i -p 'System monitors: ') choice=$(echo -e "${options[@]}" | dmenu -l -i -p 'System monitors: ')
if [ "$choice" == ' quit ' ]; then case $choice in
echo "Program terminated." quit)
fi echo "Program terminated." && exit 1
if [ "$choice" == ' tastyworks ' ]; then ;;
tastyworks)
exec /opt/tastyworks/tastyworks exec /opt/tastyworks/tastyworks
fi ;;
if [ "$choice" == ' tastytrade ' ]; then tastytrade)
exec firefox tastytrade.com exec firefox tastytrade.com
fi ;;
if [ "$choice" == ' thinkorswim ' ]; then thinkorswim)
exec /home/dt/thinkorswim/thinkorswim exec "$HOME/thinkorswim/thinkorswim"
fi ;;
*)
exit 1
;;
esac