From 7ebdd0490fc46e86e1c301c27ce5bd7cae27bd38 Mon Sep 17 00:00:00 2001 From: Reid 'arrdem' McKenzie Date: Fri, 30 Sep 2016 10:19:41 -0700 Subject: [PATCH] Fresh initial state --- README.md | 24 ++++++++++++++++++++++++ goto.plugin.zsh | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 README.md create mode 100644 goto.plugin.zsh diff --git a/README.md b/README.md new file mode 100644 index 0000000..9a4fc75 --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# goto.zsh +If you're like me and you maintain a hierarchical filesystem, it can be a real +pain to get where you want to go. I know they're considered harmful, but why not +try a `goto`? + +```shell +$ cd ~/doc/programming/web/arrdem.com +$ echo $PWD +/home/reid/doc/programming/web/arrdem.com +# that's long as hell... let's fix that +$ label arrdem.com +$ cd +$ echo $PWD +/home/reid +$ goto arrdem.com +$ echo $PWD +/home/reid/doc/programming/web/arrdem.com +``` + +This is a relatively alpha script and could use some serious attention. + +- no way to delete labels once you set them besides editing the labels file +- the labels file (~/.labels.tsv) _must_ be tab seperated +- the error messages on a missing label are useless diff --git a/goto.plugin.zsh b/goto.plugin.zsh new file mode 100644 index 0000000..c27cdc2 --- /dev/null +++ b/goto.plugin.zsh @@ -0,0 +1,44 @@ +# goto.zsh + +function _gotofile { + echo $GOTO_FILE "$HOME/.labels.tsv" | awk "{print \$1}" +} + +function _makeLabel { + printf "%s %s\n" $1 $2 >> `_gotofile` +} + +function label { + if [ $# -eq 0 ] + then + echo "Usage: $ label [dir]" + echo " creates a label which goto can cd to" + elif [ -d "$2" ] + then + _makeLabel $1 $2 + else + _makeLabel $1 $PWD + fi +} + +function goto { + if [ $# -eq 0 ] + then + echo "Usage: $ goto " + echo " jumps to a record set by label" + elif [[ "$1" == "ls" ]] + then + awk "{ print \$1 }" `_gotofile` | column -t + else + cd $(awk "/^$1\s/ {print \$2;exit;}" `_gotofile`) + fi +} + +function _goto { + for label in $(awk '{print $1}' `_gotofile`) + do + compadd "$@" $label + done +}; + +compdef _goto goto