From 8aed1d9d47cee685bce0e584fd9663c4ba1a8e5c Mon Sep 17 00:00:00 2001 From: JTaylor Date: Wed, 9 Dec 2020 09:58:54 -0500 Subject: Remove nested if statements in favor of returns --- japh | 48 +++++++++++++++++++++++++----------------------- 1 file 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") -- cgit v1.2.3