kn
/n/
kn
is an alternative to cd
. It lets you navigate quickly by typing abbreviations. It doesn't track frecency or any other statistics.
WARNING: This project is in its alpha stage.
Features
.
├── foo
│ └── bar
├── bar
├── photosxxxxxxxxxxx2021
└── photosxxxxxxxxxxx2020
$ kn foo/bar # Use `kn` just like `cd`...
$ kn pho2021 # ...or navigate with abbreviations!
$ kn -/bar # Wildcards let you skip a dir name altogether (./foo/bar/).
$ kn . # Stay in current dir.
$ kn .. # Enter parent dir.
$ kn / # Enter root dir.
$ kn # Enter home dir.
$ kn ~ # Also enter home dir.
$ kn - # Go to previous location.
Details about the ordering of found paths
If `kn` finds many matching paths with the same number of components it orders them in such a way:- Complete matches before partial matches. All matches by wildcards are equal. There can't be a wildcard and a complete/partial match at the same depth.
- Partial matches with smaller Levenshtein distance first.
- The first component (the component at the smallest depth) is the most significant and so on.
Running kn a/-/b
on paths below returns them in the following order:
apple/x/b Partial(4) / Wildcard / Complete 1.
= = !=
apple/y/bee Partial(4) / Wildcard / Partial(_) 2.
apple/x/bo Partial(4) / Wildcard / Partial(1) 1.
= = !=
apple/y/bee Partial(4) / Wildcard / Partial(2) 2.
a/x/bo Complete / Wildcard / Partial(1) 1.
!= - -
apple/y/b Partial(4) / Wildcard / Complete 2.
Installation
Getting the binary
Install kn
from crates.io
cargo install kn
OR
Build binary from source
-
git clone https://github.com/micouy/kn.git
-
cd kn
-
Put the binary in a folder that is in
PATH
:cargo build -Z unstable-options --out-dir DIR_IN_PATH --release
Or just build it and copy the binary to that dir:
cargo build --release
cp target/release/_kn DIR_IN_PATH
OR
Download a binary of the latest release for your OS and move it to a directory which is in your $PATH
. You may need to change the binary's permissions by running chmod +x _kn
.
If there are any problems with the pre-compiled binaries, file an issue.
Configuring your shell
Then add this line to the config of your shell (notice the underscore in _kn
):
-
fish (usually
~/.config/fish/config.fish
):_kn init fish | source
-
bash (usually
~/.bashrc
):eval "$(_kn init bash)"
-
zsh (usually
~/.zshrc
):eval "$(_kn init zsh)"
To be able to use kn
, reload your config or launch a new shell instance.
Help wanted
In this project I have entered a lot of areas I have little knowledge about. Contributions and criticism are very welcome. Here are some things you can do:
- Check the correctness of scripts in init/.
- Add scripts and installation instructions for shells other than
fish
,bash
andzsh
. - Review regular expressions used in
Abbr::from_string
insrc/query/abbr.rs
to validate abbreviation's components. Are there other characters or sequences which should be prohibited? - Review Github Actions workflows in .github/workflows/.
TODO
Search engine
- What to do about
.
and..
in the middle of path abbreviation? With..
in paths the results would be too unpredictable. Are there any situations when..
show up in path? The user probably wouldn't type it but a command line tool could return such path. - Return objects containing details about the matches (the sequence of
Congruence
s with details about which chars have been matched). This will be useful in interactive mode. - Use inodes instead of traversing the directory structure using
read_dir()
. Guide. Are there inodes on other OSes? - Read Falsehoods programmers believe about paths.
CLI experience
- Make
kn
somewhat interactive. Tab could confirm the pathkn
has found so far and the search could begin from that location. That would narrow down the search. (Is that possible withfish
and other shells?) - Add
--help
tokn
function. (How?) - Read about
broot
. - Enable excluding dirs.