olets / zsh-abbr

The zsh manager for auto-expanding abbreviations, inspired by fish. ~13,000 unique cloners as of May '24, 580+ Homebrew installs 6/23-6/24
https://zsh-abbr.olets.dev
Other
510 stars 18 forks source link

Support variables in abbr value #45

Closed eric2323223 closed 2 years ago

eric2323223 commented 2 years ago

Hi, I think it wil ge great to support variable evaluation when expanding abbreviation.

For example: Given password=mysecret

abbr cflogin='cf login -p ${password} -o myOrg -s mySpace'

olets commented 2 years ago

Thanks for writing this up!

Your specific example should work if you use double quotation marks ".

% password=mysecret
% abbr cflogin="cf login -p $password -o myOrg -s mySpace"

Let me know if that doesn't work.

For more generally supporting placeholders, the best solution I've thought of is xargs. There are some examples in #21. If you end up doing something like that let me know, I'm always interested to see advanced things people get up to with abbreviations.

Unasked for security advice: I don't use cf but if not providing a password (cf login -o myOrg -s mySpace) will prompt you to interactively enter one, that's going to be safer — no chance of it getting into your zsh history, and no chance of someone seeing it over your shoulder.

eric2323223 commented 2 years ago

Thank you very much

olets commented 2 years ago

You're welcome! saw the first response too, you're totally right double quotes aren't going to give you your end goal. It's an interesting problem, but I don't think zsh-abbr will be the answer.