2014-10-05 02:41:41 +00:00
|
|
|
export AUTOJUMP_SOURCED=1
|
|
|
|
|
2013-12-31 15:48:42 +00:00
|
|
|
# set user installation paths
|
2014-01-08 04:13:29 +00:00
|
|
|
if [[ -d ~/.autojump/ ]]; then
|
2013-12-31 15:48:42 +00:00
|
|
|
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
|
|
|
|
|
2014-01-11 12:58:07 +00:00
|
|
|
if [[ ! -d "$(dirname ${AUTOJUMP_ERROR_PATH})" ]]; then
|
|
|
|
mkdir -p "$(dirname ${AUTOJUMP_ERROR_PATH})"
|
|
|
|
fi
|
|
|
|
|
2014-01-08 04:13:01 +00:00
|
|
|
|
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-11 12:58:07 +00:00
|
|
|
if [[ -f "${AUTOJUMP_ERROR_PATH}" ]]; then
|
2018-01-29 15:44:51 +00:00
|
|
|
(autojump --add "${PWD}" >/dev/null 2>>${AUTOJUMP_ERROR_PATH} &) &>/dev/null
|
2014-01-11 12:58:07 +00:00
|
|
|
else
|
2018-01-29 15:44:51 +00:00
|
|
|
(autojump --add "${PWD}" >/dev/null &) &>/dev/null
|
2014-01-11 12:58:07 +00:00
|
|
|
fi
|
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() {
|
2014-08-23 01:07:27 +00:00
|
|
|
if [[ ${1} == -* ]] && [[ ${1} != "--" ]]; then
|
2012-05-27 21:24:49 +00:00
|
|
|
autojump ${@}
|
|
|
|
return
|
|
|
|
fi
|
2012-04-02 12:58:43 +00:00
|
|
|
|
2014-10-05 02:41:41 +00:00
|
|
|
output="$(autojump ${@})"
|
|
|
|
if [[ -d "${output}" ]]; then
|
2016-05-12 03:40:00 +00:00
|
|
|
if [ -t 1 ]; then # if stdout is a terminal, use colors
|
|
|
|
echo -e "\\033[31m${output}\\033[0m"
|
|
|
|
else
|
|
|
|
echo -e "${output}"
|
|
|
|
fi
|
2014-10-05 02:41:41 +00:00
|
|
|
cd "${output}"
|
2012-04-02 12:58:43 +00:00
|
|
|
else
|
|
|
|
echo "autojump: directory '${@}' not found"
|
2014-10-05 02:41:41 +00:00
|
|
|
echo "\n${output}\n"
|
2012-04-02 12:58:43 +00:00
|
|
|
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() {
|
2014-08-23 01:07:27 +00:00
|
|
|
if [[ ${1} == -* ]] && [[ ${1} != "--" ]]; then
|
2013-12-31 00:01:04 +00:00
|
|
|
autojump ${@}
|
2014-08-23 01:07:27 +00:00
|
|
|
return
|
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() {
|
2014-08-23 01:07:27 +00:00
|
|
|
if [[ ${1} == -* ]] && [[ ${1} != "--" ]]; then
|
2013-12-31 14:39:14 +00:00
|
|
|
autojump ${@}
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2014-10-05 02:41:41 +00:00
|
|
|
output="$(autojump ${@})"
|
|
|
|
if [[ -d "${output}" ]]; then
|
2013-02-14 18:59:01 +00:00
|
|
|
case ${OSTYPE} in
|
2014-11-05 15:53:03 +00:00
|
|
|
linux*)
|
2014-10-05 02:41:41 +00:00
|
|
|
xdg-open "${output}"
|
2013-02-14 18:59:01 +00:00
|
|
|
;;
|
|
|
|
darwin*)
|
2014-10-05 02:41:41 +00:00
|
|
|
open "${output}"
|
2013-02-14 18:59:01 +00:00
|
|
|
;;
|
|
|
|
cygwin)
|
2014-10-05 02:41:41 +00:00
|
|
|
cygstart "" $(cygpath -w -a ${output})
|
2013-02-14 18:59:01 +00:00
|
|
|
;;
|
|
|
|
*)
|
2014-11-05 15:53:03 +00:00
|
|
|
echo "Unknown operating system: ${OSTYPE}." 1>&2
|
2013-02-14 18:59:01 +00:00
|
|
|
;;
|
|
|
|
esac
|
2013-12-31 14:39:14 +00:00
|
|
|
else
|
|
|
|
echo "autojump: directory '${@}' not found"
|
2014-10-05 02:41:41 +00:00
|
|
|
echo "\n${output}\n"
|
2013-12-31 14:39:14 +00:00
|
|
|
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() {
|
2014-08-23 01:07:27 +00:00
|
|
|
if [[ ${1} == -* ]] && [[ ${1} != "--" ]]; then
|
2013-12-31 00:01:04 +00:00
|
|
|
autojump ${@}
|
2014-08-23 01:07:27 +00:00
|
|
|
return
|
2013-02-01 19:50:52 +00:00
|
|
|
else
|
|
|
|
jo $(pwd) ${@}
|
|
|
|
fi
|
|
|
|
}
|