/README.md

https://github.com/jabirali/fish-abbrfile · Markdown · 69 lines · 56 code · 13 blank · 0 comment · 0 complexity · acca1022794cc282e100f761417e5b23 MD5 · raw file

  1. # Fish Abbrfile
  2. ## Motivation
  3. Fish has a wonderful little built-in feature called "abbreviations", which let
  4. you autocomplete predefined snippets like `gs` into commands like `git status`.
  5. However, maintaining long lists of such abbreviations clutter your `config.fish`:
  6. # Package management.
  7. abbr -ga 'a' 'sudo apt'
  8. abbr -ga 'ai' 'sudo apt install'
  9. abbr -ga 'ar' 'sudo apt autoremove --purge'
  10. abbr -ga 'as' 'apt search'
  11. abbr -ga 'ah' 'apt help'
  12. Not too bad. Could be better. This plugin lets you do the same via `~/.config/fish/abbrfile`:
  13. # Package management.
  14. a sudo apt
  15. ai sudo apt install
  16. ar sudo apt autoremove --purge
  17. as apt search
  18. ah apt help
  19. You can have any number of spaces (but not tabs) between abbreviations and expansions.
  20. Personally, I find this approach easier to maintain across machines than dealing with
  21. "universal variables", and much cleaner than maintaining lists of `abbr` commands.
  22. If you agree, this plugin is easily installable via [`fisher`][1]:
  23. fisher add jabirali/fish-abbrfile
  24. ## Advanced usage
  25. Another common usecase for abbreviations is that you want to autocorrect UNIX
  26. commands like `ls`, `find`, `grep`, `cat` to modern replacements like [`exa`][2],
  27. [`fd`][3], [`rg`][4], and [`bat`][5]. These are faster, smarter, and prettier
  28. than their classic counterparts. But they may not be available on *every* machine
  29. you check your dotfiles into, so such autocorrection can get in the way on many
  30. systems. This plugin solves that my checking that a command is valid before
  31. performing an abbreviation: so if you write the following in your `abbrfile`,
  32. # Better coreutils.
  33. ls exa
  34. find fd
  35. grep rg
  36. cat bat -p
  37. then e.g. `find` will only be autocorrected to `fd` on systems where `fd` is
  38. installed. You can add multiple entries with the same name; in the following
  39. example, the plugin prefers the editor `nvim` over `vim`, and `vim` over `vi`,
  40. but resorts to `vi` when that's the only available:
  41. # Better editors.
  42. vi vim
  43. vi nvim
  44. Note that the plugin also understands basic `sudo` usage; if it detects `sudo`,
  45. it will use the next argument to check whether the command is installed. Thus,
  46. if you e.g. want to type `pkg install` across Manjaro Linux (`sudo pamac install`),
  47. Ubuntu Linux (`sudo apt install`), and macOS (`brew install`), this should work:
  48. # Package manager.
  49. pkg sudo apt
  50. pkg sudo pamac
  51. pkg brew
  52. [1]: https://github.com/jorgebucaran/fisher
  53. [2]: https://the.exa.website/
  54. [3]: https://github.com/sharkdp/fd
  55. [4]: https://github.com/BurntSushi/ripgrep
  56. [5]: https://github.com/sharkdp/bat