Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evaluate subshells in EXPANSION #26

Closed
yutkat opened this issue Oct 22, 2020 · 3 comments
Closed

Evaluate subshells in EXPANSION #26

yutkat opened this issue Oct 22, 2020 · 3 comments

Comments

@yutkat
Copy link

yutkat commented Oct 22, 2020

I'd like to define abbr as follows.
abbr add --quiet -g gr='$(git rev-parse --show-cdup)'

ref:
https://github.com/momo-lab/zsh-abbrev-alias#help
-e, --eval evaluates subshells on expansion.

@olets
Copy link
Owner

olets commented Oct 23, 2020

Thanks for the idea! At this time I'm not comfortable supporting evaluation in that way. Seems like a vector for easy abuse.

If you just need the result, you can use the default expand-and-accept behavior

abbr -g gr="git rev-parse --show-cdup"
gr

If you need to use the result in a command and don't care about seeing the full text of the command, that's a good use case for an alias

% alias -g gr="git rev-parse --show-cdup"
% cd my-repo/dir
% gr
../
% cat $(gr)README.md
# snip
% cd $(gr)

I see the limitation if you do want to see the full command and it needs to not be followed by a space, for example in the above cat $(git rev-parse --show-cdup)README.md example. Currently you can

abbr -g gr='$(git rev-parse --show-cdup)'
gr<Space><Delete>README.md<Enter>

which is okay but it'd be nice to document a way of expanding in place, without having to delete a space:

abbr -g gr='$(git rev-parse --show-cdup)'
gr<some binding>README.md<Enter>

I'll plan on adding that feature.

p.s. nice GH landing page!

@yutkat
Copy link
Author

yutkat commented Oct 24, 2020

I'll try to workaround it for now.

Thank you for your reply 😉

@olets
Copy link
Owner

olets commented Oct 24, 2020

Added some friendlier widget names, see https://github.com/olets/zsh-abbr#bindings

Closing but let me know if that doesn't meet your needs

@olets olets closed this as completed Oct 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants