1
0
mirror of https://github.com/wting/autojump synced 2024-09-29 22:40:46 +00:00
wting_autojump/bin/autojump.zsh

94 lines
1.9 KiB
Bash
Raw Normal View History

# 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() {
2013-12-30 23:44:39 +00:00
(autojump -a "$(pwd)" &) &>/dev/null
2009-03-30 07:34:24 +00:00
}
typeset -gaU chpwd_functions
chpwd_functions+=autojump_chpwd
2013-12-30 23:44:39 +00:00
# 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
}
2013-12-30 23:44:39 +00:00
# jump to child directory (subdirectory of current path)
jc() {
if [[ ${@} == -* ]]; then
2013-12-30 23:44:39 +00:00
autojump ${@}
2013-12-31 00:01:04 +00:00
else
2013-12-31 14:39:14 +00:00
j $(pwd) ${@}
fi
}
2013-12-30 23:44:39 +00:00
# open autojump results in file browser
jo() {
2013-11-24 22:26:23 +00:00
if [[ ${@} == -* ]]; then
2013-12-30 23:44:39 +00:00
autojump ${@}
2013-12-31 14:39:14 +00:00
return
fi
local new_path="$(autojump ${@})"
if [ -d "${new_path}" ]; then
2013-12-31 00:01:04 +00:00
case ${OSTYPE} in
linux-gnu)
2013-12-31 14:39:14 +00:00
xdg-open "${new_path}"
2013-12-31 00:01:04 +00:00
;;
darwin*)
2013-12-31 14:39:14 +00:00
open "${new_path}"
2013-12-31 00:01:04 +00:00
;;
cygwin)
2013-12-31 14:39:14 +00:00
cygstart "" $(cygpath -w -a ${new_path})
2013-12-31 00:01:04 +00:00
;;
*)
echo "Unknown operating system." 1>&2
;;
esac
2013-12-31 14:39:14 +00:00
else
echo "autojump: directory '${@}' not found"
echo "Try \`autojump --help\` for more information."
false
2013-11-24 22:26:23 +00:00
fi
}
2013-12-30 23:44:39 +00:00
# open autojump results (child directory) in file browser
jco() {
if [[ ${@} == -* ]]; then
2013-12-30 23:44:39 +00:00
autojump ${@}
2013-12-31 14:39:14 +00:00
else
jo $(pwd) ${@}
fi
}