Coder Social home page Coder Social logo

alias-tips's Introduction

alias-tips

Build Status

A Zsh plugin to help remembering those shell aliases and Git aliases you once defined.

Works with Oh My Zsh, Fig, zplug, antigen, zgen, Arch Linux, or pure Zsh.

It works by trying to find an shell or Git alias for the command you are currently executing and printing a help line reminding you about that alias.

The idea is that you might be too afraid to execute aliases defined because you can't remember them correctly, or just have forgotten about some aliases, or that aliases for your daily commands even exist.

Example

$ ls -lh
Alias tip: ll
:

$ git gui
Alias tip: gg
:

$ git rebase --interactive master
Alias tip: grbi master
:

$ git status
Alias tip: g st
:

Installation

  1. Get it

    Go to your custom plugins folder:

    cd ${ZSH_CUSTOM1:-$ZSH/custom}/plugins

    Then either clone:

    git clone https://github.com/djui/alias-tips.git

    Or download:

    wget https://github.com/djui/alias-tips/archive/master.zip
    unzip master.zip && mv alias-tips-master alias-tips && rm master.zip

    Or add it as submodule:

    git submodule add https://github.com/djui/alias-tips
    git submodule update --init
  2. Include it

    Then add the plugin to your plugin list in oh-my-zsh configuration:

    $EDITOR ~/.zshrc
    
    # -plugins=(...)
    # +plugins=(... alias-tips)

Fig

Fig adds apps, shortcuts, and autocomplete to your existing terminal.

Install alias-tips in just one click.

  1. Add zplug "djui/alias-tips" to your .zshrc
  2. Install it with zplug install
  1. Add antigen bundle djui/alias-tips to your .zshrc with your other antigen bundle commands.
  1. Add zgen load djui/alias-tips to your .zshrc
  2. Regenerate your init.zsh with zgen save

Arch Linux

  1. Install alias-tips-git from the AUR.

  2. Add the following to your .zshrc:

    source /usr/share/zsh/plugins/alias-tips/alias-tips.plugin.zsh
  3. Start a new terminal session.

Zsh

    1. Get it git clone https://github.com/djui/alias-tips.git ~/.zsh/alias-tips
  1. Add source alias-tips/alias-tips.plugin.zsh to your .zshrc.

Usage

After installation re-source your .zshrc.

Customizations

Customize the Output

The help string can be configured exporting an environment variable, e.g. in your .zshrc:

:
export ZSH_PLUGINS_ALIAS_TIPS_TEXT="Alias tip: "
:

Exclude some Aliases

A list of aliases to be excluded from being reminded of can be configured exporting an environment variable of space separated aliases, e.g. in your .zshrc:

:
export ZSH_PLUGINS_ALIAS_TIPS_EXCLUDES="_ ll vi"
:

Disable Command Expansion

If you have several alias, e.g. for different git commands the command get expanded before looking for an alias.

Example:

alias gRv='git remote -v'
alias gR='git remote'

Without the expand option gR -v will execute without a tip, with expand, it will suggest gRv.

If this may not be desired, the behaviour can be disabled by setting the environment variable, e.g. in your .zshrc:

:
export ZSH_PLUGINS_ALIAS_TIPS_EXPAND=0
:

Force Alias Use

If you want to force yourself to use the aliases you set you can enable this option through this environmental variable:

:
export ZSH_PLUGINS_ALIAS_TIPS_FORCE=1
:

This will cause alias-tips to abort the command you have entered if there exists an alias for it.

Reveal Command

If you want to reveal aliased command, e.g. to demonstrate your shell to someone else you can enable this option through this environmental variable:

:
export ZSH_PLUGINS_ALIAS_TIPS_REVEAL=1
:

Use this environmental variable to customize text:

:
export ZSH_PLUGINS_ALIAS_TIPS_REVEAL_TEXT="Alias tip: "
:

And this to exclude some obvious expansions:

:
export ZSH_PLUGINS_ALIAS_TIPS_REVEAL_EXCLUDES=(_ ll vi)
:

Limitations

  • Suffix and Global aliases are currently not supported. Only Prefix aliases ("command position") are supported. Check the Zsh manual on alias for their definition.
  • Multiline aliases (aliases which definition span multiple lines) are not supported. Currently their first line only will be used (likely incorrectly)

