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

105 lines
2.2 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
_autojump_files() {
2012-02-08 21:27:43 +00:00
if [[ ${COMP_WORDS[COMP_CWORD]} == *__* ]]; then
2011-11-28 16:12:04 +00:00
local cur
#cur=${COMP_WORDS[*]:1}
cur=${COMP_WORDS[COMP_CWORD]}
2013-12-31 00:01:04 +00:00
comps=$(autojump --complete $cur)
2011-11-28 16:12:04 +00:00
while read i
do
COMPREPLY=("${COMPREPLY[@]}" "${i}")
done <<EOF
$comps
EOF
fi
}
if [[ -n ${AUTOJUMP_AUTOCOMPLETE_CMDS} ]]; then
complete -o default -o bashdefault -F _autojump_files ${AUTOJUMP_AUTOCOMPLETE_CMDS}
fi
2011-11-28 16:12:04 +00:00
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
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
}
jc() {
if [[ ${@} == -* ]]; then
2013-12-31 00:01:04 +00:00
autojump ${@}
else
j $(pwd)/ ${@}
fi
}
jo() {
2013-02-14 18:59:01 +00:00
if [ -z $(autojump $@) ]; then
echo "autojump: directory '${@}' not found"
echo "Try \`autojump --help\` for more information."
false
else
case ${OSTYPE} in
linux-gnu)
xdg-open "$(autojump $@)"
;;
darwin*)
open "$(autojump $@)"
;;
cygwin)
cygstart "" $(cygpath -w -a $(pwd))
2013-02-14 18:59:01 +00:00
;;
*)
echo "Unknown operating system." 1>&2
;;
esac
fi
}
jco() {
if [[ ${@} == -* ]]; then
2013-12-31 00:01:04 +00:00
autojump ${@}
else
jo $(pwd) ${@}
fi
}