{
"$type": "site.standard.document",
"canonicalUrl": "https://justingarrison.com/blog/2023-06-05-zsh-global-aliases",
"coverImage": {
"$type": "blob",
"ref": {
"$link": "bafkreiddjv6jxwrp23hk2dweioohb6wec2ibhrxwplkfbkgrcogqacjv6i"
},
"mimeType": "image/jpeg",
"size": 61507
},
"description": "My favorite zsh feature no one uses",
"path": "/blog/2023-06-05-zsh-global-aliases",
"publishedAt": "2023-06-06T05:28:41.000Z",
"site": "at://did:plc:p7uix7mresfq4nfzxp3klgfa/site.standard.publication/3mmdn7mg2qm2d",
"textContent": "Shell aliases are great, but they have some limitations.\nBy default they only work at the beginning of your prompt.\nThe only exception is if there is a trailing space in your alias value the next word is also checked if it is an alias.\n\nThat's why if you run\n\nBut if you alias watch with a trailing space the following will work\n\nZsh has an additional option called global aliases which are created with alias -g key=value and they work anywhere on the command line.\nHere's a quick example of how I use them.\n\n<iframe width=\"315\" height=\"560\" src=\"https://www.youtube.com/embed/zLIMjDkYyOw\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" allowfullscreen></iframe>\n\nMost of my global aliases are capital letters because it makes it easier for me to remember them.\nHere are the ones I use most often.\n\nThese all contain a | pipe as part of the alias to save additional keystrokes and make them easier to combine together.\n\nIt is also helpful to set some of your regular aliases to be global if you frequently use them as part of complex pipelines.\nKubectl is one I often pipe to to apply manifests and alias -g k=kubectl allows it to work anywhere in the command.\n\nIf you'd like to learn more about zsh aliases or other advanced features of zsh check out my mastering zsh workshop",
"title": "Zsh Global Aliases"
}