FAQ

Q: Why only Zsh?

A: This works because of feature in Zsh called preexec. Other shells, e.g. Bash, do not have this feature. There are workarounds[1,2] but integrating these is a task left for the reader.

Testing

$ python  -m unittest test_alias-tips
$ python3 -m unittest test_alias-tips

Contributing

See: CONTRIBUTIONS.md.

alias-tips's People

Contributors

burningserenity avatar djui avatar engnadeau avatar gamepad64 avatar graingert avatar i60r avatar ibayramli avatar infokiller avatar isac322 avatar jeffreytse avatar jschaf avatar m42e avatar mephistophiles avatar molovo avatar mrienstra avatar orestisfl avatar pradyunsg avatar tomprince avatar unixorn avatar yamsol avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

alias-tips's Issues

Find aliases defined with redirects

Sometimes it makes sense to define an alias with redirect(s) prefixed if additional arguments are prepended.

# alias ggb='2>/dev/null git gui'
$ 2>/dev/null git gui blame foo
$ git gui 2>/dev/null blame foo
$ git gui blame 2>/dev/null foo
$ git gui blame foo 2>/dev/null

Should all be suggestion ggb foo.

One could imagine stripping the redirects for alias finding and then appending them again for the suggestion.

feature request: show alias the other way around

with this great plugin I can see my alias when typing 'git remote -v'.
This alias-tips plugin will show: grv. Great!

so now my question: wouldn't it be great to also show what I am actually aliassing?
so when I type 'grv', the Alias-Tips will output:
'git remote -v' . Would be very handy when I give a training, share my screen or even remember what I am actually doing ;-)

"git alias" is not a git command

git: 'alias' is not a git command. See 'git --help'.

I think you have a git alias named "alias", but it is not working for me.
Pls use the real git command, I think it might be something like 'git config --get-regexp "^alias."'

Add support for multiline aliases

Not that I want it but someone might someday. If so, this should be added.

Or if someone me feels bored and wants to extend this project.

python command not found error

I am using this awesome plugin from a long time but today I updated my Ubuntu 18.04 to Ubuntu 20.04. When I tried to source my .zshrc this plugin got the following error:

_alias_tips__preexec:37: command not found: python

After a bit of googling, I found that Ubuntu 20.04 has removed the symlink to python2.x from /usr/bin/python and now it only has python3 command available. Can someone help me how to resolve this issue? This error is coming again and again after every command I use.

Unexpected "reveals" for non-aliases

I've found some unexpected "Alias for:" messages, especially while running particularly long commands:

$ echo longlonglonglonglonglonglong linelinelinelinelinelinelinelinelinelineline
Alias for: echo longlonglonglonglonglonglong linelinelinelinelinelinelinelinelinelinelin 
longlonglonglonglonglonglong linelinelinelinelinelinelinelinelinelineline

I believe this is because the second argument to the preexec hook can be trimmed and what we really want is to compare the command with the third argument, which is not trimmed.

