1

I have these:

alias nuke-gently="rm -rf"
alias ng="nuke-gently"

in my .bash_profile. (nuke also points to a script that runs sudo rm -rf with some protections against / and ~ and stuff)

What I want to happen is:

type: ng
press: <tab>
see: ng replaced with nuke-gently

I know this can be done with Ctrl + Alt + e, but that kinda defeats the purpose of my two letter alias.

Is there a way to of tab run Ctrl + Alt + e for ng? while keeping the existing tab-completion for everything else?

3
  • Why do you need to expand it? One purpose of an alias is to avoid unnecessary typing, so ng {parameters} will run what you want without the extra Tab key-stroke. Also, it would be better to define alias ng="rm -rf" directly.
    – AFH
    Oct 18, 2017 at 13:20
  • you're not wrong, but: because I think the phrasing is funny, and it would be fun to have if I needed to rm -rf something during a presentation / talk / lunch'n'learn Oct 18, 2017 at 14:07
  • I too want this functionality like zsh has but when I'm forced to use bash on a server. Mar 8 at 0:15

1 Answer 1

1

Place it on SHIFT + Tab. That's what i did.

Put the following line into your "~/.inputrc":

"\e[Z":          "SHIFT-TAB"
"SHIFT-TAB":      history-and-alias-expand-line

Now you can complete with Tab and resolve with Shift + Tab. It's absolutely comfortable and works.

4
  • I couldn't get this to work using bind Mar 8 at 0:15
  • @SridharSarnobat Open your terminal emulator, press ctrl and then v. Press shift and then tab. Take the output instead of mine for the shift-tab entry. For how to use it with the bind command i have to check later.
    – WGRM
    Mar 9 at 1:43
  • 1
    @SridharSarnobat Ok, i looked it up. Use the following command: bind '"\e[Z":history-and-alias-expand-line' and don't forget to put it in your .bashrc to make it permanent.
    – WGRM
    Mar 10 at 22:21
  • That worked, thank you very much. I'd give up on it. Ideally I'd like to use just tab like zsh can but that's probably asking too much of bash. Mar 18 at 20:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .