1
0
mirror of https://github.com/wting/autojump synced 2024-10-27 20:34:07 +00:00
wting_autojump/bin/autojump.zsh
2013-12-31 09:49:20 -06:00

94 lines
1.9 KiB
Bash

# set user installation paths
if [[ -d ${HOME}/.autojump ]]; then
path=(${HOME}/.autojump/bin ${path})
fpath=(${HOME}/.autojump/functions/ ${fpath})
fi
# set homebrew installation paths
command -v brew &>/dev/null \
&& [[ -d "`brew --prefix`/share/zsh/site-functions" ]] \
&& fpath=(`brew --prefix`/share/zsh/site-functions ${fpath})
# tab completion handled by _j file
# change pwd hook
autojump_chpwd() {
(autojump -a "$(pwd)" &) &>/dev/null
}
typeset -gaU chpwd_functions
chpwd_functions+=autojump_chpwd
# default autojump command
j() {
if [[ ${@} == -* ]]; then
autojump ${@}
return
fi
local new_path="$(autojump ${@})"
if [ -d "${new_path}" ]; then
echo -e "\\033[31m${new_path}\\033[0m"
cd "${new_path}"
else
echo "autojump: directory '${@}' not found"
echo "Try \`autojump --help\` for more information."
false
fi
}
# jump to child directory (subdirectory of current path)
jc() {
if [[ ${@} == -* ]]; then
autojump ${@}
else
j $(pwd) ${@}
fi
}
# open autojump results in file browser
jo() {
if [[ ${@} == -* ]]; then
autojump ${@}
return
fi
local new_path="$(autojump ${@})"
if [ -d "${new_path}" ]; then
case ${OSTYPE} in
linux-gnu)
xdg-open "${new_path}"
;;
darwin*)
open "${new_path}"
;;
cygwin)
cygstart "" $(cygpath -w -a ${new_path})
;;
*)
echo "Unknown operating system." 1>&2
;;
esac
else
echo "autojump: directory '${@}' not found"
echo "Try \`autojump --help\` for more information."
false
fi
}
# open autojump results (child directory) in file browser
jco() {
if [[ ${@} == -* ]]; then
autojump ${@}
else
jo $(pwd) ${@}
fi
}