0

I'm trying to create an alias for cwebp to run from zsh that converts an input image file, to an output image file of the same name, but with the .webp file extension:

# in .zshrc
alias cwebphoto='cwebp -preset "photo" -short -noalpha $1 -o ${1%.*}.webp'

Then in zsh

> cwebphoto hello.png

Returns a converted file named .webp How can I instead return a file named hello.webp?

Any help is appreciated!

s4l4x
  • 148
  • 6

1 Answers1

2

You want a function instead.

cwebphoto () {
  cwebp -preset "photo" -short -noalpha $1 -o ${1%.*}.webp
}

(In zsh, you can also use $1:r in place of ${1%.*}.)

chepner
  • 497,756
  • 71
  • 530
  • 681
  • 1
    Thank you. I'm curious where I can read more about $1:r? – s4l4x Aug 15 '20 at 01:40
  • 1
    `man zshexpn`. This and other modifiers (a single character following a `:`) are documented under history expansion, but they can also be used with parameter expansions – chepner Aug 15 '20 at 12:58