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

80 lines
1.7 KiB
Bash
Raw Normal View History

2013-12-30 23:44:39 +00:00
# set paths for user installations
if [[ -d ${HOME}/.autojump ]]; then
path=(${HOME}/.autojump/bin ${path})
fpath=(${HOME}/.autojump/functions/ ${fpath})
fi
2012-03-02 00:45:47 +00:00
# set fpath if necessary for homebrew installation
command -v brew &>/dev/null \
&& [[ -d "`brew --prefix`/share/zsh/site-functions" ]] \
&& fpath=(`brew --prefix`/share/zsh/site-functions ${fpath})
2013-12-30 23:44:39 +00:00
# add 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 ${@}
return
fi
2013-12-30 23:44:39 +00:00
j $(pwd)/ ${@}
}
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-11-24 22:26:23 +00:00
return
fi
2013-12-30 23:44:39 +00:00
case ${OSTYPE} in
linux-gnu)
xdg-open "$(autojump $@)"
;;
darwin*)
open "$(autojump $@)"
;;
cygwin)
cygstart "" $(cygpath -w -a $(pwd))
;;
*)
echo "Unknown operating system." 1>&2
;;
esac
}
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 ${@}
return
fi
2013-12-30 23:44:39 +00:00
jo $(pwd)/ ${@}
}