Another issue is with export (maybe some other builtins too, but I've only seen export so far):

$ export TEST=x                                                                   
Alias for: export TEST=x  

This one is because expanded command for some reason has a trailing whitespace. I'm not sure, maybe this is actually a zsh bug, but we can easily workaround this by removing the trailing whitespace before doing comparison.

Would you be interested in PRs to fix that? Any objections to

  1. Using CMD_EXPANDED=$3 instead of CMD_EXPANDED=$2
  2. Removal trailing whitespace from CMD/CMD_EXPANDED?

grep: (standard input): binary file matches

When the function has special characters, this plugin will show up this error information output by grep, this error was shown on every executed command, here is the key code line caused the error, it could be easily reproduced by using zsh-vi-mode at the same time.

image

image

Allow ignoring certain aliases.

It would be nice to be able to ignore certain aliases. For example, if I have an alias to correct a common-typo, I don't want to be reminded of the typo if I type the correct command.

Find alias even when flag order is differently defined

Currently the following does not work:

# alias l=ls '-l -h -a'
# alias l=ls -lha'
$ ls -l -a -h foo
$ ls -lah foo

should be suggestion: l foo.

The algorithm should change to a heuristic that in most cases finds the alias. What makes this non-trivial is at least:

  1. -- must be respected as flag and argument terminator
  2. -foo is indistinguishable from -f -o -o for some commands but is actually --foo for other commands
  3. -f bar, --foo bar, and --foo=bar are not always identical depending on if -f|--foo is and argument flag or bool flag.

Acceptance criteria and constraints:

  • It's OK if only cases like alias l=ls '-l -h -a' are handled and not yet alias l=ls -lha'.
  • The above case should be solved.
  • No regression should be introduced.
  • It's tolerable if it introduces a neglect able amount of false-positives, e.g.: docker run foo -- -it != dr foo (or dr foo --) if alias alias dr='docker run -it' defined.
  • It's not tolerable for run-time to go up significantly, as one would have to check for all permutations over all aliases defined.

grep -> ripgrep alias error

Hi there.

I've discovered that using alias-tips alongside the following alias provides the following error:

alias grep='rg -uu'

Error parsing regex near '.\+ () {$' at character offset 14: Empty regex groups (e.g., '()') are not allowed.

Python IndexError

Hi, for some reason I'm getting a Python IndexError:

Traceback (most recent call last):
  File "../djui/alias-tips-master/alias-tips", line 39, in <module>
    main()
  File "../djui/alias-tips-master/alias-tips", line 24, in main
    aliases = get_aliases()
  File "../djui/alias-tips-master/alias-tips", line 20, in get_aliases
    return [(alias[0], alias[1].strip('\'')) for alias in aliases]
IndexError: list index out of range

Any idea why? I'm running Python 2.7.3 by the way.

Thanks.

_alias_tips__preexec:34: command not found: python

Recently getting this message on OSX:

~/htdocs
❯ which python
_alias_tips__preexec:34: command not found: python
python not found

~/htdocs
❯ which python3
_alias_tips__preexec:34: command not found: python
/opt/homebrew/bin/python3

`ZSH_PLUGINS_ALIAS_TIPS_FORCE=1` not working

Hey I had the force alias tips working on my win10 wsl ubuntu setup. I reinstalled windows and the wsl system, but after reinstalling everything I noticed the force on aliases isn't working. Other stuff like export ZSH_PLUGINS_ALIAS_TIPS_REVEAL=1 still work, but not the force one.

how to zplug

zplug "djui/alias-tips" install alias-tips, but no effects in shell.
how to config?

Support zsh-abbr

Reproducing the issue

  • Install zsh-abbr.
  • Run alias ll="ls -l".
  • Run abbr import-aliases.
  • Run ll. It's autoexpanded by zsh-abbr.
  • alias-tips displays that I should use ll, which I already did

Python Required?

I'm currently cleaning up my dotfiles, and noticed some weird issues when using pyenv. I use pyenv exclusively for my development stuff, and try to keep my global userspace as clean as possible.

Because of this, I narrowed down the following error message to this plugin:

Command 'python' not found, did you mean:

  command 'python3' from deb python3
  command 'python' from deb python-is-python3

This basically appears on my CLI after each command I run, until I manually load pyenv (by running pyenv) to activate the shim, at which point this plugin starts working.

It would be super cool if this plugin could work without relying on a system python.

Constantly showing suggestion even when using suggestion

Hello! Just installed this yesterday and am unsure if I am missing something as it doesn't seem to work as expected. I tried using the various config options to change the behavior but am currently stuck.

If I use a command that has an alias, such as npm i -g yarn, I get a correct suggestion to use npmg yarn instead. However, when I use that, I get the same suggestion. Would love to use the force option to force me to use aliases, but this currently means I can run no commands that have an alias.

Some sample output when I have force on:

❯ zshconfig
Alias tip: zshconfig
❯ zshconfig
Alias tip: zshconfig
❯ npmg yarn
Alias tip: npmg yarn
❯ nano ~/Dropbox/ohmyzsh/zshrc
Alias tip: nano ~/Dropbox/ohmyzsh/zshrc

The current options I have set in my .zshrc are:

# Alias-tips options
export ZSH_PLUGINS_ALIAS_TIPS_TEXT="Alias tip: "
export ZSH_PLUGINS_ALIAS_TIPS_EXCLUDES="ls"
export ZSH_PLUGINS_ALIAS_TIPS_EXPAND=1
export ZSH_PLUGINS_ALIAS_TIPS_FORCE=1
export ZSH_PLUGINS_ALIAS_TIPS_REVEAL=0
export ZSH_PLUGINS_ALIAS_TIPS_REVEAL_TEXT="Alias was: "
export ZSH_PLUGINS_ALIAS_TIPS_REVEAL_EXCLUDES=(ls)

Would love to use this plugin so any help would be appreciated!

[Request] support partial alias

for example I have two alias
alias g='git'
alias gp = 'git push'

and then if i do g push it won't show me the prompt that this is the same as gp

Reveal git aliases

Hey! This plugin is almost exactly what I was looking for! Kudos 👍
But I'm missing something, which is the "reveal used alias" feature for git aliases.

After adding export ZSH_PLUGINS_ALIAS_TIPS_REVEAL=1, it works fine for regular aliases

$ ll
Alias for: ls -G -lh
total 64
drwxr-xr-x   16 jose.armesto  staff   512B 30 mar 21:49 .
drwxr-xr-x+ 125 jose.armesto  staff   3,9K 31 mar 12:37 ..
drwxr-xr-x   16 jose.armesto  staff   512B 31 mar 12:37 .git
-rw-r--r--    1 jose.armesto  staff   105B 23 may  2016 .gitignore
-rw-r--r--    1 jose.armesto  staff   4,8K 30 mar 21:39 CONTRIBUTING.md
-rw-r--r--    1 jose.armesto  staff   1,2K 30 mar 21:39 LICENSE.txt
-rw-r--r--    1 jose.armesto  staff   9,1K 30 mar 21:39 README.md

But it doesn't for git aliases

$ git dm
Alias tip: g dm
$ g dm
Alias for: git dm

I'd like to see this output

$ git dm
Alias for: !git branch --merged | grep -v '\*' | xargs -n 1 git branch -d

Since these are my git aliases

$ git alias
Alias tip: g alias
alias=!git config -l | grep ^alias | cut -c 7- | sort
amend=commit --amend --no-edit
dm=!git branch --merged | grep -v '\*' | xargs -n 1 git branch -d

Any ideas?

Error when running any command

On master any command I run gives a similar output:

_alias_tips__preexec:17: argument list too long: python
zsh: argument list too long: ls
rbenv:11: argument list too long: rbenv
rbenv:11: argument list too long: rbenv
prompt_background_jobs:1: argument list too long: wc
prompt_background_jobs:2: argument list too long: awk

If I checkout commit 5a2a92f the problem goes away. Any ideas?

zsh version: 5.2
zplug version 2.1.0

Performance Hit on Oh My Zsh

I love Alias tips, but it causes my startup time to take a severe hit, as shown by zprof:

~> zprof
num  calls                time                       self            name
-----------------------------------------------------------------------------------
 1)    1         242.86   242.86   43.35%    242.86   242.86   43.35%  _alias_tips__preexec

