summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJTaylor <jtaylor@classicalconversations.com>2020-12-09 09:58:54 -0500
committerJTaylor <jtaylor@classicalconversations.com>2020-12-09 09:58:54 -0500
commit8aed1d9d47cee685bce0e584fd9663c4ba1a8e5c (patch)
tree5e6d5db56257c185710cf196a2ce92abf1f315fc
parente088c950b8098164b51e0a01b78233dd0a32fc29 (diff)
Remove nested if statements in favor of returns
-rw-r--r--japh48
1 files changed, 25 insertions, 23 deletions
diff --git a/japh b/japh
index 91405a3..2bc8b26 100644
--- a/japh
+++ b/japh
@@ -23,39 +23,41 @@ function japh() {
"n")
if [ -z $2 ]; then
echo "Command must not be empty!"
- japh_usage
- else
- cmd_name=$2
+ return
+ fi
- cmd_tmp_file=/tmp/japh_$cmd_name
+ cmd_name=$2
- $EDITOR $cmd_tmp_file
+ cmd_tmp_file=/tmp/japh_$cmd_name
- if [ ! -s $cmd_tmp_file ]; then
- echo "You must have a command!"
- else
- printf "function cmd_$cmd_name() {\n" >> $JAPH_DIR/cmds
- cat $cmd_tmp_file >> $JAPH_DIR/cmds
- printf "\n}\n" >> $JAPH_DIR/cmds
- fi
+ $EDITOR $cmd_tmp_file
+
+ if [ ! -s $cmd_tmp_file ]; then
+ echo "You must have a command!"
+ else
+ printf "function cmd_$cmd_name() {\n" >> $JAPH_DIR/cmds
+ cat $cmd_tmp_file >> $JAPH_DIR/cmds
+ printf "\n}\n" >> $JAPH_DIR/cmds
+ rm $cmd_tmp_file
fi
;;
"r")
if [ -z $2 ]; then
echo "Command must not be empty!"
japh_usage
- else
- source $JAPH_DIR/cmds
- type cmd_$2 &> /dev/null
- status=$?
+ return
+ fi
- if [ $status -eq 0 ];
- then
- cmd_$2
- else
- echo "Command was not found!"
- japh_usage
- fi
+ source $JAPH_DIR/cmds
+ type cmd_$2 &> /dev/null
+ status=$?
+
+ if [ $status -eq 0 ];
+ then
+ cmd_$2
+ else
+ echo "Command was not found!"
+ japh_usage
fi
;;
"help" | "-h")