mirror of
https://github.com/Llewellynvdm/zoxide.git
synced 2025-04-09 01:31:50 +00:00
Enable --strict checks for mypy
This commit is contained in:
parent
ed47c2b1ac
commit
279e393d5c
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
contrib/completions/* linguist-generated=true
|
||||||
|
contrib/completions/README.md linguist-generated=false
|
42
README.md
42
README.md
@ -3,23 +3,35 @@
|
|||||||
"code_blocks": false,
|
"code_blocks": false,
|
||||||
"tables": false
|
"tables": false
|
||||||
},
|
},
|
||||||
"MD033": false
|
"MD033": false,
|
||||||
|
"MD041": false
|
||||||
} -->
|
} -->
|
||||||
|
|
||||||
|
<div align="center">
|
||||||
|
|
||||||
# zoxide
|
# zoxide
|
||||||
|
|
||||||
[![crates.io][crates.io-badge]][crates.io]
|
[![crates.io][crates.io-badge]][crates.io]
|
||||||
[![Downloads][downloads-badge]][releases]
|
[![Downloads][downloads-badge]][releases]
|
||||||
[![Built with Nix][builtwithnix-badge]][builtwithnix]
|
[![Built with Nix][builtwithnix-badge]][builtwithnix]
|
||||||
|
|
||||||
zoxide is a smarter cd command, inspired by z and autojump. It keeps track of
|
zoxide is a **smarter cd command**, inspired by z and autojump.
|
||||||
the directories you use most frequently, and uses a ranking algorithm to
|
|
||||||
navigate to the best match.
|
It remembers which directories you use most frequently, so you can "jump" to
|
||||||
|
them in just a few keystrokes.<br />
|
||||||
|
zoxide works on all major shells.
|
||||||
|
|
||||||
|
[Getting started](#getting-started) •
|
||||||
|
[Installation](#installation) •
|
||||||
|
[Configuration](#configuration) •
|
||||||
|
[Integrations](#third-party-integrations)
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
## Getting started
|
||||||
|
|
||||||
![Tutorial][tutorial]
|
![Tutorial][tutorial]
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
z foo # cd into highest ranked directory matching foo
|
z foo # cd into highest ranked directory matching foo
|
||||||
z foo bar # cd into highest ranked directory matching foo and bar
|
z foo bar # cd into highest ranked directory matching foo and bar
|
||||||
@ -34,7 +46,7 @@ zi foo # cd with interactive selection (using fzf)
|
|||||||
|
|
||||||
Read more about the matching algorithm [here][algorithm-matching].
|
Read more about the matching algorithm [here][algorithm-matching].
|
||||||
|
|
||||||
## Getting started
|
## Installation
|
||||||
|
|
||||||
### *Step 1: Install zoxide*
|
### *Step 1: Install zoxide*
|
||||||
|
|
||||||
@ -137,7 +149,7 @@ To install zoxide, use a package manager:
|
|||||||
To start using zoxide, add it to your shell.
|
To start using zoxide, add it to your shell.
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>bash</summary>
|
<summary>Bash</summary>
|
||||||
|
|
||||||
Add this to your configuration (usually `~/.bashrc`):
|
Add this to your configuration (usually `~/.bashrc`):
|
||||||
|
|
||||||
@ -148,7 +160,7 @@ eval "$(zoxide init bash)"
|
|||||||
</details>
|
</details>
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>elvish</summary>
|
<summary>Elvish</summary>
|
||||||
|
|
||||||
Add this to your configuration (usually `~/.elvish/rc.elv`):
|
Add this to your configuration (usually `~/.elvish/rc.elv`):
|
||||||
|
|
||||||
@ -161,7 +173,7 @@ Note: zoxide only supports elvish v0.16.0 and above.
|
|||||||
</details>
|
</details>
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>fish</summary>
|
<summary>Fish</summary>
|
||||||
|
|
||||||
Add this to your configuration (usually `~/.config/fish/config.fish`):
|
Add this to your configuration (usually `~/.config/fish/config.fish`):
|
||||||
|
|
||||||
@ -172,7 +184,7 @@ zoxide init fish | source
|
|||||||
</details>
|
</details>
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>nushell</summary>
|
<summary>Nushell</summary>
|
||||||
|
|
||||||
Add this to your configuration (find it by running `config path` in Nushell):
|
Add this to your configuration (find it by running `config path` in Nushell):
|
||||||
|
|
||||||
@ -185,7 +197,7 @@ Note: zoxide only supports Nushell v0.37.0 and above.
|
|||||||
</details>
|
</details>
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>powershell</summary>
|
<summary>PowerShell</summary>
|
||||||
|
|
||||||
Add this to your configuration (find it by running `echo $profile` in
|
Add this to your configuration (find it by running `echo $profile` in
|
||||||
PowerShell):
|
PowerShell):
|
||||||
@ -200,7 +212,7 @@ Invoke-Expression (& {
|
|||||||
</details>
|
</details>
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>xonsh</summary>
|
<summary>Xonsh</summary>
|
||||||
|
|
||||||
Add this to your configuration (usually `~/.xonshrc`):
|
Add this to your configuration (usually `~/.xonshrc`):
|
||||||
|
|
||||||
@ -211,7 +223,7 @@ execx($(zoxide init xonsh), 'exec', __xonsh__.ctx, filename='zoxide')
|
|||||||
</details>
|
</details>
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>zsh</summary>
|
<summary>Zsh</summary>
|
||||||
|
|
||||||
Add this to your configuration (usually `~/.zshrc`):
|
Add this to your configuration (usually `~/.zshrc`):
|
||||||
|
|
||||||
@ -222,7 +234,7 @@ eval "$(zoxide init zsh)"
|
|||||||
</details>
|
</details>
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>any POSIX shell</summary>
|
<summary>Any POSIX shell</summary>
|
||||||
|
|
||||||
Add this to your configuration:
|
Add this to your configuration:
|
||||||
|
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
# completions
|
# completions
|
||||||
|
|
||||||
Shell completions for zoxide, auto-generated by [`clap`][clap].
|
Shell completions for zoxide, generated by [clap]. Since clap is in beta, these
|
||||||
|
completions should not be treated as stable.
|
||||||
Since `clap` itself is in beta at the moment, these completions should not be
|
|
||||||
treated as stable either.
|
|
||||||
|
|
||||||
[clap]: https://github.com/clap-rs/clap
|
[clap]: https://github.com/clap-rs/clap
|
||||||
|
@ -4,7 +4,7 @@ use clap::{AppSettings, ArgEnum, Parser, ValueHint};
|
|||||||
|
|
||||||
const ENV_HELP: &str = "ENVIRONMENT VARIABLES:
|
const ENV_HELP: &str = "ENVIRONMENT VARIABLES:
|
||||||
_ZO_DATA_DIR Path for zoxide data files
|
_ZO_DATA_DIR Path for zoxide data files
|
||||||
_ZO_ECHO Prints the matched directory before navigating to it when set to 1
|
_ZO_ECHO Print the matched directory before navigating to it when set to 1
|
||||||
_ZO_EXCLUDE_DIRS List of directory globs to be excluded
|
_ZO_EXCLUDE_DIRS List of directory globs to be excluded
|
||||||
_ZO_FZF_OPTS Custom flags to pass to fzf
|
_ZO_FZF_OPTS Custom flags to pass to fzf
|
||||||
_ZO_MAXAGE Maximum total age after which entries start getting deleted
|
_ZO_MAXAGE Maximum total age after which entries start getting deleted
|
||||||
|
@ -286,7 +286,7 @@ mod tests {
|
|||||||
let opts = Opts { cmd, hook, echo, resolve_symlinks };
|
let opts = Opts { cmd, hook, echo, resolve_symlinks };
|
||||||
let source = Xonsh(&opts).render().unwrap();
|
let source = Xonsh(&opts).render().unwrap();
|
||||||
|
|
||||||
Command::new("mypy").args(&["--command", &source]).assert().success().stderr("");
|
Command::new("mypy").args(&["--command", &source, "--strict"]).assert().success().stderr("");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
|
@ -8,7 +8,7 @@ import os
|
|||||||
import os.path
|
import os.path
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
from typing import AnyStr, Dict, List, Optional
|
import typing
|
||||||
|
|
||||||
import xonsh.dirstack # type: ignore # pylint: disable=import-error
|
import xonsh.dirstack # type: ignore # pylint: disable=import-error
|
||||||
import xonsh.environ # type: ignore # pylint: disable=import-error
|
import xonsh.environ # type: ignore # pylint: disable=import-error
|
||||||
@ -20,13 +20,13 @@ import xonsh.environ # type: ignore # pylint: disable=import-error
|
|||||||
|
|
||||||
def __zoxide_bin() -> str:
|
def __zoxide_bin() -> str:
|
||||||
"""Finds and returns the location of the zoxide binary."""
|
"""Finds and returns the location of the zoxide binary."""
|
||||||
zoxide = xonsh.environ.locate_binary("zoxide")
|
zoxide = typing.cast(str, xonsh.environ.locate_binary("zoxide"))
|
||||||
if zoxide is None:
|
if zoxide is None:
|
||||||
zoxide = "zoxide"
|
zoxide = "zoxide"
|
||||||
return zoxide
|
return zoxide
|
||||||
|
|
||||||
|
|
||||||
def __zoxide_env() -> Dict[str, str]:
|
def __zoxide_env() -> typing.Dict[str, str]:
|
||||||
"""Returns the current environment."""
|
"""Returns the current environment."""
|
||||||
return builtins.__xonsh__.env.detype() # type: ignore # pylint:disable=no-member
|
return builtins.__xonsh__.env.detype() # type: ignore # pylint:disable=no-member
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ def __zoxide_pwd() -> str:
|
|||||||
return pwd
|
return pwd
|
||||||
|
|
||||||
|
|
||||||
def __zoxide_cd(path: Optional[AnyStr] = None):
|
def __zoxide_cd(path: typing.Optional[typing.AnyStr] = None) -> None:
|
||||||
"""cd + custom logic based on the value of _ZO_ECHO."""
|
"""cd + custom logic based on the value of _ZO_ECHO."""
|
||||||
if path is None:
|
if path is None:
|
||||||
args = []
|
args = []
|
||||||
@ -63,10 +63,12 @@ class ZoxideSilentException(Exception):
|
|||||||
"""Exit without complaining."""
|
"""Exit without complaining."""
|
||||||
|
|
||||||
|
|
||||||
def __zoxide_errhandler(func):
|
def __zoxide_errhandler(
|
||||||
|
func: typing.Callable[[typing.List[str]], None]
|
||||||
|
) -> typing.Callable[[typing.List[str]], int]:
|
||||||
"""Print exception and exit with error code 1."""
|
"""Print exception and exit with error code 1."""
|
||||||
|
|
||||||
def wrapper(args: List[str]):
|
def wrapper(args: typing.List[str]) -> int:
|
||||||
try:
|
try:
|
||||||
func(args)
|
func(args)
|
||||||
return 0
|
return 0
|
||||||
@ -94,7 +96,7 @@ if "__zoxide_hook" not in globals():
|
|||||||
{%- else if hook == InitHook::Pwd %}
|
{%- else if hook == InitHook::Pwd %}
|
||||||
@builtins.events.on_chdir # type: ignore # pylint:disable=no-member
|
@builtins.events.on_chdir # type: ignore # pylint:disable=no-member
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
def __zoxide_hook(**_kwargs):
|
def __zoxide_hook(**_kwargs: typing.Any) -> None:
|
||||||
"""Hook to add new entries to the database."""
|
"""Hook to add new entries to the database."""
|
||||||
pwd = __zoxide_pwd()
|
pwd = __zoxide_pwd()
|
||||||
zoxide = __zoxide_bin()
|
zoxide = __zoxide_bin()
|
||||||
@ -114,7 +116,7 @@ if "__zoxide_hook" not in globals():
|
|||||||
|
|
||||||
|
|
||||||
@__zoxide_errhandler
|
@__zoxide_errhandler
|
||||||
def __zoxide_z(args: List[str]):
|
def __zoxide_z(args: typing.List[str]) -> None:
|
||||||
"""Jump to a directory using only keywords."""
|
"""Jump to a directory using only keywords."""
|
||||||
if args == []:
|
if args == []:
|
||||||
__zoxide_cd()
|
__zoxide_cd()
|
||||||
@ -139,7 +141,7 @@ def __zoxide_z(args: List[str]):
|
|||||||
|
|
||||||
|
|
||||||
@__zoxide_errhandler
|
@__zoxide_errhandler
|
||||||
def __zoxide_zi(args: List[str]):
|
def __zoxide_zi(args: typing.List[str]) -> None:
|
||||||
"""Jump to a directory using interactive search."""
|
"""Jump to a directory using interactive search."""
|
||||||
try:
|
try:
|
||||||
zoxide = __zoxide_bin()
|
zoxide = __zoxide_bin()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user