Giter Site home page Giter Site logo

fish-abbreviation-tips's Introduction

fish-abbreviation-tips Generic badge Generic badge Generic badge

asciicast

Help you remembering abbreviations and aliases by displaying tips when you can use them

๐Ÿš€ Install

Install using fisher :

fisher add Gazorby/fish-abbreviation-tips

๐Ÿ”ง Usage

Just use your shell normally and enjoy tips!

Adding / removing abbreviations or aliases

The plugin automatically track changes when adding/removing abbreviations or aliases using abbr or functions commands (see behind the scenes), so you won't see tips anymore for an abbreviation/alias that has been erased, and you will get new ones for newly added abbreviations/aliases

๐Ÿ›  Configuration

Configuration is done through environment variables.

To avoid spamming your config.fish, you can set environment variables using set -U once, to make them persistent across restarts and share them across fish's instances

Default configuration

ABBR_TIPS_PROMPT "\n๐Ÿ’ก \e[1m{{ .abbr }}\e[0m => {{ .cmd }}"
ABBR_TIPS_ALIAS_WHITELIST # Not set

ABBR_TIPS_REGEXES '(^(\w+\s+)+(-{1,2})\w+)(\s\S+)' '(^( ?\w+){3}).*' '(^( ?\w+){2}).*' '(^( ?\w+){1}).*'
# 1 : Test command with arguments removed
# 2 : Test the firsts three words
# 3 : Test the firsts two words
# 4 : Test the first word

Tips prompt

ABBR_TIPS_PROMPT

By default, tips will showing up like this :

๐Ÿ’ก ga => git add

But you customize it using the prompt environment variable. The plugin will replace {{ .abbr }} with the abbreviation/alias and {{ .cmd }} with the corresponding command.

โš ๏ธ tips are displayed using echo -e (interpretation of backslash escapes)

Alias whitelist

ABBR_TIPS_ALIAS_WHITELIST

By default, if the command is a user defined function (alias) the plugin won't search for a matching abbreviation because your aliases names are likely to be uniques, so there wouldn't be abbreviations with the same names.

But, in some cases, you may write aliases which wrap existing commands without altering their actual execution (ex : add some hooks before/after the command execution). In this special case, you may also have abbreviations using these aliases, so you don't want to ignore them.

To do that, just add these aliases to the environment variable

Regexes

ABBR_TIPS_REGEXES

If the command dosn't match an abbreviation/alias exactly, then it is tested against some regexes to try extracting a possible abbreviation/alias.

For example, you could have an abbreviation/alias like this :

gcm => git commit -m

So you want a tip when typing git commit -m "my commit", but the command doesn't match exactly git commit -m. To tackle this, we have a default regex that will match commands with arguments removed, so your git commit -m "my commit" will be tested as git commit -m.

You can add such regexes to the ABBR_TIPS_REGEXES list, and they will be tested in the order in which they have been added (see default configuration). Matching is lazy, so if the string extracted with the first regex match an abbreviation/alias, it won't go further. Keep in mind that only the first matching group will be tested. (so you must have at least one per regex)

๐ŸŽฅ Behind the scenes

In order to not slow down your prompt, the plugin store abbreviations/aliases and their corresponding commands in lists (actually simulating a dictionary, as fish doesn't support dict yet) to avoid iterating over all abbreviations/aliases each time you type a command. So retrieving an abbreviation or an alias from a command is fast as it doesn't involve any loop.

The plugin will create lists once during installation by calling __abbr_tips_init in background (more precisely in spawned shell, because fish doesn't put functions in background). Then, lists will get updated when you add or remove abbreviation/alias using abbr or functions builtin.

โœ… Support

๐Ÿ’ญ Inspiration

Inspired by zsh-fast-alias-tips and alias-tips zsh plugins

๐Ÿ“ License

MIT

fish-abbreviation-tips's People

Contributors

benjamineskola avatar gazorby avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.