Fresh initial state

This commit is contained in:
Reid 'arrdem' McKenzie 2016-09-30 10:19:41 -07:00
commit 7ebdd0490f
2 changed files with 68 additions and 0 deletions

24
README.md Normal file
View file

@ -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

44
goto.plugin.zsh Normal file
View file

@ -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 <name> [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 <name>"
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