Fix return values in Bash hook (#196)

This commit is contained in:
Ajeet D'Souza 2021-04-29 01:23:43 +05:30 committed by GitHub
parent 0f5fde5afa
commit 697afe7ba6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 13 deletions

View File

@ -42,18 +42,20 @@ If you would rather not run a script, you can download the binary from the
#### On Linux
| Distribution | Repository | Instructions |
| -------------- | ----------------------- | --------------------------------------------------------- |
| **Any** | [crates.io] | `cargo install zoxide` |
| **Any** | [Linuxbrew] | `brew install zoxide` |
| Alpine Linux | [Alpine Linux Packages] | `apk add zoxide` |
| Arch Linux | [AUR] | `yay -Sy zoxide-bin` |
| CentOS | [Copr] | `dnf copr enable atim/zoxide` <br /> `dnf install zoxide` |
| Debian Testing | [Debian Packages] | `apt install zoxide` |
| Fedora | [Fedora Packages] | `dnf install zoxide` |
| NixOS | [nixpkgs] | `nix-env -iA nixpkgs.zoxide` |
| Parrot OS | | `apt install zoxide` |
| Void Linux | [Void Linux Packages] | `xbps-install -S zoxide` |
| Distribution | Repository | Instructions |
| ------------------ | ----------------------- | --------------------------------------------------------- |
| **Any** | [crates.io] | `cargo install zoxide` |
| **Any** | [Linuxbrew] | `brew install zoxide` |
| Alpine Linux 3.13+ | [Alpine Linux Packages] | `apk add zoxide` |
| Arch Linux | [AUR] | `yay -Sy zoxide-bin` |
| CentOS 7+ | [Copr] | `dnf copr enable atim/zoxide` <br /> `dnf install zoxide` |
| Debian Testing | [Debian Packages] | `apt install zoxide` |
| Devuan 4.0+ | [Devuan Packages] | `apt install zoxide` |
| Fedora 32+ | [Fedora Packages] | `dnf install zoxide` |
| NixOS | [nixpkgs] | `nix-env -iA nixpkgs.zoxide` |
| Parrot OS | | `apt install zoxide` |
| Ubuntu 21.04+ | [Ubuntu Packages] | `apt install zoxide` |
| Void Linux | [Void Linux Packages] | `xbps-install -S zoxide` |
#### On macOS
@ -244,6 +246,7 @@ Be sure to set these before calling `zoxide init`.
[crates.io]: https://crates.io/crates/zoxide
[debian packages]: https://packages.debian.org/testing/admin/zoxide
[demo.gif]: demo.gif
[devuan packages]: https://pkginfo.devuan.org/cgi-bin/package-query.html?c=package&q=zoxide
[dports]: https://github.com/DragonFlyBSD/DPorts/tree/master/sysutils/zoxide
[fedora packages]: https://src.fedoraproject.org/rpms/rust-zoxide
[freshports]: https://www.freshports.org/sysutils/zoxide/
@ -260,6 +263,7 @@ Be sure to set these before calling `zoxide init`.
[releases]: https://github.com/ajeetdsouza/zoxide/releases
[scoop]: https://github.com/ScoopInstaller/Main/tree/master/bucket/zoxide.json
[termux]: https://github.com/termux/termux-packages/tree/master/packages/zoxide
[ubuntu packages]: https://packages.ubuntu.com/hirsute/zoxide
[void linux packages]: https://github.com/void-linux/void-packages/tree/master/srcpkgs/zoxide
[xxh-plugin-prerun-zoxide]: https://github.com/xxh/xxh-plugin-prerun-zoxide
[xxh]: https://github.com/xxh/xxh

View File

@ -8,7 +8,7 @@ impl Query {
I: IntoIterator<Item = S>,
S: AsRef<str>,
{
Query(keywords.into_iter().map(|s: S| to_lowercase(s)).collect())
Query(keywords.into_iter().map(to_lowercase).collect())
}
pub fn matches<S: AsRef<str>>(&self, path: S) -> bool {

View File

@ -24,6 +24,10 @@ function __zoxide_cd() {
# Hook configuration for zoxide.
#
{# Custom prompts often use "$?" to show the exit status of the previous
# command. Adding __zoxide_hook to the front of $PROMPT_COMMAND would change
# the exit status, so we must capture it and return it manually instead. -#}
# Hook to add new entries to the database.
{%- match hook %}
{%- when Hook::None %}
@ -31,11 +35,14 @@ function __zoxide_cd() {
{%- when Hook::Prompt %}
function __zoxide_hook() {
\builtin local -r __zoxide_retval="$?"
zoxide add -- "$(__zoxide_pwd)"
return "${__zoxide_retval}"
}
{%- when Hook::Pwd %}
function __zoxide_hook() {
\builtin local -r __zoxide_retval="$?"
\builtin local -r __zoxide_pwd_tmp="$(__zoxide_pwd)"
if [ -z "${__zoxide_pwd_old}" ]; then
__zoxide_pwd_old="${__zoxide_pwd_tmp}"
@ -43,10 +50,15 @@ function __zoxide_hook() {
__zoxide_pwd_old="${__zoxide_pwd_tmp}"
zoxide add -- "${__zoxide_pwd_old}"
fi
return "${__zoxide_retval}"
}
{%- endmatch %}
{# bash throws an error if $PROMPT_COMMAND contains two semicolons in sequence.
# This is hard to avoid perfectly, but adding __zoxide_hook to the front of
# $PROMPT_COMMAND rather than the back makes this scenario unlikely. -#}
# Initialize hook.
if [ "${__zoxide_hooked}" != '1' ]; then
__zoxide_hooked='1'