All Projects → micouy → kn

micouy / kn

Licence: MIT license
Alternative to cd. Navigate by typing abbreviations of paths.

Programming Languages

rust
11053 projects
shell
77523 projects

Projects that are alternatives of or similar to kn

Z.lua
⚡ A new cd command that helps you navigate faster by learning your habits.
Stars: ✭ 2,164 (+3082.35%)
Mutual labels:  cd, jump
Enhancd
🚀 A next-generation cd command with your interactive filter
Stars: ✭ 2,049 (+2913.24%)
Mutual labels:  cd, jump
czmod
🚀 Native Module Written in C to Boost z.lua !!
Stars: ✭ 35 (-48.53%)
Mutual labels:  cd, jump
itree
Interactive tree command for file system navigation
Stars: ✭ 18 (-73.53%)
Mutual labels:  navigation, cd
connect-backup
A tool to backup and restore AWS Connect, with some useful other utilities too
Stars: ✭ 19 (-72.06%)
Mutual labels:  cd
GoGoCarto
This repo has been moved to https://gitlab.adullact.net/pixelhumain/GoGoCarto since 17/12/2018
Stars: ✭ 43 (-36.76%)
Mutual labels:  directory
PiecewiseDeterministicMarkovProcesses.jl
Piecewise Deterministic Markov Processes in Julia
Stars: ✭ 20 (-70.59%)
Mutual labels:  jump
dirgen
Generate files and folders from a template file
Stars: ✭ 21 (-69.12%)
Mutual labels:  directory
abbreviations-in-code
List of common abbreviation in program codes
Stars: ✭ 163 (+139.71%)
Mutual labels:  abbreviation
applicationset-progressive-sync
Progressive sync controller for Argo ApplicationSet
Stars: ✭ 99 (+45.59%)
Mutual labels:  cd
hexo-directory-category
Automatically add category to Hexo article according to the article file directory.
Stars: ✭ 35 (-48.53%)
Mutual labels:  directory
release-changelog-builder-action
A GitHub action that builds your release notes / changelog fast, easy and exactly the way you want.
Stars: ✭ 515 (+657.35%)
Mutual labels:  cd
software-factory
The ready to use Continuous Integration platform
Stars: ✭ 17 (-75%)
Mutual labels:  cd
member-directory
📖 Membership directory manager with API integrations.
Stars: ✭ 19 (-72.06%)
Mutual labels:  directory
create-react-app-circleci
create-react-app + CircleCI CI/CD workflow
Stars: ✭ 18 (-73.53%)
Mutual labels:  cd
flagsmith
Open Source Feature Flagging and Remote Config Service. Host on-prem or use our hosted version at https://flagsmith.com/
Stars: ✭ 2,309 (+3295.59%)
Mutual labels:  cd
openapi-definitions
OpenAPI Definitions
Stars: ✭ 30 (-55.88%)
Mutual labels:  directory
cyanrip
Bule-ish CD ripper
Stars: ✭ 94 (+38.24%)
Mutual labels:  cd
dropship
Super simple deployment tool
Stars: ✭ 62 (-8.82%)
Mutual labels:  cd
gtree
Output tree🌳 or Make directories📁 from #Markdown or Programmatically. Provide CLI, Golang library and Web (using #Wasm ).
Stars: ✭ 88 (+29.41%)
Mutual labels:  directory

kn /n/

Github Actions badge crates.io badge

kn is an alternative to cd. It lets you navigate quickly by typing abbreviations.

cargo install kn

Then follow the configuration instructions.

Features

Abbreviations

You can use kn just like you'd use cd. The difference is that you can search with abbreviations instead of full dir names. For example, instead of foo/bar you can type fo/ba.

.
├── foo
│  └── bar
├── bar
├── photosxxxxxxxxxxx2021
└── photosxxxxxxxxxxx2020
kn foo/bar          # Use `kn` just like `cd`...
kn fo/ba            # ...or navigate with abbreviations! No asterisks required.
kn pho2021          # Type only the significant parts of the dir name. You can skip the middle part.

Wildcards

You can also use wildcards - to avoid typing a dir name altogether i.e. kn -/ba to go to foo/bar. Note that kn f-/b- will not match foo/bar. In this case - functions as a literal character.

kn -/bar            # Wildcards can be used to skip a dir name altogether (changes dir to ./foo/bar/).

Multiple dots

kn splits the arg into two parts, a prefix and a sequence of abbreviations. The prefix may contain components like c:/, /, ~/, ., .. and it is treated as a literal path. It may also contain components with more than two dots, which are interpreted like this:

kn ..               # Go to parent dir (as usual).
kn ...              # Go to grandparent dir (same as ../..).
kn ....             # Go to grand-grandparent dir (same as ../../..).

kn ........         # Type as many dots as you want!
kn .../....         # This works as well.

kn .../..../abbr    # You can put abbreviations after the prefix.

If any of the mentioned components occurs in the path after an abbreviation, it is treated as an abbreviation.

kn ./../foo/bar/../baz
#  ^---^                 prefix
#       ^------------^   abbreviations

. and the first .. mean current dir and parent dir, while the second .. is treated as an abbreviation, that is, it will match a dir name containing two dots.

--exclude-old-pwd

This flag excludes your previous location from the search. You don't have to type it when using kn, just set it in your shell script (notice the underscore in _kn):

_kn init --shell fish --exclude-old-pwd

It's useful when two paths match your abbreviation and you enter the wrong one:

my-files/
$ kn d

my-files/dir-1/
$ kn -

my-files/
$ kn d # just press arrow up twice

my-files/dir-2/
$ # success!

In order for kn to exclude the previous location there must be at least one other match and the provided arg must not be a literal path (that is, it must be an abbreviation).

Installation

Make sure to configure your shell after the installation.

From crates.io

cargo install kn

From source

  1. git clone https://github.com/micouy/kn.git

  2. cd kn

  3. 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

From the release page

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 --shell fish | source

  • bash (usually ~/.bashrc):

    eval "$(_kn init --shell bash)"

  • zsh (usually ~/.zshrc):

    eval "$(_kn init --shell zsh)"

You may also want to enable the --exclude-old-pwd flag. 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 and zsh.
  • Review Github Actions workflows in .github/workflows/.

The algorithm

kn doesn't track frecency or any other statistics. It searches the disk for paths matching the abbreviation. If it finds multiple matching paths, it orders them in such a way:

  1. Compare each component against the corresponding component of the abbreviation. The components of the path may or may not match the abbreviation. If a component matches the abbreviation, there are three possible results:

    • Complete if the corresponding components are equal.
    • Prefix if the abbreviation's component is a prefix of the path's component.
    • Subsequence(coefficient) if the abbreviation's component is a subsequence of the path's component. The coefficient is the Powierża coefficient of these strings.

    Retain only these paths in which all of the components match.

  2. Order the paths in reverse lexicographical order (compare the results from right to left). Complete then Prefix then Subsequence. Order paths with Subsequence result in ascending order of their coefficient's.

  3. Order paths with the same results with alphanumeric_sort::compare_os_str.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].