`cd` alternative. Navigate by typing abbreviation of paths.

Overview

kn /n/

Github Actions badge crates.io badge

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

Demo

.
├── 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:
  1. 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.
  2. Partial matches with smaller Levenshtein distance first.
  3. 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
  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

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 and zsh.
  • Review regular expressions used in Abbr::from_string in src/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 Congruences 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 path kn has found so far and the search could begin from that location. That would narrow down the search. (Is that possible with fish and other shells?)
  • Add --help to kn function. (How?)
  • Read about broot.
  • Enable excluding dirs.
Comments
  • G_LIBC_2.18 not found

    G_LIBC_2.18 not found

    I am on old linux machine and the linux executable requires a specific version of g_libc. Can you provide a musl version (the same way ripgrep does)? Many thanks

    opened by elkarouh 3
  • Unable to use

    Unable to use

    The situation in a nutshell:

    ~
    ❯ cargo install kn --force
        Updating crates.io index
      Installing kn v0.3.0
        Finished release [optimized] target(s) in 0.42s
       Replacing /Users/virginiacool/.cargo/bin/_kn
        Replaced package `kn v0.3.0` with `kn v0.3.0` (executable `_kn`)
    ~
    ❯ exa
    Applications  Dev
    ~
    ❯ _kn Dev
    Value of arg `subcommand` is invalid.
    ~
    ❯
    

    Two questions:

    • Why executable is _kn?
    • Why doesn't it work?
    opened by teenjuna 1
  • Surprising behavior with no arguments

    Surprising behavior with no arguments

    Running kn with no arguments kills the shell that it's running in. This is somewhat surprising and not how I'm used to tools in this category working (e.g. with zoxide/z, if no arguments are provided, then nothing happens).

    opened by chipbuster 1
  • Some pattern that didn't worked

    Some pattern that didn't worked

    In this situation:

    .
    ── foo
    │  └── bar
    ├── libfoo
    │  └── bar
    

    $ kn foo $ kn ../lib-/bar Path not found

    I don't know if it's suppose to work so I'm reporting :)

    Feel free to close is it's intended behaviour :)

    opened by Geobert 1
  • Double dot (..) in the middle of path

    Double dot (..) in the middle of path

    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.

    I see double dots in filenames all the time when users create files on Windows where filename extensions are hidden by default. For example, when dealing with personal names: Truman, Harry S..pdf, Truman, H.S..pdf - Windows users just never see the .pdf at the end so no double-dots for them :)

    opened by sio 1
  • Merge `proto/slim-down` into master.

    Merge `proto/slim-down` into master.

    Changes:

    • Remove loose slices.
    • Rename slices to abbreviations.
    • Remove search options.
    • Make abbreviations match their superseries.
    • Add ordering of findings.
    • Fix bug with - at the beginning of the abbreviation.
    • Interpret the prefix, /, . and .. components at the beginning as a start path.
    opened by micouy 0
  • Merge `refac/slice-matching` into master.

    Merge `refac/slice-matching` into master.

    Changes:

    • Add wildcards -.
    • Add extracting start dir from the first sequence.
    • Refac whole matching logic.
    • Add proper handling of search options.
    • Add logging.
    • Add tests in mod query.
    opened by micouy 0
Releases(v0.3.2)
Owner
Mikołaj Powierża
Mikołaj Powierża
A safe and ergonomic alternative to rm

rip (Rm ImProved) rip is a command-line deletion tool focused on safety, ergonomics, and performance. It favors a simple interface, and does not imple

Kevin Liu 781 Jan 7, 2023
A simple, fast and user-friendly alternative to 'find'

fd [中文] [한국어] fd is a program to find entries in your filesytem. It is a simple, fast and user-friendly alternative to find. While it does not aim to

David Peter 25.8k Dec 30, 2022
A modern alternative to watch command

A modern alternative to watch command

Tavo Annus 7 Oct 7, 2022
As-tree - Print a list of paths as a tree of paths 🌳

as-tree Print a list of paths as a tree of paths. For example, given: dir1/foo.txt dir1/bar.txt dir2/qux.txt it will print: . ├── dir1 │ ├── foo.tx

Jake Zimmerman 396 Dec 10, 2022
A faster way to navigate your filesystem

zoxide A faster way to navigate your filesystem Table of contents Introduction Examples Getting started Step 1: Install zoxide Step 2: Install fzf (op

Ajeet D'Souza 8.7k Jan 8, 2023
Broot - A new way to see and navigate directory trees

Broot A better way to navigate directories Installation Instructions Get an overview of a directory, even a big one br -s Notice the unlisted? That's

Canop 8k Jan 8, 2023
command line tool to navigate JSON files with basic SQL-like queries

navi-json command line tool to navigate JSON files with basic SQL-like queries. The name plays with the assonance with the word 'navigator', at least

Giulio Toldo 2 Oct 2, 2022
Navigate in the world of ESP32 with easy. Tool for maintaining development environment.

ESP Helm Get all important information for Embedded Development with ESP32 and mainitain the development environment. Check out releases for binary ve

Juraj Michálek 4 Aug 7, 2023
Zellij plugin to quickly navigate your panes (clone of nvim's harpoon)

harpoon A Zellij plugin for quickly searching and switching between tabs. Copy of the original harpoon for nvim. Usage a to add pane to list Up and Do

null 13 Aug 11, 2023
Lightweight command line tool to quickly navigate across folders.

slingshot 0.3.0 Slingshot is a lightweight tool to browse files in the terminal. It allows the user to quickly filter through files in any directory,

Caio Ishikawa 40 Sep 17, 2023
A fully extensible command interface to navigate around your leptos application.

leptos-kbar A fully extensible command interface to navigate around your leptos application. See demo: https://leptos-kbar.vercel.app/ Roadmap leptos-

null 7 Mar 10, 2024
ergonomic paths and files in rust

path_abs: ergonomic paths and files in rust. This library aims to provide ergonomic path and file operations to rust with reasonable performance. See

Rett Berg 45 Oct 29, 2022
A Bevy Engine plugin for making 2D paths, smooth animations with Bezier curves

bevy_pen_tool A Bevy Engine plugin for making 2D paths and smooth animations with Bezier curves TODO: Mesh-making functionality for building 2D shapes

Eli 36 Dec 22, 2022
Download pdbs from symbol servers and cache locally, parse symbol paths from env vars

symsrv This crate lets you download and cache pdb files from symbol servers, according to the rules from the _NT_SYMBOL_PATH environment variable. It

Markus Stange 6 Sep 15, 2022
Tooling for the simple-package-paths Nix RFC

Implementation Index the tree for references. If .git exists, use ls-tree equivalent Check the validity of the pkgs/unit directory Should only contain

Nixpkgs Architecture Team 3 Jan 18, 2023
Temporary files and directories with UTF-8 paths.

camino-tempfile A secure, cross-platform, temporary file library for Rust with UTF-8 paths. This crate is a wrapper around tempfile that works with th

null 4 Apr 24, 2023
Rust Macros to automate the addition of Paths/Schemas to Utoipa crate, simulating Reflection during the compilation phase

utoipa_auto_discovery Rust Macros to automate the addition of Paths/Schemas to Utoipa crate, simulating Reflection during the compilation phase Crate

null 4 Jun 9, 2023
Pathfinding library for calculating all node pairs' shortest paths in an unweighted undirected graph.

bit_gossip bit_gossip, named after its implementation technique, is a simple pathfinding library for calculating all node pairs' shortest paths in an

Jack Lee 49 Sep 4, 2024
Terminal typing "game"

ToggleCoolCowSaysType A terminal based typing game. Usage: toggle_cool_cow_says_type [-t {word_count}] [-t {file_extension}] [-s] {project_path} -s :

Togglebit 23 Sep 27, 2022
Terminal-based typing test.

ttyper Ttyper is a terminal-based typing test built with Rust and tui-rs. installation With Cargo: cargo install ttyper usage For usage instructions,

Max Niederman 527 Dec 17, 2022