mirror of
https://github.com/wting/autojump
synced 2024-10-27 20:34:07 +00:00
531a7321d3
Fixes #247.
99 lines
2.1 KiB
Fish
99 lines
2.1 KiB
Fish
# set user installation path
|
|
if test -d ~/.autojump
|
|
set -x PATH ~/.autojump/bin $PATH
|
|
end
|
|
|
|
|
|
# enable tab completion
|
|
complete -x -c j -a '(autojump --complete (commandline -t))'
|
|
|
|
|
|
# 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
|
|
|
|
|
|
# change pwd hook
|
|
function __aj_add --on-variable PWD
|
|
status --is-command-substitution; and return
|
|
autojump --add (pwd) >/dev/null 2>>$AUTOJUMP_ERROR_PATH &
|
|
end
|
|
|
|
|
|
# misc helper functions
|
|
function __aj_err
|
|
# TODO(ting|#247): set error file location
|
|
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
|
|
|
|
|
|
# default autojump command
|
|
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
|
|
|
|
|
|
# jump to child directory (subdirectory of current path)
|
|
function jc
|
|
switch "$argv"
|
|
case '-*'
|
|
j $argv
|
|
case '*'
|
|
j (pwd) $argv
|
|
end
|
|
end
|
|
|
|
|
|
# open autojump results in file browser
|
|
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
|
|
|
|
|
|
# open autojump results (child directory) in file browser
|
|
function jco
|
|
switch "$argv"
|
|
case '-*'
|
|
j $argv
|
|
case '*'
|
|
jo (pwd) $argv
|
|
end
|
|
end
|