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 :).