Skip to content

Commit

Permalink
Enable --strict checks for mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
ajeetdsouza committed Oct 28, 2021
1 parent ed47c2b commit 279e393
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 30 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
contrib/completions/* linguist-generated=true
contrib/completions/README.md linguist-generated=false
42 changes: 27 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,34 @@
"code_blocks": false,
"tables": false
},
"MD033": false
"MD033": false,
"MD041": false
} -->

<div align="center">

# zoxide

[![crates.io][crates.io-badge]][crates.io]
[![Downloads][downloads-badge]][releases]
[![Built with Nix][builtwithnix-badge]][builtwithnix]

zoxide is a smarter cd command, inspired by z and autojump. It keeps track of
the directories you use most frequently, and uses a ranking algorithm to
navigate to the best match.
zoxide is a **smarter cd command**, inspired by z and autojump.

![Tutorial][tutorial]
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>

## Examples
## Getting started

![Tutorial][tutorial]

```sh
z foo # cd into highest ranked directory matching foo
Expand All @@ -34,7 +46,7 @@ zi foo # cd with interactive selection (using fzf)

Read more about the matching algorithm [here][algorithm-matching].

## Getting started
## Installation

### *Step 1: Install zoxide*

Expand Down Expand Up @@ -137,7 +149,7 @@ To install zoxide, use a package manager:
To start using zoxide, add it to your shell.

<details>
<summary>bash</summary>
<summary>Bash</summary>

Add this to your configuration (usually `~/.bashrc`):

Expand All @@ -148,7 +160,7 @@ eval "$(zoxide init bash)"
</details>

<details>
<summary>elvish</summary>
<summary>Elvish</summary>

Add this to your configuration (usually `~/.elvish/rc.elv`):

Expand All @@ -161,7 +173,7 @@ Note: zoxide only supports elvish v0.16.0 and above.
</details>

<details>
<summary>fish</summary>
<summary>Fish</summary>

Add this to your configuration (usually `~/.config/fish/config.fish`):

Expand All @@ -172,7 +184,7 @@ zoxide init fish | source
</details>

<details>
<summary>nushell</summary>
<summary>Nushell</summary>

Add this to your configuration (find it by running `config path` in Nushell):

Expand All @@ -185,7 +197,7 @@ Note: zoxide only supports Nushell v0.37.0 and above.
</details>

<details>
<summary>powershell</summary>
<summary>PowerShell</summary>

Add this to your configuration (find it by running `echo $profile` in
PowerShell):
Expand All @@ -200,7 +212,7 @@ Invoke-Expression (& {
</details>

<details>
<summary>xonsh</summary>
<summary>Xonsh</summary>

Add this to your configuration (usually `~/.xonshrc`):

Expand All @@ -211,7 +223,7 @@ execx($(zoxide init xonsh), 'exec', __xonsh__.ctx, filename='zoxide')
</details>

<details>
<summary>zsh</summary>
<summary>Zsh</summary>

Add this to your configuration (usually `~/.zshrc`):

Expand All @@ -222,7 +234,7 @@ eval "$(zoxide init zsh)"
</details>

<details>
<summary>any POSIX shell</summary>
<summary>Any POSIX shell</summary>

Add this to your configuration:

Expand Down
6 changes: 2 additions & 4 deletions contrib/completions/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# completions

Shell completions for zoxide, auto-generated by [`clap`][clap].

Since `clap` itself is in beta at the moment, these completions should not be
treated as stable either.
Shell completions for zoxide, generated by [clap]. Since clap is in beta, these
completions should not be treated as stable.

[clap]: https://github.com/clap-rs/clap
2 changes: 1 addition & 1 deletion src/app/_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use clap::{AppSettings, ArgEnum, Parser, ValueHint};

const ENV_HELP: &str = "ENVIRONMENT VARIABLES:
_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_FZF_OPTS Custom flags to pass to fzf
_ZO_MAXAGE Maximum total age after which entries start getting deleted
Expand Down
2 changes: 1 addition & 1 deletion src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ mod tests {
let opts = Opts { cmd, hook, echo, resolve_symlinks };
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]
Expand Down
20 changes: 11 additions & 9 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, Dict, List, Optional
import typing

import xonsh.dirstack # type: ignore # pylint: disable=import-error
import xonsh.environ # type: ignore # pylint: disable=import-error
Expand All @@ -20,13 +20,13 @@ import xonsh.environ # type: ignore # pylint: disable=import-error

def __zoxide_bin() -> str:
"""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:
zoxide = "zoxide"
return zoxide


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

Expand All @@ -43,7 +43,7 @@ def __zoxide_pwd() -> str:
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."""
if path is None:
args = []
Expand All @@ -63,10 +63,12 @@ class ZoxideSilentException(Exception):
"""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."""

def wrapper(args: List[str]):
def wrapper(args: typing.List[str]) -> int:
try:
func(args)
return 0
Expand Down Expand Up @@ -94,7 +96,7 @@ if "__zoxide_hook" not in globals():
{%- else if hook == InitHook::Pwd %}
@builtins.events.on_chdir # type: ignore # pylint:disable=no-member
{%- endif %}
def __zoxide_hook(**_kwargs):
def __zoxide_hook(**_kwargs: typing.Any) -> None:
"""Hook to add new entries to the database."""
pwd = __zoxide_pwd()
zoxide = __zoxide_bin()
Expand All @@ -114,7 +116,7 @@ if "__zoxide_hook" not in globals():


@__zoxide_errhandler
def __zoxide_z(args: List[str]):
def __zoxide_z(args: typing.List[str]) -> None:
"""Jump to a directory using only keywords."""
if args == []:
__zoxide_cd()
Expand All @@ -139,7 +141,7 @@ def __zoxide_z(args: List[str]):


@__zoxide_errhandler
def __zoxide_zi(args: List[str]):
def __zoxide_zi(args: typing.List[str]) -> None:
"""Jump to a directory using interactive search."""
try:
zoxide = __zoxide_bin()
Expand Down

0 comments on commit 279e393

Please sign in to comment.