zabb - a plugin for finding z abbreviations
I love the z command. It lets me quickly jump to my favorite directories by typing very few keys. But - sometimes I give in to my OCD and pause to wonder: how few keys can I get away with?
I can experiment, try different short versions. But this is hit-and-miss, and ironically, it can mess with the ranking and change what abbreviations can be used.
Presenting the solution:
zabb is a command that tries to figure out the shortest memorable abbreviation of a directory that is usable by
z to unambiguously jump to that directory.
By default, only abbreviations that start the same way as the directory name are returned.
USAGE: zabb [<DIRECTORY>] ARGS: <DIRECTORY> Directory to find z abbrevs for. If none is given, it defaults to the current working directory FLAGS: -s or --shortest Allow abbreviations even if they do not start the same way as the directory name. (This will often find shorter abbreviations, but they may be less easy to remember) -a or --all List all (contiguous) abbreviations (implies -s) -1 or --one-letter List which directories each single-letter abbreviations in the alphabet will result in -h or --help Print help
~ > ls -d Do* Documents Downloads ~ > zabb Downloads d ~ > z d ~/Downloads > cd ~ > zabb Documents doc ~ > z doc ~/Documents > cd ~ > zabb -s Documents u m e ~ > z u ~ /Documents> cd ~ > zabb -a Documents u m e t oc cu um [...]
Non-contiguous, i.e. space-separated, abbreviations are not looked for. So, in some fairly rare circumstances, the shortest abbreviations may not be found.
Currently zabb mainly supports the zoxide implementation of
z. It works ok with z.lua, fasd and z, but may not find the shortest abbreviations for those. It may work for other implementations if they support the
z -e command. I welcome PRs to expand
zabb to other implementations.
This plugin is designed as a zinit module, but it's also compatible with other plugin managers.
You can use Turbo Mode to load
zinit ice wait'1' lucid zinit light mellbourn/zabb
The MIT License (MIT)
Copyright (c) 2021 Klas Mellbourn