add bash support
This commit is contained in:
parent
6d91b4e3c4
commit
b21c1da09a
29
README.md
29
README.md
|
|
@ -13,6 +13,7 @@ A cd command that learns your habits
|
||||||
- [Adding `zoxide` to your shell](#adding-zoxide-to-your-shell)
|
- [Adding `zoxide` to your shell](#adding-zoxide-to-your-shell)
|
||||||
- [zsh](#zsh)
|
- [zsh](#zsh)
|
||||||
- [fish](#fish)
|
- [fish](#fish)
|
||||||
|
- [bash](#bash)
|
||||||
- [Configuration](#configuration)
|
- [Configuration](#configuration)
|
||||||
- [Environment variables](#environment-variables)
|
- [Environment variables](#environment-variables)
|
||||||
|
|
||||||
|
|
@ -106,6 +107,34 @@ Using [oh-my-fish](https://github.com/oh-my-fish/oh-my-fish):
|
||||||
omf install https://github.com/ajeetdsouza/zoxide
|
omf install https://github.com/ajeetdsouza/zoxide
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### bash
|
||||||
|
|
||||||
|
`bash` lacks `zsh` like `precmd` and `preexec` hooks,
|
||||||
|
install this little script to help fix that:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ curl https://raw.githubusercontent.com/rcaloras/bash-preexec/master/bash-preexec.sh -o ~/.bash-preexec.sh
|
||||||
|
|
||||||
|
# Add this line to the end of your .bashrc
|
||||||
|
source ~/.bash-preexec.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
Once `precmd` hooks are setup:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ curl https://raw.githubusercontent.com/ajeetdsouza/zoxide/master/bash_zoxide.sh -o ~/.bash_zoxide.sh
|
||||||
|
|
||||||
|
# Add this line to the end of your .bashrc
|
||||||
|
source ~/.bash_zoxide.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
Remember to reload `bash`!
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ exec bash
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
### Environment variables
|
### Environment variables
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
# pre-command hook
|
||||||
|
_zoxide_precmd() {
|
||||||
|
zoxide add
|
||||||
|
}
|
||||||
|
|
||||||
|
# TODO: find a fool proof way to check for the bash-preexec plugin
|
||||||
|
[[ -f ~/.bash_zoxide.sh ]] && precmd_functions+=(_zoxide_precmd)
|
||||||
|
|
||||||
|
function z() {
|
||||||
|
if [ $# -ne 0 ]; then
|
||||||
|
_Z_RESULT=$(zoxide query "$@")
|
||||||
|
case $_Z_RESULT in
|
||||||
|
"query: "*)
|
||||||
|
cd "${_Z_RESULT:7}"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "${_Z_RESULT}"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
alias zi="z -i"
|
||||||
|
alias za="zoxide add"
|
||||||
|
alias zq="zoxide query"
|
||||||
|
alias zr="zoxide remove"
|
||||||
Loading…
Reference in New Issue