Skip to content

Commit

Permalink
xonsh: Fix error messages (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajeetdsouza authored Oct 5, 2021
1 parent 9176634 commit 8ec3a8b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 16 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Nushell: upgrade minimum supported version to v0.37.0.

### Fixed

- Xonsh: error messages in `zi`.
- Xonsh: configuration environment variables not being handled correctly.

## [0.7.5] - 2020-09-09

### Added
Expand Down
24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ They must be set before `zoxide init` is called.
| [ranger] | File manager | [ranger-zoxide] |
| [telescope.nvim] | Fuzzy finder for Neovim | [telescope-zoxide] |
| [vim] | Text editor | [zoxide.vim] |
| [xplr] | File manager | [zoxide.xplr] |
| [xxh] | Transports shell configuration over SSH | [xxh-plugin-prerun-zoxide] |
| [zsh-autocomplete] | Realtime completions for zsh | Supported by default |

Expand Down Expand Up @@ -375,8 +376,10 @@ They must be set before `zoxide init` is called.
[vim]: https://github.com/vim/vim
[void linux packages]: https://github.com/void-linux/void-packages/tree/master/srcpkgs/zoxide
[wiki-env]: https://github.com/ajeetdsouza/zoxide/wiki/HOWTO:-set-environment-variables "HOWTO: set environment variables"
[xplr]: https://github.com/sayanarijit/xplr
[xxh-plugin-prerun-zoxide]: https://github.com/xxh/xxh-plugin-prerun-zoxide
[xxh]: https://github.com/xxh/xxh
[zoxide.el]: https://gitlab.com/Vonfry/zoxide.el
[zoxide.vim]: https://github.com/nanotee/zoxide.vim
[zoxide.xplr]: https://github.com/sayanarijit/zoxide.xplr
[zsh-autocomplete]: https://github.com/marlonrichert/zsh-autocomplete
22 changes: 18 additions & 4 deletions templates/xonsh.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import os
import os.path
import subprocess
import sys
from typing import AnyStr, List, Optional
from typing import AnyStr, Dict, List, Optional

import xonsh.dirstack # type: ignore # pylint: disable=import-error
import xonsh.environ # type: ignore # pylint: disable=import-error
Expand All @@ -26,12 +26,17 @@ def __zoxide_bin() -> str:
return zoxide


def __zoxide_env() -> Dict[str, str]:
"""Returns the current environment."""
return builtins.__xonsh__.env.detype() # type: ignore # pylint:disable=no-member


def __zoxide_pwd() -> str:
"""pwd based on the value of _ZO_RESOLVE_SYMLINKS."""
{%- if resolve_symlinks %}
pwd = os.getcwd()
{%- else %}
pwd = builtins.__xonsh__.env.get("PWD") # type: ignore # pylint:disable=no-member
pwd = __zoxide_env().get("PWD")
if pwd is None:
raise Exception("$PWD not found")
{%- endif %}
Expand Down Expand Up @@ -93,7 +98,11 @@ if "__zoxide_hook" not in globals():
"""Hook to add new entries to the database."""
pwd = __zoxide_pwd()
zoxide = __zoxide_bin()
subprocess.run([zoxide, "add", "--", pwd], check=False)
subprocess.run(
[zoxide, "add", "--", pwd],
check=False,
env=__zoxide_env(),
)


{% endif -%}
Expand All @@ -119,6 +128,7 @@ def __zoxide_z(args: List[str]):
cmd = subprocess.run(
[zoxide, "query", "--exclude", __zoxide_pwd(), "--"] + args,
check=True,
env=__zoxide_env(),
stdout=subprocess.PIPE,
)
except subprocess.CalledProcessError as exc:
Expand All @@ -128,12 +138,16 @@ def __zoxide_z(args: List[str]):
__zoxide_cd(result)


@__zoxide_errhandler
def __zoxide_zi(args: List[str]):
"""Jump to a directory using interactive search."""
try:
zoxide = __zoxide_bin()
cmd = subprocess.run(
[zoxide, "query", "-i", "--"] + args, check=True, stdout=subprocess.PIPE
[zoxide, "query", "-i", "--"] + args,
check=True,
env=__zoxide_env(),
stdout=subprocess.PIPE,
)
except subprocess.CalledProcessError as exc:
raise ZoxideSilentException() from exc
Expand Down

0 comments on commit 8ec3a8b

Please sign in to comment.