2016-09-07 04:56:16 +00:00
|
|
|
set -gx AUTOJUMP_SOURCED 1
|
2014-10-05 02:41:41 +00:00
|
|
|
|
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
|
|
|
|
|
2015-06-09 20:32:38 +00:00
|
|
|
# Set ostype, if not set
|
|
|
|
if not set -q OSTYPE
|
|
|
|
set -gx OSTYPE (bash -c 'echo ${OSTYPE}')
|
|
|
|
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
|
2014-12-14 19:30:22 +00:00
|
|
|
if test (uname) = "Darwin"
|
2016-09-07 04:56:16 +00:00
|
|
|
set -gx AUTOJUMP_ERROR_PATH ~/Library/autojump/errors.log
|
2015-01-07 21:47:33 +00:00
|
|
|
else if test -d "$XDG_DATA_HOME"
|
2016-09-07 04:56:16 +00:00
|
|
|
set -gx AUTOJUMP_ERROR_PATH $XDG_DATA_HOME/autojump/errors.log
|
2014-10-05 03:03:44 +00:00
|
|
|
else
|
2016-09-07 04:56:16 +00:00
|
|
|
set -gx AUTOJUMP_ERROR_PATH ~/.local/share/autojump/errors.log
|
2014-10-05 03:03:44 +00:00
|
|
|
end
|
|
|
|
|
2014-12-14 21:23:53 +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-10-05 03:03:44 +00:00
|
|
|
autojump --add (pwd) >/dev/null 2>>$AUTOJUMP_ERROR_PATH &
|
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
|
2015-06-09 20:32:38 +00:00
|
|
|
echo -e $argv 1>&2; false
|
2013-05-18 11:58:41 +00:00
|
|
|
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)
|
2015-06-09 20:42:44 +00:00
|
|
|
# Check for . and attempt a regular cd
|
|
|
|
if [ $output = "." ]
|
|
|
|
cd $argv
|
2013-05-18 11:58:41 +00:00
|
|
|
else
|
2015-06-09 20:42:44 +00:00
|
|
|
if test -d "$output"
|
|
|
|
set_color red
|
|
|
|
echo $output
|
|
|
|
set_color normal
|
|
|
|
cd $output
|
|
|
|
else
|
|
|
|
__aj_err "autojump: directory '"$argv"' not found"
|
|
|
|
__aj_err "\n$output\n"
|
|
|
|
__aj_err "Try `autojump --help` for more information."
|
|
|
|
end
|
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"
|
2015-06-09 20:32:38 +00:00
|
|
|
switch $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 '*'
|
2015-07-07 03:12:35 +00:00
|
|
|
__aj_err "Unknown operating system: \"$OSTYPE\""
|
2013-05-18 11:58:41 +00:00
|
|
|
end
|
2015-06-09 20:32:38 +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
|
|
|
|
|
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
|