How to write a zsh alias that calls a subshell?

Multi tool use
Multi tool use


How to write a zsh alias that calls a subshell?



I am trying to create a zsh alias which would do the equivalent of:


zsh


cat `which some_command`



In bash that is not achievable with an alias so I had a function in my ~/.bashrc with the following content:


~/.bashrc


function catw {
cat `/usr/bin/which "${1}"`
}



I moved the function to ~/.zhrc without changes and it works, but while in bash it executes immediately with zsh I am getting a several seconds delay before the cat command actually runs.


~/.zhrc


bash


zsh


cat



Is there a way to have this as a more efficient zsh alias? If not then why does the function takes longer to execute? Can I change anything in the function to make it work as fast as in bash?


zsh


bash





I tried your function in my zsh and catw ldd was pretty much instantaneous. Do you get the same lag when you repeat the command multiple times?
– that other guy
Jul 1 at 4:44


catw ldd





@thatotherguy: I have identified the issue: I had cat aliased to ccat (the colorizing cat from github.com/jingweno/ccat). The bash function apparently does not use the alias inside functions, while zsh probably tried to resolve the alias which caused the delay. Replacing cat with /bin/cat made the operation instant in zsh.
– ccpizza
Jul 1 at 11:18


cat


ccat


zsh


cat


/bin/cat


zsh





It's barely worth the effort in zsh: cat =some_command.
– chepner
Jul 1 at 15:39


zsh


cat =some_command





@chepner: can you please explain what you mean? and, if possible, maybe provide some links to examples?
– ccpizza
Jul 1 at 21:59





=some_command is special syntax zsh provides which does the same thing as which. You can see by running echo =some_command.
– chepner
Jul 1 at 22:40


=some_command


zsh


which


echo =some_command









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

8pNgCt
5mQU770i,5Vby7sY6IP 3KX LG5M0T04ZoYpwY,c4pCwceL2rfmEmF4BPdAouO81gPXkcUZj4dnG S65XT Ve,9FX29D,nM0Tg4z

Popular posts from this blog

PySpark - SparkContext: Error initializing SparkContext File does not exist

django NoReverseMatch Exception

List of Kim Possible characters