Get PWD from shell instead of the os.environ (#239)
This commit is contained in:
parent
d74cd962f0
commit
712d3403ef
|
|
@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
- Nushell: errors on 0.33.0.
|
- Nushell: errors on 0.33.0.
|
||||||
- PowerShell: errors when initializing in `StrictMode`.
|
- PowerShell: errors when initializing in `StrictMode`.
|
||||||
- Bash/POSIX: remove conflicting alias definitions when initializing.
|
- Bash/POSIX: remove conflicting alias definitions when initializing.
|
||||||
|
- Bash: remove extra semicolon when setting `$PROMPT_COMMAND`.
|
||||||
|
- Xonsh: use shell environment instead of `os.environ`.
|
||||||
|
|
||||||
## [0.7.2] - 2021-06-10
|
## [0.7.2] - 2021-06-10
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -334,8 +334,12 @@ mod tests {
|
||||||
let mut source = Xonsh(&opts).render().unwrap();
|
let mut source = Xonsh(&opts).render().unwrap();
|
||||||
source.push('\n');
|
source.push('\n');
|
||||||
|
|
||||||
|
let tempdir = tempfile::tempdir().unwrap();
|
||||||
|
let tempdir = tempdir.path().to_str().unwrap();
|
||||||
|
|
||||||
Command::new("pylint")
|
Command::new("pylint")
|
||||||
.args(&["--from-stdin", "zoxide"])
|
.args(&["--from-stdin", "zoxide"])
|
||||||
|
.env("HOME", tempdir)
|
||||||
.write_stdin(source)
|
.write_stdin(source)
|
||||||
.assert()
|
.assert()
|
||||||
.success()
|
.success()
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,11 @@
|
||||||
|
|
||||||
"""Initialize zoxide on Xonsh."""
|
"""Initialize zoxide on Xonsh."""
|
||||||
|
|
||||||
|
import builtins # pylint: disable=unused-import
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
{%- if cmd.is_some() %}
|
|
||||||
from builtins import aliases # type: ignore # pylint: disable=no-name-in-module
|
|
||||||
{%- endif %}
|
|
||||||
{%- if hook != InitHook::None %}
|
|
||||||
from builtins import events # type: ignore # pylint: disable=no-name-in-module
|
|
||||||
{%- endif %}
|
|
||||||
from subprocess import CalledProcessError
|
|
||||||
from typing import AnyStr, List, Optional
|
from typing import AnyStr, List, Optional
|
||||||
|
|
||||||
import xonsh.dirstack # type: ignore # pylint: disable=import-error
|
import xonsh.dirstack # type: ignore # pylint: disable=import-error
|
||||||
|
|
@ -37,9 +31,9 @@ def __zoxide_pwd() -> str:
|
||||||
{%- if resolve_symlinks %}
|
{%- if resolve_symlinks %}
|
||||||
pwd = os.getcwd()
|
pwd = os.getcwd()
|
||||||
{%- else %}
|
{%- else %}
|
||||||
pwd = os.getenv("PWD")
|
pwd = builtins.__xonsh__.env.get("PWD") # type: ignore # pylint:disable=no-member
|
||||||
if pwd is None:
|
if pwd is None:
|
||||||
raise Exception("$PWD not found in env")
|
raise Exception("$PWD not found")
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
return pwd
|
return pwd
|
||||||
|
|
||||||
|
|
@ -91,9 +85,9 @@ if globals().get("__zoxide_hooked") is not True:
|
||||||
{%- when InitHook::None %}
|
{%- when InitHook::None %}
|
||||||
{{ not_configured }}
|
{{ not_configured }}
|
||||||
{%- when InitHook::Prompt %}
|
{%- when InitHook::Prompt %}
|
||||||
@events.on_post_prompt # type: ignore # pylint:disable=undefined-variable
|
@builtins.events.on_post_prompt # type: ignore # pylint:disable=no-member
|
||||||
{%- when InitHook::Pwd %}
|
{%- when InitHook::Pwd %}
|
||||||
@events.on_chdir # type: ignore # pylint:disable=undefined-variable
|
@builtins.events.on_chdir # type: ignore # pylint:disable=no-member
|
||||||
{%- endmatch %}
|
{%- endmatch %}
|
||||||
def __zoxide_hook(**_kwargs):
|
def __zoxide_hook(**_kwargs):
|
||||||
"""Hook to add new entries to the database."""
|
"""Hook to add new entries to the database."""
|
||||||
|
|
@ -125,7 +119,7 @@ def __zoxide_z(args: List[str]):
|
||||||
check=True,
|
check=True,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
)
|
)
|
||||||
except CalledProcessError as exc:
|
except subprocess.CalledProcessError as exc:
|
||||||
raise ZoxideSilentException() from exc
|
raise ZoxideSilentException() from exc
|
||||||
|
|
||||||
__zoxide_result = __zoxide_cmd.stdout[:-1]
|
__zoxide_result = __zoxide_cmd.stdout[:-1]
|
||||||
|
|
@ -139,7 +133,7 @@ def __zoxide_zi(args: List[str]):
|
||||||
__zoxide_cmd = subprocess.run(
|
__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:
|
except subprocess.CalledProcessError as exc:
|
||||||
raise ZoxideSilentException() from exc
|
raise ZoxideSilentException() from exc
|
||||||
|
|
||||||
__zoxide_result = __zoxide_cmd.stdout[:-1]
|
__zoxide_result = __zoxide_cmd.stdout[:-1]
|
||||||
|
|
@ -153,8 +147,8 @@ def __zoxide_zi(args: List[str]):
|
||||||
{%- match cmd %}
|
{%- match cmd %}
|
||||||
{%- when Some with (cmd) %}
|
{%- when Some with (cmd) %}
|
||||||
|
|
||||||
aliases["{{cmd}}"] = __zoxide_z
|
builtins.aliases["{{cmd}}"] = __zoxide_z # type: ignore # pylint:disable=no-member
|
||||||
aliases["{{cmd}}i"] = __zoxide_zi
|
builtins.aliases["{{cmd}}i"] = __zoxide_zi # type: ignore # pylint:disable=no-member
|
||||||
|
|
||||||
{%- when None %}
|
{%- when None %}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue