how to expand aliases inline in bash?

Is there a way to expand aliases inline in bash?

$bash>alias ll='ls -l '
$bash>ll<tab>
$bash>ls -l 

Solution 1:

You can press Ctrl-Alt-e to perform the readline function shell-expand-line which will do alias, history and word expansions. Note that on some keyboards Meta is not Alt. You might need to press Esc then Ctrl-e

The functions alias-expand-line and history-and-alias-expand-line are not bound by default, but you can bind them by adding lines similar to the following to your ~/.inputrc file.

"\e\C-l": alias-expand-line

which would make Ctrl-Alt-l (lower case "ell") perform only alias expansion.

Solution 2:

For people having zsh & Oh My ZSH installed looking for a simple solution, globalias might be your friend

Expands all glob expressions, subcommands and aliases (including global).

# .zsrc:
alias S="sudo systemctl"

$ S<space>
# expands to:
$ sudo systemctl

to install just add "globalias" to you .zshrc plugin list

plugins=(... globalias)

Then just press SPACE to trigger the expansion of a command you've written.

If you only want to insert a space without expanding the command line, press CTRL+SPACE