https://www.stefanjudis.com/today-i-learned/suffix-aliases-in-zsh/ Skip to contentNavigation * Home * Articles * Screencasts * Projects * About * Newsletter * Other stuff * Home * Articles * Screencasts * Projects * About * Newsletter * Other stuff Stefan on Twitter Stefan on YouTube RSS Suffix aliases (-s) in Zsh Published at Jul 05 2022 Updated at Jul 05 2022 Reading time 2min This post is part of my Today I learned series in which I share all my web development learnings. I like geeking out on my local shell setup, and my dotfiles hold a few aliases I can't live without - ll, ni, nr and all these other two-character commands are deeply engrained in my muscle memory. To define an alias, you set a new command name and map it to another command. alias ll='exa -la --git --icons' Today I learned that the alias command in Zsh also supports a -s flag which enables suffix aliases. As a result, this is a valid alias in Zsh: # "Run" the file to look at its content # $ index.html # -> cat index.html alias -s html=cat You can "just run files" with a suffix alias without defining a command or making it an executable. After defining the alias above, executing index.html on your terminal will be expanded and shuffled to cat index.html. If you want to learn more about suffix aliases, access its manual via man zshbuiltins on the command line. But there's more! You can define a suffix alias for multiple file types, too. I added cat (aliased to bat on my machine) as the standard handling of the following file formats. # "Run" the file to look at its content # $ ./readme.md # -> cat ./readme.md alias -s {js,json,env,md,html,css,toml}=cat I'm super into this shorter way of looking into text files quickly. Example showing a the execution of the file "sort-by" which results in the display of its content. This functionality is pretty neat already, but there's more (even though it might be a bit of a hack). @_smhmd pointed out that they use suffix aliases to save typing git clone when cloning a git repository. They paste the repo SSH link into the terminal, and it's expanded to a proper clone command. Smart! # "Run" ssh links to clone repos # $ git@github.com:stefanjudis/dotfiles.git # -> git clone git@github.com:stefanjudis/dotfiles.git alias -s git="git clone" Running a SSH link on the terminal which results in cloning of this repo Do you know of more suffix alias use cases? If so, I'd love to hear them via email or on Twitter! Share on Twitter Subscribe to my weekly newsletter Related Topics * tilPost * Bash Related Articles * How to measure network quality (download/upload) on macOS * Recursive directory creation with shell brace expansion * What are idempotent scripts? * A directory-dependent and interactive command history * A better way to navigate/search your CLI history - McFly Learn something new every week! Sign up to start every week with quick to read Web Development learnings, productivity tricks, useful GitHub projects, #devsheets and music that keeps you going. [dude-newsl] Your email (required) [ ] Subscribe Read the last issue and join 2542 subscribers. Prefer RSS? Go to my feeds page to pick what you're interested in. Web vitals of this page These Web Vitals metrics are shown using my web-vitals-elements element. Drop it in your site and see the numbers. Other stuff * Blogroll -- Great people with fantastic ideas * Resources -- Things I like on the internet * Talks -- My conference & meetup talks * Things I use -- My hardware & software setup Go back up Info & Copyright Say Hi on Twitter, GitHub or YouTube. This site was rebuilt at 7/5/2022, 9:45:09 PM using the CEN stack ( Contentful, Eleventy & Netlify). (c) 2022 Copyright Stefan Judis. All rights reserved.