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

96 lines
2.0 KiB
Bash
Raw Normal View History

_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
# set paths if necessary for local installations
if [ -d ~/.autojump/ ]; then
export PATH=~/.autojump/bin:"${PATH}"
fi
2012-11-21 23:48:12 +00:00
autojump_add_to_database() {
2013-12-31 00:01:04 +00:00
autojump -a "$(pwd)" &>/dev/null
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,2}.* ]]; then
autojump ${@}
return
fi
new_path="$(autojump ${@})"
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-31 14:39:14 +00:00
# jump to child directory (subdirectory of current path)
jc() {
if [[ ${@} == -* ]]; then
2013-12-31 00:01:04 +00:00
autojump ${@}
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() {
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-12-31 14:39:14 +00:00
# open autojump results (child directory) in file browser
jco() {
if [[ ${@} == -* ]]; then
2013-12-31 00:01:04 +00:00
autojump ${@}
else
jo $(pwd) ${@}
fi
}