Skip to content

essentialkaos/path

Code Climate Maintainability Codacy badge GitHub Actions CI Status GitHub Actions CodeQL Status

InstallationCommand-line completionMan documentationUsageCI StatusContributingLicense


path is a dead simple tool for working with paths. This tool provides commands which you can use to replace such tools as basename, dirname, and readlink and many more. But unlike these tools, path allows you to pass input not only as arguments, but also using standard input (for example with pipes). It's easy to use and doesn't require to know all this kung-fu with find or xargs.

Simple examples:

find . -iname '*.txt' -print0 | xargs -0 -n1 -- basename
# or
find . -iname '*.txt' | xargs -L1 -I{} basename "{}"
# with path
find . -iname '*.txt' | path basename
# Note that there is two spaces between {} and \; and if you forget
# about this it will don't work. Also in this case we will run 'basename'
# for each item in find output.
find . -mindepth 1 -maxdepth 1 -type d -exec basename {}  \;
# with path
find . -mindepth 1 -maxdepth 1 -type d | path basename

Also, it works MUCH faster (~120x):

$ git clone https://github.com/kubernetes/kubernetes.git --depth=1

$ cd kubernetes

$ hyperfine 'find . -iname *.go -print0 | xargs -0 -n1 -- basename' 'find . -iname *.go | path basename'

Benchmark 1: find . -iname *.go -print0 | xargs -0 -n1 -- basename
  Time (mean ± σ):     12.621 s ±  0.077 s    [User: 5.871 s, System: 7.043 s]
  Range (min … max):   12.512 s … 12.745 s    10 runs

Benchmark 2: find . -iname *.go | path basename
  Time (mean ± σ):     106.5 ms ±   1.5 ms    [User: 59.8 ms, System: 60.4 ms]
  Range (min … max):   104.1 ms … 111.1 ms    28 runs

Summary
  find . -iname *.go | path basename ran
  118.45 ± 1.80 times faster than find . -iname *.go -print0 | xargs -0 -n1 -- basename

Installation

From source

To build the path from scratch, make sure you have a working Go 1.22+ workspace (instructions), then:

go install github.com/essentialkaos/path@latest
sudo dnf install -y https://pkgs.kaos.st/kaos-repo-latest.el$(grep 'CPE_NAME' /etc/os-release | tr -d '"' | cut -d':' -f5).noarch.rpm
sudo dnf install path

Prebuilt binaries

You can download prebuilt binaries for Linux and macOS from EK Apps Repository:

bash <(curl -fsSL https://apps.kaos.st/get) path

Command-line completion

You can generate completion for bash, zsh or fish shell.

Bash:

sudo path --completion=bash 1> /etc/bash_completion.d/path

ZSH:

sudo path --completion=zsh 1> /usr/share/zsh/site-functions/path

Fish:

sudo path --completion=fish 1> /usr/share/fish/vendor_completions.d/path.fish

Man documentation

You can generate man page using next command:

path --generate-man | sudo gzip > /usr/share/man/man1/path.1.gz

Usage

CI Status

Branch Status
master CI
develop CI

Contributing

Before contributing to this project please read our Contributing Guidelines.

License

Apache License, Version 2.0