2014-10-05 02:41:41 +00:00
|
|
|
set -x AUTOJUMP_SOURCED 1
|
|
|
|
|
2013-12-31 15:48:42 +00:00
|
|
|
# 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
|
|
|
|
|
2013-12-31 15:48:42 +00:00
|
|
|
|
|
|
|
# enable tab completion
|
2013-12-31 16:59:01 +00:00
|
|
|
complete -x -c j -a '(autojump --complete (commandline -t))'
|
2013-12-31 15:48:42 +00:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2014-11-18 08:55:01 +00:00
|
|
|
if test ! -d "(dirname $AUTOJUMP_ERROR_PATH)"
|
|
|
|
mkdir -p "(dirname $AUTOJUMP_ERROR_PATH)"
|
|
|
|
end
|
2014-10-05 03:03:44 +00:00
|
|
|
|
2013-12-31 15:48:42 +00:00
|
|
|
# change pwd hook
|
|
|
|
function __aj_add --on-variable PWD
|
|
|
|
status --is-command-substitution; and return
|
2014-11-18 08:55:01 +00:00
|
|
|
if test -f "$AUTOJUMP_ERROR_PATH"
|
|
|
|
autojump --add (pwd) >/dev/null 2>>$AUTOJUMP_ERROR_PATH &
|
|
|
|
else
|
|
|
|
autojump --add (pwd) >/dev/null &
|
|
|
|
end
|
2013-12-31 15:48:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# misc helper functions
|
2013-05-18 11:58:41 +00:00
|
|
|
function __aj_err
|
2014-01-08 17:11:39 +00:00
|
|
|
# TODO(ting|#247): set error file location
|
2013-05-18 11:58:41 +00:00
|
|
|
echo $argv 1>&2; false
|
|
|
|
end
|
|
|
|
|
2013-12-31 15:48:42 +00:00
|
|
|
# default autojump command
|
2013-05-18 11:58:41 +00:00
|
|
|
function j
|
|
|
|
switch "$argv"
|
|
|
|
case '-*' '--*'
|
|
|
|
autojump $argv
|
|
|
|
case '*'
|
2014-10-05 02:41:41 +00:00
|
|
|
set -l output (autojump $argv)
|
|
|
|
if test -d "$output"
|
2013-05-18 11:58:41 +00:00
|
|
|
set_color red
|
2014-10-05 02:41:41 +00:00
|
|
|
echo $output
|
2013-05-18 11:58:41 +00:00
|
|
|
set_color normal
|
2014-10-05 02:41:41 +00:00
|
|
|
cd $output
|
2013-05-18 11:58:41 +00:00
|
|
|
else
|
2014-10-05 02:41:41 +00:00
|
|
|
__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
|
|
|
|
|
2013-12-31 15:48:42 +00:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2013-12-31 15:48:42 +00:00
|
|
|
|
|
|
|
# open autojump results in file browser
|
2013-05-18 11:58:41 +00:00
|
|
|
function jo
|
2014-10-05 02:41:41 +00:00
|
|
|
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}')
|
2014-11-05 15:53:03 +00:00
|
|
|
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 '*'
|
2014-11-05 15:53:03 +00:00
|
|
|
__aj_error "Unknown operating system: '"$OSTYPE"'"
|
2013-05-18 11:58:41 +00:00
|
|
|
end
|
|
|
|
echo end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-12-31 15:48:42 +00:00
|
|
|
|
|
|
|
# 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
|