From c4aebf6041c1335b5a6348ff969f83b0f7ab15cc Mon Sep 17 00:00:00 2001 From: Kent Primrose Date: Mon, 29 Mar 2021 22:10:56 -0500 Subject: [PATCH 1/2] Reference integration with nnn (autojump plugin) (#166) --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 125a675..3a8e48f 100644 --- a/README.md +++ b/README.md @@ -233,6 +233,7 @@ eval "$(zoxide init posix --hook prompt)" ## 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 From e2506631e922b0ae24e277ab5e354986c59a0815 Mon Sep 17 00:00:00 2001 From: Ajeet D'Souza <98ajeet@gmail.com> Date: Tue, 30 Mar 2021 18:44:29 +0530 Subject: [PATCH 2/2] Find zoxide in Xonsh shells (#168) --- templates/xonsh.txt | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/templates/xonsh.txt b/templates/xonsh.txt index 0d424e3..e440b38 100644 --- a/templates/xonsh.txt +++ b/templates/xonsh.txt @@ -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