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
|
|
|
}
|
2014-03-10 09:49:52 +00:00
|
|
|
complete -F _autojump j jo
|
2011-07-24 19:08:56 +00:00
|
|
|
|
2014-03-10 09:49:52 +00:00
|
|
|
_complete_autojump_c() {
|
|
|
|
local current_word
|
|
|
|
SAVE_IFS=$IFS
|
|
|
|
IFS=$'\n'
|
|
|
|
COMPREPLY=()
|
|
|
|
current_word="${COMP_WORDS[COMP_CWORD]}"
|
|
|
|
# tabbing on empty "prefix", e.g. jc <tab>
|
|
|
|
if [ -z "$current_word" ]; then
|
|
|
|
autocomplete_pattern="$PWD"
|
2014-03-10 15:29:15 +00:00
|
|
|
# tabbing when last item is a number, e.g. jc /some/path.*first.*second__2<tab>
|
2014-03-10 09:49:52 +00:00
|
|
|
elif [[ "$current_word" =~ ^[0-9]+$ ]]; then
|
|
|
|
autocomplete_pattern="${PWD}__$current_word"
|
2014-03-10 15:29:15 +00:00
|
|
|
# tabbing when last item contains .*, e.g. jc /some/path.*another<tab>
|
2014-03-10 09:49:52 +00:00
|
|
|
elif [[ "$current_word" =~ .*\.\*.* ]]; then
|
|
|
|
autocomplete_pattern="$current_word"
|
|
|
|
# tabbing when there are tokens, e.g. jc first second<tab>
|
|
|
|
else
|
|
|
|
autocomplete_pattern="${PWD}.*${current_word}"
|
|
|
|
fi
|
|
|
|
comps=$(autojump --complete "$autocomplete_pattern")
|
|
|
|
COMPREPLY=($(compgen -W "$comps" --))
|
|
|
|
IFS=$SAVE_IFS
|
|
|
|
}
|
|
|
|
complete -F _complete_autojump_c jc jco
|
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
|
2014-10-05 03:02:41 +00:00
|
|
|
(autojump --add "$(pwd)" >/dev/null 2>>${AUTOJUMP_ERROR_PATH} &) &>/dev/null
|
2014-01-11 12:58:07 +00:00
|
|
|
else
|
|
|
|
(autojump --add "$(pwd)" >/dev/null &) &>/dev/null
|
|
|
|
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() {
|
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 ${@})"
|
2014-01-08 04:13:29 +00:00
|
|
|
if [[ -d "${new_path}" ]]; then
|
2012-04-02 12:58:43 +00:00
|
|
|
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
|
|
|
|
2014-03-10 15:29:15 +00:00
|
|
|
alias jc=j
|
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 ${@})"
|
2014-01-08 04:13:29 +00:00
|
|
|
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
|
|
|
|
2014-03-10 15:29:15 +00:00
|
|
|
alias jco=jo
|