103 days ago · Tech · hide · Fediverse post

Zsh modifiers are a family of suffixes that transform words as they’re expanded. Several of them are dedicated to slicing up filenames, replacing fiddly calls to dirname, basename, and friends. Let’s take a look at them now! The filename modifiers Four modifiers cover most filename manipulation. Take this variable assignment to a path: $ f=talks/robot.png These modifiers each return a different part of the path: :h (“head”) keeps the directory part, like dirname: $ print ${f:h} talks Like dirname, it returns . when there’s no directory part: $ g=robot.png $ print ${g:h} . :t (“tail”) keeps the filename part, like basename: $ print ${f:t} robot.png :r (“root”) drops the extension: $ print ${f:r} talks/robot :e (“extension”) keeps only the extension: $ print ${f:e} png Modifiers can be chained, applying left to right. For example, :t:r does “tail” then “root”, reducing a path to its bare name: $ print ${f:t:r} robot An example with :r I recently wanted to convert some PNG images into…

Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town