2013-12-31 15:48:42 +00:00
|
|
|
# set user installation paths
|
|
|
|
if [ -d ~/.autojump/ ]; then
|
|
|
|
export PATH=~/.autojump/bin:"${PATH}"
|
|
|
|
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
|
|
|
|
|
|
|
|
|
2013-12-31 15:48:42 +00:00
|
|
|
# enable tab completion
|
2013-12-30 22:27:34 +00:00
|
|
|
_autojump() {
|
2009-03-03 11:09:36 +00:00
|
|
|
local cur
|
2010-04-27 08:08:07 +00:00
|
|
|
cur=${COMP_WORDS[*]:1}
|
2013-12-31 00:01:04 +00:00
|
|
|
comps=$(autojump --complete $cur)
|
2013-12-31 15:48:42 +00:00
|
|
|
while read i; do
|
2010-04-27 08:08:07 +00:00
|
|
|
COMPREPLY=("${COMPREPLY[@]}" "${i}")
|
2011-09-21 10:34:17 +00:00
|
|
|
done <<EOF
|
|
|
|
$comps
|
|
|
|
EOF
|
2009-03-03 11:09:36 +00:00
|
|
|
}
|
|
|
|
complete -F _autojump j
|
2011-07-24 19:08:56 +00:00
|
|
|
|
2012-02-08 21:27:43 +00:00
|
|
|
|
2013-12-31 15:48:42 +00:00
|
|
|
# change pwd hook
|
2012-11-21 23:48:12 +00:00
|
|
|
autojump_add_to_database() {
|
2014-01-08 04:13:01 +00:00
|
|
|
(autojump --add "$(pwd)" >/dev/null 2>${AUTOJUMP_ERROR_PATH} &) &>/dev/null
|
2012-11-21 23:48:12 +00:00
|
|
|
}
|
2011-09-14 05:56:30 +00:00
|
|
|
|
|
|
|
case $PROMPT_COMMAND in
|
2013-02-01 20:59:34 +00:00
|
|
|
*autojump*)
|
|
|
|
;;
|
|
|
|
*)
|
2013-03-30 02:36:41 +00:00
|
|
|
PROMPT_COMMAND="${PROMPT_COMMAND:+$(echo "${PROMPT_COMMAND}" | awk '{gsub(/; *$/,"")}1') ; }autojump_add_to_database"
|
2013-02-01 20:59:34 +00:00
|
|
|
;;
|
2011-09-14 05:56:30 +00:00
|
|
|
esac
|
|
|
|
|
2013-12-31 15:48:42 +00:00
|
|
|
|
2013-12-31 14:39:14 +00:00
|
|
|
# default autojump command
|
2013-12-30 22:27:34 +00:00
|
|
|
j() {
|
2012-06-29 04:50:25 +00:00
|
|
|
if [[ ${@} =~ ^-{1,2}.* ]]; then
|
2012-05-27 21:24:49 +00:00
|
|
|
autojump ${@}
|
|
|
|
return
|
|
|
|
fi
|
2012-04-02 12:58:43 +00:00
|
|
|
|
2012-12-15 04:58:20 +00:00
|
|
|
new_path="$(autojump ${@})"
|
2012-04-02 12:58:43 +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
|
|
|
|
}
|
2012-12-15 04:58:20 +00:00
|
|
|
|
2013-12-31 15:48:42 +00:00
|
|
|
|
2013-12-31 14:39:14 +00:00
|
|
|
# jump to child directory (subdirectory of current path)
|
2013-12-30 22:27:34 +00:00
|
|
|
jc() {
|
2012-12-15 04:58:20 +00:00
|
|
|
if [[ ${@} == -* ]]; then
|
2013-12-31 00:01:04 +00:00
|
|
|
autojump ${@}
|
2012-12-15 04:58:20 +00:00
|
|
|
else
|
2013-12-31 14:39:14 +00:00
|
|
|
j $(pwd) ${@}
|
2012-12-15 04:58:20 +00:00
|
|
|
fi
|
|
|
|
}
|
2013-02-01 19:50:52 +00:00
|
|
|
|
2013-12-31 15:48:42 +00:00
|
|
|
|
2013-12-31 14:39:14 +00:00
|
|
|
# open autojump results in file browser
|
2013-12-30 22:27:34 +00:00
|
|
|
jo() {
|
2013-12-31 14:39:14 +00:00
|
|
|
if [[ ${@} == -* ]]; then
|
|
|
|
autojump ${@}
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
new_path="$(autojump ${@})"
|
|
|
|
if [ -d "${new_path}" ]; then
|
2013-02-14 18:59:01 +00:00
|
|
|
case ${OSTYPE} in
|
|
|
|
linux-gnu)
|
2013-12-31 14:39:14 +00:00
|
|
|
xdg-open "${new_path}"
|
2013-02-14 18:59:01 +00:00
|
|
|
;;
|
|
|
|
darwin*)
|
2013-12-31 14:39:14 +00:00
|
|
|
open "${new_path}"
|
2013-02-14 18:59:01 +00:00
|
|
|
;;
|
|
|
|
cygwin)
|
2013-12-31 14:39:14 +00:00
|
|
|
cygstart "" $(cygpath -w -a ${new_path})
|
2013-02-14 18:59:01 +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-02-14 18:59:01 +00:00
|
|
|
fi
|
2013-02-01 19:50:52 +00:00
|
|
|
}
|
|
|
|
|
2013-12-31 15:48:42 +00:00
|
|
|
|
2013-12-31 14:39:14 +00:00
|
|
|
# open autojump results (child directory) in file browser
|
2013-12-30 22:27:34 +00:00
|
|
|
jco() {
|
2013-02-01 19:50:52 +00:00
|
|
|
if [[ ${@} == -* ]]; then
|
2013-12-31 00:01:04 +00:00
|
|
|
autojump ${@}
|
2013-02-01 19:50:52 +00:00
|
|
|
else
|
|
|
|
jo $(pwd) ${@}
|
|
|
|
fi
|
|
|
|
}
|