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

Add paths in background, sync comments between shell wrappers

Closes #230.
This commit is contained in:
William Ting 2013-12-31 09:48:42 -06:00
parent 3709536698
commit b0957e50eb
3 changed files with 47 additions and 28 deletions

View File

@ -1,9 +1,15 @@
# set user installation paths
if [ -d ~/.autojump/ ]; then
export PATH=~/.autojump/bin:"${PATH}"
fi
# enable tab completion
_autojump() { _autojump() {
local cur local cur
cur=${COMP_WORDS[*]:1} cur=${COMP_WORDS[*]:1}
comps=$(autojump --complete $cur) comps=$(autojump --complete $cur)
while read i while read i; do
do
COMPREPLY=("${COMPREPLY[@]}" "${i}") COMPREPLY=("${COMPREPLY[@]}" "${i}")
done <<EOF done <<EOF
$comps $comps
@ -11,13 +17,10 @@ EOF
} }
complete -F _autojump j complete -F _autojump j
# set paths if necessary for local installations
if [ -d ~/.autojump/ ]; then
export PATH=~/.autojump/bin:"${PATH}"
fi
# change pwd hook
autojump_add_to_database() { autojump_add_to_database() {
autojump -a "$(pwd)" &>/dev/null (autojump -a "$(pwd)" &) &>/dev/null
} }
case $PROMPT_COMMAND in case $PROMPT_COMMAND in
@ -28,6 +31,7 @@ case $PROMPT_COMMAND in
;; ;;
esac esac
# default autojump command # default autojump command
j() { j() {
if [[ ${@} =~ ^-{1,2}.* ]]; then if [[ ${@} =~ ^-{1,2}.* ]]; then
@ -46,6 +50,7 @@ j() {
fi fi
} }
# jump to child directory (subdirectory of current path) # jump to child directory (subdirectory of current path)
jc() { jc() {
if [[ ${@} == -* ]]; then if [[ ${@} == -* ]]; then
@ -55,6 +60,7 @@ jc() {
fi fi
} }
# open autojump results in file browser # open autojump results in file browser
jo() { jo() {
if [[ ${@} == -* ]]; then if [[ ${@} == -* ]]; then
@ -85,6 +91,7 @@ jo() {
fi fi
} }
# open autojump results (child directory) in file browser # open autojump results (child directory) in file browser
jco() { jco() {
if [[ ${@} == -* ]]; then if [[ ${@} == -* ]]; then

View File

@ -1,23 +1,23 @@
complete -x -c j -a '(autojump --bash --complete (commandline -t))' # set user installation path
switch "$XDG_DATA_HOME"
case "*$USER*"
set -x AUTOJUMP_DATA_DIR "$XDG_DATA_HOME/autojump"
case '*'
set -x AUTOJUMP_DATA_DIR ~/.local/share/autojump
end
if not test -d $AUTOJUMP_DATA_DIR
mkdir $AUTOJUMP_DATA_DIR
end
# local installation
if test -d ~/.autojump if test -d ~/.autojump
set -x PATH ~/.autojump/bin $PATH set -x PATH ~/.autojump/bin $PATH
end end
set -x AUTOJUMP_HOME $HOME set -x AUTOJUMP_HOME $HOME
# enable tab completion
complete -x -c j -a '(autojump --bash --complete (commandline -t))'
# change pwd hook
function __aj_add --on-variable PWD
status --is-command-substitution; and return
autojump -a (pwd) &>/dev/null &
end
# misc helper functions
function __aj_err function __aj_err
echo $argv 1>&2; false echo $argv 1>&2; false
end end
@ -27,11 +27,8 @@ function __aj_not_found
__aj_err "Try `autojump --help` for more information." __aj_err "Try `autojump --help` for more information."
end end
function __aj_add --on-variable PWD
status --is-command-substitution; and return
autojump -a (pwd) >/dev/null ^$AUTOJUMP_DATA_DIR/autojump_errors
end
# default autojump command
function j function j
switch "$argv" switch "$argv"
case '-*' '--*' case '-*' '--*'
@ -49,6 +46,8 @@ function j
end end
end end
# jump to child directory (subdirectory of current path)
function jc function jc
switch "$argv" switch "$argv"
case '-*' case '-*'
@ -58,6 +57,8 @@ function jc
end end
end end
# open autojump results in file browser
function jo function jo
if test -z (autojump $argv) if test -z (autojump $argv)
__aj_not_found $argv __aj_not_found $argv
@ -76,6 +77,8 @@ function jo
end end
end end
# open autojump results (child directory) in file browser
function jco function jco
switch "$argv" switch "$argv"
case '-*' case '-*'

View File

@ -1,15 +1,20 @@
# set paths for user installations # set user installation paths
if [[ -d ${HOME}/.autojump ]]; then if [[ -d ${HOME}/.autojump ]]; then
path=(${HOME}/.autojump/bin ${path}) path=(${HOME}/.autojump/bin ${path})
fpath=(${HOME}/.autojump/functions/ ${fpath}) fpath=(${HOME}/.autojump/functions/ ${fpath})
fi fi
# set fpath if necessary for homebrew installation
# set homebrew installation paths
command -v brew &>/dev/null \ command -v brew &>/dev/null \
&& [[ -d "`brew --prefix`/share/zsh/site-functions" ]] \ && [[ -d "`brew --prefix`/share/zsh/site-functions" ]] \
&& fpath=(`brew --prefix`/share/zsh/site-functions ${fpath}) && fpath=(`brew --prefix`/share/zsh/site-functions ${fpath})
# add change pwd hook
# tab completion handled by _j file
# change pwd hook
autojump_chpwd() { autojump_chpwd() {
(autojump -a "$(pwd)" &) &>/dev/null (autojump -a "$(pwd)" &) &>/dev/null
} }
@ -17,6 +22,7 @@ autojump_chpwd() {
typeset -gaU chpwd_functions typeset -gaU chpwd_functions
chpwd_functions+=autojump_chpwd chpwd_functions+=autojump_chpwd
# default autojump command # default autojump command
j() { j() {
if [[ ${@} == -* ]]; then if [[ ${@} == -* ]]; then
@ -35,6 +41,7 @@ j() {
fi fi
} }
# jump to child directory (subdirectory of current path) # jump to child directory (subdirectory of current path)
jc() { jc() {
if [[ ${@} == -* ]]; then if [[ ${@} == -* ]]; then
@ -44,6 +51,7 @@ jc() {
fi fi
} }
# open autojump results in file browser # open autojump results in file browser
jo() { jo() {
if [[ ${@} == -* ]]; then if [[ ${@} == -* ]]; then
@ -74,6 +82,7 @@ jo() {
fi fi
} }
# open autojump results (child directory) in file browser # open autojump results (child directory) in file browser
jco() { jco() {
if [[ ${@} == -* ]]; then if [[ ${@} == -* ]]; then