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