mirror of
https://gitlab.com/dwt1/dotfiles.git
synced 2026-08-09 17:41:12 +10:00
Replace multiple if statements with a switch case
This commit is contained in:
@@ -27,51 +27,57 @@ declare options=(" awesome
|
|||||||
|
|
||||||
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"
|
||||||
|
|||||||
+13
-39
@@ -21,42 +21,16 @@ declare -a options=(" r/archlinux
|
|||||||
|
|
||||||
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
|
|
||||||
|
|||||||
+21
-27
@@ -20,30 +20,24 @@ declare -a options=(" htop
|
|||||||
|
|
||||||
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
|
|
||||||
|
|||||||
+15
-10
@@ -15,16 +15,21 @@ declare -a options=(" tastyworks
|
|||||||
|
|
||||||
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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user