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

113 lines
2.6 KiB
Fish
Raw Normal View History

set -gx 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
# Set ostype, if not set
if not set -q OSTYPE
set -gx OSTYPE (bash -c 'echo ${OSTYPE}')
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
2014-12-14 19:30:22 +00:00
if test (uname) = "Darwin"
set -gx AUTOJUMP_ERROR_PATH ~/Library/autojump/errors.log
else if test -d "$XDG_DATA_HOME"
set -gx AUTOJUMP_ERROR_PATH $XDG_DATA_HOME/autojump/errors.log
2014-10-05 03:03:44 +00:00
else
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
# 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 &
end
# misc helper functions
2013-05-18 11:58:41 +00:00
function __aj_err
# TODO(ting|#247): set error file location
echo -e $argv 1>&2; false
2013-05-18 11:58:41 +00:00
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)
# Check for . and attempt a regular cd
if [ $output = "." ]
cd $argv
2013-05-18 11:58:41 +00:00
else
if test -d "$output"
set_color green
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
# 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"
switch $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 '*'
2015-07-07 03:12:35 +00:00
__aj_err "Unknown operating system: \"$OSTYPE\""
2013-05-18 11:58:41 +00:00
end
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
# 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