Merge branch 'main' into ajeet/nu

This commit is contained in:
Ajeet D'Souza 2021-03-31 20:04:38 +05:30
commit 86e5d60148
2 changed files with 16 additions and 3 deletions

View File

@ -221,6 +221,7 @@ Be sure to set these before calling `zoxide init`.
## Third-party integrations
- [xxh](https://github.com/xxh/xxh), via [xxh-plugin-prerun-zoxide](https://github.com/xxh/xxh-plugin-prerun-zoxide)
- [nnn](https://github.com/jarun/nnn), via [autojump plugin](https://github.com/jarun/nnn/blob/master/plugins/autojump)
[alpine linux packages]: https://pkgs.alpinelinux.org/packages?name=zoxide
[aur]: https://aur.archlinux.org/packages/zoxide-bin

View File

@ -17,12 +17,21 @@ from subprocess import CalledProcessError
from typing import AnyStr, List, Optional
import xonsh.dirstack # type: ignore # pylint: disable=import-error
import xonsh.environ # type: ignore # pylint: disable=import-error
{{ SECTION }}
# Utility functions for zoxide.
#
def __zoxide_bin() -> str:
"""Finds and returns the location of the zoxide binary."""
zoxide = xonsh.environ.locate_binary("zoxide")
if zoxide is None:
zoxide = "zoxide"
return zoxide
def __zoxide_pwd() -> str:
"""pwd based on the value of _ZO_RESOLVE_SYMLINKS."""
{%- if resolve_symlinks %}
@ -90,7 +99,8 @@ if globals().get("__zoxide_hooked") is not True:
def __zoxide_hook(**_kwargs):
"""Hook to add new entries to the database."""
pwd = __zoxide_pwd()
subprocess.run(["zoxide", "add", pwd], check=False)
zoxide = __zoxide_bin()
subprocess.run([zoxide, "add", pwd], check=False)
{{ SECTION }}
@ -110,8 +120,9 @@ def __zoxide_z(args: List[str]):
__zoxide_cd(args[0])
else:
try:
zoxide = __zoxide_bin()
__zoxide_cmd = subprocess.run(
["zoxide", "query", "--"] + args, check=True, stdout=subprocess.PIPE
[zoxide, "query", "--"] + args, check=True, stdout=subprocess.PIPE
)
except CalledProcessError as exc:
raise ZoxideSilentException() from exc
@ -123,8 +134,9 @@ def __zoxide_z(args: List[str]):
def __zoxide_zi(args: List[str]):
"""Jump to a directory using interactive search."""
try:
zoxide = __zoxide_bin()
__zoxide_cmd = subprocess.run(
["zoxide", "query", "-i", "--"] + args, check=True, stdout=subprocess.PIPE
[zoxide, "query", "-i", "--"] + args, check=True, stdout=subprocess.PIPE
)
except CalledProcessError as exc:
raise ZoxideSilentException() from exc