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

minor shell script cleanup

This commit is contained in:
William Ting 2013-12-31 08:39:14 -06:00
parent c4feb1a2b2
commit c0301c7cee
2 changed files with 34 additions and 17 deletions

View File

@ -47,6 +47,7 @@ case $PROMPT_COMMAND in
;; ;;
esac esac
# default autojump command
j() { j() {
if [[ ${@} =~ ^-{1,2}.* ]]; then if [[ ${@} =~ ^-{1,2}.* ]]; then
autojump ${@} autojump ${@}
@ -64,37 +65,46 @@ j() {
fi fi
} }
# jump to child directory (subdirectory of current path)
jc() { jc() {
if [[ ${@} == -* ]]; then if [[ ${@} == -* ]]; then
autojump ${@} autojump ${@}
else else
j $(pwd)/ ${@} j $(pwd) ${@}
fi fi
} }
# open autojump results in file browser
jo() { jo() {
if [ -z $(autojump $@) ]; then if [[ ${@} == -* ]]; then
echo "autojump: directory '${@}' not found" autojump ${@}
echo "Try \`autojump --help\` for more information." return
false fi
else
new_path="$(autojump ${@})"
if [ -d "${new_path}" ]; then
case ${OSTYPE} in case ${OSTYPE} in
linux-gnu) linux-gnu)
xdg-open "$(autojump $@)" xdg-open "${new_path}"
;; ;;
darwin*) darwin*)
open "$(autojump $@)" open "${new_path}"
;; ;;
cygwin) cygwin)
cygstart "" $(cygpath -w -a $(pwd)) cygstart "" $(cygpath -w -a ${new_path})
;; ;;
*) *)
echo "Unknown operating system." 1>&2 echo "Unknown operating system." 1>&2
;; ;;
esac esac
else
echo "autojump: directory '${@}' not found"
echo "Try \`autojump --help\` for more information."
false
fi fi
} }
# open autojump results (child directory) in file browser
jco() { jco() {
if [[ ${@} == -* ]]; then if [[ ${@} == -* ]]; then
autojump ${@} autojump ${@}

View File

@ -40,7 +40,7 @@ jc() {
if [[ ${@} == -* ]]; then if [[ ${@} == -* ]]; then
autojump ${@} autojump ${@}
else else
j $(pwd)/ ${@} j $(pwd) ${@}
fi fi
} }
@ -48,21 +48,29 @@ jc() {
jo() { jo() {
if [[ ${@} == -* ]]; then if [[ ${@} == -* ]]; then
autojump ${@} autojump ${@}
else return
fi
local new_path="$(autojump ${@})"
if [ -d "${new_path}" ]; then
case ${OSTYPE} in case ${OSTYPE} in
linux-gnu) linux-gnu)
xdg-open "$(autojump $@)" xdg-open "${new_path}"
;; ;;
darwin*) darwin*)
open "$(autojump $@)" open "${new_path}"
;; ;;
cygwin) cygwin)
cygstart "" $(cygpath -w -a $(pwd)) cygstart "" $(cygpath -w -a ${new_path})
;; ;;
*) *)
echo "Unknown operating system." 1>&2 echo "Unknown operating system." 1>&2
;; ;;
esac esac
else
echo "autojump: directory '${@}' not found"
echo "Try \`autojump --help\` for more information."
false
fi fi
} }
@ -70,8 +78,7 @@ jo() {
jco() { jco() {
if [[ ${@} == -* ]]; then if [[ ${@} == -* ]]; then
autojump ${@} autojump ${@}
return else
jo $(pwd) ${@}
fi fi
jo $(pwd)/ ${@}
} }