From 701e454dd6b25acd2b0fbf2bc07a5d809029c84d Mon Sep 17 00:00:00 2001 From: Alexander Bolodurin Date: Sat, 18 May 2013 21:58:41 +1000 Subject: [PATCH] Add Fish support. --- bin/autojump.fish | 86 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 bin/autojump.fish diff --git a/bin/autojump.fish b/bin/autojump.fish new file mode 100644 index 0000000..1421a91 --- /dev/null +++ b/bin/autojump.fish @@ -0,0 +1,86 @@ +complete -x -c j -a '(autojump --bash --complete (commandline -t))' + +switch "$XDG_DATA_HOME" + case "*$USER*" + set -x AUTOJUMP_DATA_DIR "$XDG_DATA_HOME/autojump" + case '*' + set -x AUTOJUMP_DATA_DIR ~/.local/share/autojump +end + +if not test -d $AUTOJUMP_DATA_DIR + mkdir $AUTOJUMP_DATA_DIR +end + +# local installation +if test -d ~/.autojump + export PATH ~/.autojump/bin $PATH +end + +set -x AUTOJUMP_HOME $HOME + +function __aj_err + echo $argv 1>&2; false +end + +function __aj_not_found + __aj_err "autojump: directory '"$argv"' not found" + __aj_err "Try `autojump --help` for more information." +end + +function __aj_add --on-variable PWD + status --is-command-substitution; and return + autojump -a (pwd) >/dev/null ^$AUTOJUMP_DATA_DIR/autojump_errors +end + +function j + switch "$argv" + case '-*' '--*' + autojump $argv + case '*' + set -l new_path (autojump $argv) + if test -d "$new_path" + set_color red + echo $new_path + set_color normal + cd $new_path + else + __aj_not_found $argv + end + end +end + +function jc + switch "$argv" + case '-*' + j $argv + case '*' + j (pwd) $argv + end +end + +function jo + if test -z (autojump $argv) + __aj_not_found $argv + else + switch (sh -c 'echo ${OSTYPE}') + case linux-gnu + xdg-open (autojump $argv) + case 'darwin*' + open (autojump $argv) + case cygwin + cygstart "" (cygpath -w -a (pwd)) + case '*' + __aj_error "Unknown operating system." + end + echo end + end +end + +function jco + switch "$argv" + case '-*' + j $argv + case '*' + jo (pwd) $argv + end +end