diff options
author | JTaylor <jtaylor@classicalconversations.com> | 2020-12-08 15:58:52 -0500 |
---|---|---|
committer | JTaylor <jtaylor@classicalconversations.com> | 2020-12-08 15:58:52 -0500 |
commit | bc394d031a45f7ff5346d615c794bcb1c315bdb2 (patch) | |
tree | 798172d364e82213113be9ad16c80c62bb8176e5 | |
parent | 182e67d6c098f53afd407b6eaecbbbb6d1807d5a (diff) |
Add capability to add commands
-rw-r--r-- | japh | 40 |
1 files changed, 40 insertions, 0 deletions
@@ -7,6 +7,8 @@ JAPH_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" CMD_FILE="$JAPH_DIR/cmds" +EDITOR="vim" + function japh() { case $1 in "add") @@ -18,6 +20,44 @@ function japh() { # Show the currently added commands cat $CMD_FILE ;; + "n") + if [ -z $2 ]; then + echo "Command must not be empty!" + japh_usage + else + cmd_name=$2 + + cmd_tmp_file=/tmp/japh_$cmd_name + + $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 + fi + 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=$? + + if [ $status -eq 0 ]; + then + cmd_$2 + else + echo "Command was not found!" + japh_usage + fi + fi + ;; "help" | "-h") japh_usage ;; |