Monday, May 20, 2024
HomeJavaScriptSuffix aliases (-s) in Zsh

Suffix aliases (-s) in Zsh


I like geeking out on my native shell setup, and my dotfiles maintain a number of aliases I am unable to dwell with out – ll, ni, nr and all these different two-character instructions are deeply engrained in my muscle reminiscence.

To outline an alias, you set a brand new command title and map it to a different command.

alias ll='exa -la --git --icons'

As we speak I discovered that the alias command in Zsh additionally helps a -s flag which permits suffix aliases. Consequently, it is a legitimate alias in Zsh:




alias -s html=cat

You possibly can “simply run information” with a suffix alias with out defining a command or making it an executable. After defining the alias above, executing index.html in your terminal might be expanded and shuffled to cat index.html. 😲

If you wish to study extra about suffix aliases, entry its handbook by way of man zshbuiltins on the command line.

However there’s extra! You possibly can outline a suffix alias for a number of file sorts, too. I added cat (aliased to bat on my machine) as the usual dealing with of the next file codecs.




alias -s {js,json,env,md,html,css,toml}=cat

I am tremendous into this shorter manner of trying into textual content information rapidly.

Example showing a the execution of the file "sort-by" which results in the display of its content.

This performance is fairly neat already, however there’s extra (though it may be a little bit of a hack). @_smhmd identified that they use suffix aliases to avoid wasting typing git clone when cloning a git repository. They paste the repo SSH hyperlink into the terminal, and it is expanded to a correct clone command. Good! 😲




alias -s git="git clone"
Running a SSH link on the terminal which results in cloning of this repo

Are you aware of extra suffix alias use instances? In that case, I would love to listen to them by way of electronic mail or on Twitter!



RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments