I have a function that creates a new markdown file, but I was wondering how can I simplify this?

  today=$(date +"%F")

I figured I could combine the title/clean_title into one, but when I try something like ${1:l... or ${$1:l... I get console error about bad substitution. Is this possible?


Nest the ${...} bits, though do also consider how readable the code will be for future readers.

() { clean_title=${${1:l}//[^a-zA-Z0-9]/-}; printf "$clean_title" } " BLA "

Also the A-Z match probably doesn't make much sense given the earlier lowercase...


In zsh, you can nest parameter expansion operators. You can also get the date with the prompt expansion of %D{%F} (zsh also has a strftime builtin in the zsh/datetime module if you want some more verbose and readable code).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.