Skip to content

Commit

Permalink
feat(zsh): improved zoxide interactions
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejandroSuero committed Mar 29, 2024
1 parent 93b4650 commit 9fbe1ad
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
7 changes: 1 addition & 6 deletions roles/zsh/files/zsh/nvm.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env zsh

function check_nvmrc() {
check_nvmrc() {
if [[ -f "$PWD"/.nvmrc ]]; then
nvm use > /dev/null
fi
Expand All @@ -10,8 +10,3 @@ cd() {
builtin cd "$@"
check_nvmrc
}

z() {
__zoxide_z "$@"
check_nvmrc
}
47 changes: 47 additions & 0 deletions roles/zsh/files/zsh/zoxide.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env zsh

_z_cd() {
cd "$@" || return "$?"

if [ "$_ZO_ECHO" = "1" ]; then
echo "$PWD"
fi
}

z() {
if [ "$#" -eq 0 ]; then
_z_cd ~
elif [ "$#" -eq 1 ] && [ "$1" = '-' ]; then
if [ -n "$OLDPWD" ]; then
_z_cd "$OLDPWD"
else
echo 'zoxide: $OLDPWD is not set'
return 1
fi
else
_zoxide_result="$(zoxide query -- "$@")" && _z_cd "$_zoxide_result"
fi
check_nvmrc
}

zi() {
_zoxide_result="$(zoxide query -i -- "$@")" && _z_cd "$_zoxide_result"
}


alias za='zoxide add'

alias zq='zoxide query'
alias zqi='zoxide query -i'

alias zr='zoxide remove'
zri() {
_zoxide_result="$(zoxide query -i -- "$@")" && zoxide remove "$_zoxide_result"
}


_zoxide_hook() {
zoxide add "$(pwd -L)"
}

chpwd_functions=(${chpwd_functions[@]} "_zoxide_hook")

0 comments on commit 9fbe1ad

Please sign in to comment.