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

113 lines
2.5 KiB
Bash
Raw Normal View History

# set user installation paths
if [[ -d ~/.autojump/bin ]]; then
2014-01-08 04:13:29 +00:00
path=(~/.autojump/bin ${path})
fi
if [[ -d ~/.autojump/functions ]]; then
fpath=(~/.autojump/functions ${fpath})
fi
# set homebrew installation paths
if command -v brew &>/dev/null && [[ -d "$(brew --prefix)/share/zsh/site-functions" ]]; then
2014-01-08 04:13:29 +00:00
fpath=("$(brew --prefix)/share/zsh/site-functions" ${fpath})
fi
2014-01-08 04:13:01 +00:00
# set error file location
if [[ "$(uname)" == "Darwin" ]]; then
export AUTOJUMP_ERROR_PATH=~/Library/autojump/errors.log
elif [[ -n "${XDG_DATA_HOME}" ]]; then
export AUTOJUMP_ERROR_PATH="${XDG_DATA_HOME}/autojump/errors.log"
else
export AUTOJUMP_ERROR_PATH=~/.local/share/autojump/errors.log
fi
if [[ ! -d ${AUTOJUMP_ERROR_PATH:h} ]]; then
mkdir -p ${AUTOJUMP_ERROR_PATH:h}
fi
# change pwd hook
autojump_chpwd() {
if [[ -f "${AUTOJUMP_ERROR_PATH}" ]]; then
2014-10-05 03:02:41 +00:00
autojump --add "$(pwd)" >/dev/null 2>>${AUTOJUMP_ERROR_PATH} &!
else
autojump --add "$(pwd)" >/dev/null &!
fi
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
setopt localoptions noautonamedirs
local new_path="$(autojump ${@})"
2014-01-08 04:13:29 +00:00
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
setopt localoptions noautonamedirs
2013-12-31 14:39:14 +00:00
local new_path="$(autojump ${@})"
2014-01-08 04:13:29 +00:00
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
}