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

89 lines
1.8 KiB
Fish
Raw Normal View History

# 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))'
# change pwd hook
function __aj_add --on-variable PWD
status --is-command-substitution; and return
2013-12-31 16:59:01 +00:00
autojump -a (pwd) >/dev/null &
end
# misc helper functions
2013-05-18 11:58:41 +00:00
function __aj_err
2014-01-08 04:13:01 +00:00
# TODO(ting|2014-01-07): set error file location
2013-05-18 11:58:41 +00:00
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
2013-05-18 11:58:41 +00:00
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)
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
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
2013-05-18 11:58:41 +00:00
function jco
switch "$argv"
case '-*'
j $argv
case '*'
jo (pwd) $argv
end
end