1
0
mirror of https://github.com/wting/autojump synced 2024-09-28 22:10:45 +00:00
wting_autojump/bin/autojump.bash

127 lines
2.8 KiB
Bash
Raw Normal View History

export AUTOJUMP_SOURCED=1
# set user installation paths
2014-01-08 04:13:29 +00:00
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
if [[ ! -d "$(dirname ${AUTOJUMP_ERROR_PATH})" ]]; then
mkdir -p "$(dirname ${AUTOJUMP_ERROR_PATH})"
fi
2014-01-08 04:13:01 +00:00
# enable tab completion
_autojump() {
2009-03-03 11:09:36 +00:00
local cur
cur=${COMP_WORDS[*]:1}
2013-12-31 00:01:04 +00:00
comps=$(autojump --complete $cur)
while read i; do
COMPREPLY=("${COMPREPLY[@]}" "${i}")
done <<EOF
$comps
EOF
2009-03-03 11:09:36 +00:00
}
complete -F _autojump j
2012-02-08 21:27:43 +00:00
# change pwd hook
2012-11-21 23:48:12 +00:00
autojump_add_to_database() {
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
else
(autojump --add "$(pwd)" >/dev/null &) &>/dev/null
fi
2012-11-21 23:48:12 +00:00
}
case $PROMPT_COMMAND in
2013-02-01 20:59:34 +00:00
*autojump*)
;;
*)
PROMPT_COMMAND="${PROMPT_COMMAND:+$(echo "${PROMPT_COMMAND}" | awk '{gsub(/; *$/,"")}1') ; }autojump_add_to_database"
2013-02-01 20:59:34 +00:00
;;
esac
2013-12-31 14:39:14 +00:00
# default autojump command
j() {
if [[ ${1} == -* ]] && [[ ${1} != "--" ]]; then
autojump ${@}
return
fi
output="$(autojump ${@})"
if [[ -d "${output}" ]]; then
echo -e "\\033[31m${output}\\033[0m"
cd "${output}"
else
echo "autojump: directory '${@}' not found"
echo "\n${output}\n"
echo "Try \`autojump --help\` for more information."
false
fi
}
2013-12-31 14:39:14 +00:00
# jump to child directory (subdirectory of current path)
jc() {
if [[ ${1} == -* ]] && [[ ${1} != "--" ]]; then
2013-12-31 00:01:04 +00:00
autojump ${@}
return
else
2013-12-31 14:39:14 +00:00
j $(pwd) ${@}
fi
}
2013-12-31 14:39:14 +00:00
# open autojump results in file browser
jo() {
if [[ ${1} == -* ]] && [[ ${1} != "--" ]]; then
2013-12-31 14:39:14 +00:00
autojump ${@}
return
fi
output="$(autojump ${@})"
if [[ -d "${output}" ]]; then
2013-02-14 18:59:01 +00:00
case ${OSTYPE} in
2014-10-30 10:39:18 +00:00
linux|linux-gnu)
xdg-open "${output}"
2013-02-14 18:59:01 +00:00
;;
darwin*)
open "${output}"
2013-02-14 18:59:01 +00:00
;;
cygwin)
cygstart "" $(cygpath -w -a ${output})
2013-02-14 18:59:01 +00:00
;;
*)
2014-10-30 10:39:18 +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"
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-12-31 14:39:14 +00:00
# open autojump results (child directory) in file browser
jco() {
if [[ ${1} == -* ]] && [[ ${1} != "--" ]]; then
2013-12-31 00:01:04 +00:00
autojump ${@}
return
else
jo $(pwd) ${@}
fi
}