diff --git a/README.md b/README.md index 917fb23..67f4a37 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ This project is currently a work-in-progress. Only the fish shell is supported a ## TODO - Documentation/License - - Installation & Generalization + - Uninstaller & Updater - Command Memory/Env Support - Double wh does an la, not ls - directory history for ls'ing back diff --git a/do_what.bash b/do_what.bash deleted file mode 100644 index 3468ec2..0000000 --- a/do_what.bash +++ /dev/null @@ -1,3 +0,0 @@ -function wh { - source <(python3 /home/glmdev/Projects/do_what/do_what.py $*) -} diff --git a/do_what.fish b/do_what.fish deleted file mode 100644 index d604432..0000000 --- a/do_what.fish +++ /dev/null @@ -1,3 +0,0 @@ -function wh - python3 /home/glmdev/Projects/do_what/do_what.py $argv | . -end diff --git a/do_what.py b/do_what.py index a0df692..c49a01a 100644 --- a/do_what.py +++ b/do_what.py @@ -8,7 +8,12 @@ import json mime = magic.Magic(mime=True) # supported values: fish, bash, zsh -shell="fish" +if ( 'DO_WHAT_SHELL' in os.environ ): + shell=os.environ['DO_WHAT_SHELL'] +else: + print("echo Shell type not set. To set up the environment, add the following line to your shell\\\'s init file:") + print("echo dowhat {shell} \| .") + exit() # Defaults print_file="cat" diff --git a/do_what_aliaser.py b/do_what_aliaser.py new file mode 100644 index 0000000..bbfe02a --- /dev/null +++ b/do_what_aliaser.py @@ -0,0 +1,16 @@ +import sys + +if ( len(sys.argv) > 1 ): + shell = sys.argv[1] + if ( shell == "fish" ): + print("function wh") + print(" set -x DO_WHAT_SHELL fish") + print(" python3 "+interpreter_location+" $argv | .") + print("end") + elif ( shell == "bash" or shell == "zsh" ): + print("function wh {") + print(" export DO_WHAT_SHELL="+shell) + print(" source <(python3 "+interpreter_location+" $*)") + print("}") +else: + print("No shell specified.") diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..ad92d4a --- /dev/null +++ b/install.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +INSTALL_DIR=$(readlink -f $1) + +# Make the installation directory +mkdir -p $INSTALL_DIR/do_what +mkdir -p $INSTALL_DIR/bin + +cp ./do_what.py $INSTALL_DIR/do_what/interpreter.py + +echo "#!/usr/bin/env python3" > $INSTALL_DIR/do_what/dowhat +echo "interpreter_location=\"$INSTALL_DIR/do_what/interpreter.py\"" >> $INSTALL_DIR/do_what/dowhat +cat ./do_what_aliaser.py >> $INSTALL_DIR/do_what/dowhat + +ln -s $INSTALL_DIR/do_what/dowhat $INSTALL_DIR/bin/dowhat +chmod +x $INSTALL_DIR/do_what/dowhat + +echo "End."