I want to create an alias, that can be defined on any command and concats | lolcat
to it. So far I googled myself to
alias MyCommandName='f(){"$@" | lolcat; unset -f f};f'
but when I test it with dmesg
I get no result.
# set dmesg
alias dmesg='f(){"$@" | lolcat; unset -f f};f'
#desired command: dmesg | lolcat
dmesg
In my understanding the alias defines a function f, that is called afterwards. To prevent recursion, the last statement is to unset the function.
EDIT: I stopped at:
alias MyCommandName='f(){eval "$@ | lolcat"; unset -f f};f'
alias MyCommandName='f(){eval "$0 $@ | lolcat"; unset -f f};f'
which does not the trick, because i can't pass the $0
argument into my function. The $0
is always f inside of the function. a generic aliaslias like is NOT possible. :(
NOT A DUPLICATE of this, because I am using ZSH and argument passing is possible according to like 10 other answers like this and this :).
$@
there is from the shell's arguments, not the aliases. Just use plain functions instead:f () { "$@" | lolcat; }
thenf dmesg
.$@
is not evaluated when you define the alias). Please read those posts again and apply them properly.dmesg
i just wanna do it for fun and to set a users terminal outputs in color :), since they don't need to know, before they are surprised, i don't like thef dmesg
idea, because it spoilers, that there is something special. ;)