From ae4d1093a2375618f7b2f81abb54327a1eaa6aee Mon Sep 17 00:00:00 2001 From: rickyjon Date: Sat, 9 Nov 2019 14:35:51 +1100 Subject: [PATCH] Add error-handling and better optimization --- new.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/new.sh b/new.sh index 2b41afc..8bb9698 100755 --- a/new.sh +++ b/new.sh @@ -1,21 +1,21 @@ #!/usr/bin/env bash -# ____ _____ +# ____ _____ # | _ \_ _| Derek Taylor (DistroTube) # | | | || | http://www.youtube.com/c/DistroTube -# | |_| || | http://www.gitlab.com/dwt1/ -# |____/ |_| +# | |_| || | http://www.gitlab.com/dwt1/ +# |____/ |_| # # This is a test script -myDir='/home/dt/test/' +myDir="$HOME/test/" dirOptions=$(cd ${myDir} && /bin/ls -d */ | cut -d " " -f 1) dirChoice=$(echo -e "${dirOptions[@]}\nquit" | dmenu -i -p 'My directories: ') if [ "$dirChoice" == "quit" ]; then echo "Program terminated." -elif [ "$dirChoice" == ${dirChoice} ]; then - fileOptions=$(cd ${myDir}${dirChoice} && /bin/ls -Ap | cut -d " " -f 1 | grep -v / ) - fileChoice=$(echo -e "${fileOptions[@]}" | dmenu -i -l 15 -p 'Edit this file: ') - exec emacsclient -c ${myDir}${dirChoice}${fileChoice} +elif [ -n "$dirChoice" ]; then + fileChoice=$(/bin/ls ${myDir}'/'${dirChoice} -Apb | cut -d " " -f 1 | \ + grep -v / | dmenu -i -l 15 -p 'Edit this file: ') + [ -n "$fileChoice" ] && exec emacsclient -c ${myDir}${dirChoice}${fileChoice} fi