Skip to content

Commit

Permalink
Fix #4: replace autojump with shonenjump
Browse files Browse the repository at this point in the history
  • Loading branch information
suzaku committed Nov 30, 2020
1 parent d274d9d commit 48386d4
Showing 1 changed file with 24 additions and 30 deletions.
54 changes: 24 additions & 30 deletions scripts/shonenjump.bash
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
export AUTOJUMP_SOURCED=1

# set user installation paths
if [[ -d ~/.autojump/ ]]; then
export PATH=~/.autojump/bin:"${PATH}"
fi


# set error file location
if [[ "$(uname)" == "Darwin" ]]; then
export AUTOJUMP_ERROR_PATH=~/Library/autojump/errors.log
export AUTOJUMP_ERROR_PATH=~/Library/shonenjump/errors.log
elif [[ -n "${XDG_DATA_HOME}" ]]; then
export AUTOJUMP_ERROR_PATH="${XDG_DATA_HOME}/autojump/errors.log"
export AUTOJUMP_ERROR_PATH="${XDG_DATA_HOME}/shonenjump/errors.log"
else
export AUTOJUMP_ERROR_PATH=~/.local/share/autojump/errors.log
export AUTOJUMP_ERROR_PATH=~/.local/share/shonenjump/errors.log
fi

if [[ ! -d "$(dirname ${AUTOJUMP_ERROR_PATH})" ]]; then
Expand All @@ -21,45 +15,45 @@ fi


# enable tab completion
_autojump() {
_shonenjump() {
local cur
cur=${COMP_WORDS[*]:1}
comps=$(autojump --complete $cur)
comps=$(shonenjump --complete $cur)
while read i; do
COMPREPLY=("${COMPREPLY[@]}" "${i}")
done <<EOF
$comps
EOF
}
complete -F _autojump j
complete -F _shonenjump j


# change pwd hook
autojump_add_to_database() {
shonenjump_add_to_database() {
if [[ -f "${AUTOJUMP_ERROR_PATH}" ]]; then
(autojump --add "$(pwd)" >/dev/null 2>>${AUTOJUMP_ERROR_PATH} &) &>/dev/null
(shonenjump --add "$(pwd)" >/dev/null 2>>${AUTOJUMP_ERROR_PATH} &) &>/dev/null
else
(autojump --add "$(pwd)" >/dev/null &) &>/dev/null
(shonenjump --add "$(pwd)" >/dev/null &) &>/dev/null
fi
}

case $PROMPT_COMMAND in
*autojump*)
*shonenjump*)
;;
*)
PROMPT_COMMAND="${PROMPT_COMMAND:+$(echo "${PROMPT_COMMAND}" | awk '{gsub(/; *$/,"")}1') ; }autojump_add_to_database"
PROMPT_COMMAND="${PROMPT_COMMAND:+$(echo "${PROMPT_COMMAND}" | awk '{gsub(/; *$/,"")}1') ; }shonenjump_add_to_database"
;;
esac


# default autojump command
# default shonenjump command
j() {
if [[ ${1} == -* ]] && [[ ${1} != "--" ]]; then
autojump ${@}
shonenjump ${@}
return
fi

output="$(autojump ${@})"
output="$(shonenjump ${@})"
if [[ -d "${output}" ]]; then
if [ -t 1 ]; then # if stdout is a terminal, use colors
echo -e "\\033[31m${output}\\033[0m"
Expand All @@ -68,9 +62,9 @@ j() {
fi
cd "${output}"
else
echo "autojump: directory '${@}' not found"
echo "shonenjump: directory '${@}' not found"
echo "\n${output}\n"
echo "Try \`autojump --help\` for more information."
echo "Try \`shonenjump --help\` for more information."
false
fi
}
Expand All @@ -79,22 +73,22 @@ j() {
# jump to child directory (subdirectory of current path)
jc() {
if [[ ${1} == -* ]] && [[ ${1} != "--" ]]; then
autojump ${@}
shonenjump ${@}
return
else
j $(pwd) ${@}
fi
}


# open autojump results in file browser
# open shonenjump results in file browser
jo() {
if [[ ${1} == -* ]] && [[ ${1} != "--" ]]; then
autojump ${@}
shonenjump ${@}
return
fi

output="$(autojump ${@})"
output="$(shonenjump ${@})"
if [[ -d "${output}" ]]; then
case ${OSTYPE} in
linux*)
Expand All @@ -111,18 +105,18 @@ jo() {
;;
esac
else
echo "autojump: directory '${@}' not found"
echo "shonenjump: directory '${@}' not found"
echo "\n${output}\n"
echo "Try \`autojump --help\` for more information."
echo "Try \`shonenjump --help\` for more information."
false
fi
}


# open autojump results (child directory) in file browser
# open shonenjump results (child directory) in file browser
jco() {
if [[ ${1} == -* ]] && [[ ${1} != "--" ]]; then
autojump ${@}
shonenjump ${@}
return
else
jo $(pwd) ${@}
Expand Down

0 comments on commit 48386d4

Please sign in to comment.