0

I have some Bash aliases which I use to perform standard day-to-day tasks in my macOS terminal using the Bash shell. Sometimes I find myself wanting to run a one-off command very similar to an alias I already have configured. My current approach is to type alias my-alias-name, copy the portion of the result within the command section of the quotes, paste it back into the Terminal input, and then edit it.

This approach is distracting and a little time consuming since command auto-complete doesn't work after I've started typing the word alias (so I either have to type in the full alias name or autocomplete my alias first and then go back to the start of the line and type alias). Also it means I have to use my mouse and replace my current clipboard contents, plus identify and copy the correct portion of the output.

Is there a way to automatically insert the alias command into the Terminal input without having to resort to copy/pasting a selection of a command output?

$ alias example-alias="ls -l"

<exa>tab,control+A<alias >

$ alias example-alias
alias example-alias='ls -l'

Highlight the text between the single quotes with mouse, +C, +V

For instance, is there a way to write an alias/script expand-alias such that the following will insert the alias command into the command input to be modified?

expand-alias example-alias

1 Answer 1

0

Per this tip, one can use control+option+E to perform alias, history, and shell expansion on the current line. Therefore one can type/autocomplete the alias command, type this key combination, and have the text inserted into the input to be modified.

A downside of this approach is that it requires remembering a three-key combination for something that is only used occasionally. Depending on how your brain works, it might be harder to remember than a well-named command would be.

You must log in to answer this question.

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