I figure out the solution with my way.
Firstly, i create a function called "addExpand" to add alias/fucntion easier if i want.
xb@dnxb:/tmp/t$ type -a addExpand
addExpand is a function
addExpand ()
{
echo -e "#!/bin/bash\nshopt -s expand_aliases\n. ~/.bash_aliases 2>/dev/null\n$1"' "$@"' | sudo tee /usr/bin/e_"$1";
sudo chmod +x /usr/bin/e_"$1"
}
xb@dnxb:/tmp/t$ addExpand l
#!/bin/bash
shopt -s expand_aliases
. ~/.bash_aliases 2>/dev/null
l "$@"
After i run addExpand l
, alias l
will created as an executable file named /usr/bin/e_l with following content:
xb@dnxb:/tmp/t$ cat /usr/bin/e_l
#!/bin/bash
shopt -s expand_aliases
. ~/.bash_aliases 2>/dev/null
l "$@"
Now enjoy to use expand version of alias/function:
xb@dnxb:/tmp/t$ watch --color -n 1 e_l /tmp //works like a charm !!!
xb@dnxb:/tmp/t$
Note:
[1] e_l
, prefix with 'e_' to imply it's expansion version of command.
[2] I feel too heavy to perform sourcing every seconds if run with watch -n 1
. I might need to find a way to solve this problem.
[3] Another disadvantage is it doesn't resolve alias recursively.