Closed philwhln closed 4 years ago
Looking in ~/.config/zsh/abbreviations
, I can see the single quotes have been replaced with double-quotes.
abbr nodes="echo "MASTERS" && kubectl get nodes --selector="kubernetes.io/role=master" && echo "REGULAR NODES" && kubectl get nodes --selector="kubernetes.io/role!=master,dedicated!=heavy" && echo "HEAVY NODES" && kubectl get nodes --selector="kubernetes.io/role!=master,dedicated=heavy""
Editing this file to escape the quotes fixes the error, so the solution would seem to be doing this escaping of double quotes on persisting the values.
abbr nodes="echo \"MASTERS\" && kubectl get nodes --selector=\"kubernetes.io/role=master\" && echo \"REGULAR NODES\" && kubectl get nodes --selector=\"kubernetes.io/role!=master,dedicated!=heavy\" && echo \"HEAVY NODES\" && kubectl get nodes --selector=\"kubernetes.io/role!=master,dedicated=heavy\""
Makes sense, thanks for reporting! Yes, the expansions get saved to the user file wrapped in double quotes. The original quote level should be preserved if possible.
It'll be probably a couple weeks before I'm able to look into it. In the meantime, single quotes will work too if you don't want to gunk up your command with slashes, and the echo's will work without quotes. And it's outside my wheelhouse but in at least some circumstances kubectl's --selector doesn't need quotes.
Cool use case, I hadn't thought to use a single abbreviation for a string of commands. I like it.
Fixed in 3.1.2!
If you version control your user abbreviations file you'll probably see some noise after the first time you make a change to any user abbreviations via the command line (ie after the first time abbr updates the user file) — more double quotes, more \
s. You don't have to change the way you write expansions, either interactively or editing the user abbrevations file directly — zsh will figure out the quoting / escaping as needed.
I added the following abbreviation with single quotes. It worked fine in that terminal session.
When I opened a new terminal I hit this error....
Trying to delete it fails...