Is there any way to fix/optimize this? I am using oh-my-zsh.

aliasing git breaks functionality

I have git itself aliased:

alias g=git

This causes git aliases not to be found.
That is, git status will cause Alias tip: git st, but g status will not result in any message about aliases.

Is it possible to configure alias-tips so that g is correctly interpreted as an alias to git?

Alias prefix issue (nonexistent alias suggestion)

Should you define m as an alias for make, for example, then running makepkg will prompt the plugin to remind you that there's an alias for that (mpkg in this case) even though there's no such alias.

Expand aliases within commands to find alias tips

Hi - thanks for the awesome plugin! I have an enhancement suggestion for you.

I use the oh-my-zsh git plugin, and I've already trained myself to always use g instead of git - which unfortunately means that alias-tips doesn't work for any git command that I type. (I assume because it doesn't expand g -> git before finding an alias matching the command.)

Here's an example:

→ repo:(master) g status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
→ repo:(master) git status
Alias tip: gst
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean

The relevant aliases from the git plugin:

alias g='git'
alias gst='git status'

Sounds tricky, but it would be really great if alias-tips expanded aliases inside commands.

Tips for git

How about adding tips support for git's own aliases?

Say, I have a git alias c commit.

So, if I run

git commit -m "new commit"

It would be nice if I got a message for that like:

Alias Tip: git c -m "new commit"

why are functions excluded?

I see functions are actively excluded, why is that? sometimes I use functions for better args parsing and sometimes I forget I made them :)

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.