1
0
mirror of https://github.com/wting/autojump synced 2024-10-27 20:34:07 +00:00
wting_autojump/bin/autojump.fish

107 lines
2.5 KiB
Fish
Raw Normal View History

set -x AUTOJUMP_SOURCED 1
# set user installation path
2013-05-18 11:58:41 +00:00
if test -d ~/.autojump
2013-05-25 12:28:06 +00:00
set -x PATH ~/.autojump/bin $PATH
2013-05-18 11:58:41 +00:00
end
# enable tab completion
2013-12-31 16:59:01 +00:00
complete -x -c j -a '(autojump --complete (commandline -t))'
2014-10-05 03:03:44 +00:00
# set error file location
if (uname) == "Darwin"
set -x AUTOJUMP_ERROR_PATH ~/Library/autojump/errors.log
else if test -d $XDG_DATA_HOME
set -x AUTOJUMP_ERROR_PATH $XDG_DATA_HOME/autojump/errors.log
else
set -x AUTOJUMP_ERROR_PATH ~/.local/share/autojump/errors.log
end
if test ! -d "(dirname $AUTOJUMP_ERROR_PATH)"
mkdir -p "(dirname $AUTOJUMP_ERROR_PATH)"
end
2014-10-05 03:03:44 +00:00
# change pwd hook
function __aj_add --on-variable PWD
status --is-command-substitution; and return
if test -f "$AUTOJUMP_ERROR_PATH"
autojump --add (pwd) >/dev/null 2>>$AUTOJUMP_ERROR_PATH &
else
autojump --add (pwd) >/dev/null &
end
end
# misc helper functions
2013-05-18 11:58:41 +00:00
function __aj_err
# TODO(ting|#247): set error file location
2013-05-18 11:58:41 +00:00
echo $argv 1>&2; false
end
# default autojump command
2013-05-18 11:58:41 +00:00
function j
switch "$argv"
case '-*' '--*'
autojump $argv
case '*'
set -l output (autojump $argv)
if test -d "$output"
2013-05-18 11:58:41 +00:00
set_color red
echo $output
2013-05-18 11:58:41 +00:00
set_color normal
cd $output
2013-05-18 11:58:41 +00:00
else
__aj_err "autojump: directory '"$argv"' not found"
__aj_err "\n$output\n"
__aj_err "Try `autojump --help` for more information."
2013-05-18 11:58:41 +00:00
end
end
end
# jump to child directory (subdirectory of current path)
2013-05-18 11:58:41 +00:00
function jc
switch "$argv"
case '-*'
j $argv
case '*'
j (pwd) $argv
end
end
# open autojump results in file browser
2013-05-18 11:58:41 +00:00
function jo
set -l output (autojump $argv)
if test -d "$output"
__aj_err "autojump: directory '"$argv"' not found"
__aj_err "\n$output\n"
__aj_err "Try `autojump --help` for more information."
2013-05-18 11:58:41 +00:00
else
switch (sh -c 'echo ${OSTYPE}')
case 'linux*'
2013-05-18 11:58:41 +00:00
xdg-open (autojump $argv)
case 'darwin*'
open (autojump $argv)
case cygwin
cygstart "" (cygpath -w -a (pwd))
case '*'
__aj_error "Unknown operating system: '"$OSTYPE"'"
2013-05-18 11:58:41 +00:00
end
echo end
end
end
# open autojump results (child directory) in file browser
2013-05-18 11:58:41 +00:00
function jco
switch "$argv"
case '-*'
j $argv
case '*'
jo (pwd) $argv
end
end