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

Allow for custom actions on enter/meta-enter #96

Merged
merged 3 commits into from
Feb 24, 2018

Conversation

shanematley
Copy link

The custom actions may be set using zstyle configuration. Configuration
is set in the following way:

zstyle ':zaw:<source-name>' default "<func-name|action description>"
zstyle ':zaw:<source-name>' alt "<func-name|action description>"

Also add "(Enter)" or "(Meta-enter)" to the description of actions when
selecting an action.

An example:

# Set default action for git-files using the description
zstyle ':zaw:git-files' default 'append to edit buffer'
# Set alternate action for git-files using the name of function
zstyle ':zaw:git-files' alt zaw-callback-edit-file

Now using Enter/Meta-enter will use the actions mentioned above. When tab is hit and an action is being selected, the following will be displayed, highlighting the default/alt actions for future use:

filter:
select action for 'zaw.zsh'
edit file (Meta-enter)
add
add -p
reset
checkout
rm
append to edit buffer (Enter)
[1/7]

The custom actions may be set using zstyle configuration. Configuration
is set in the following way:

zstyle ':zaw:<source-name>' default "<func-name|action description>"
zstyle ':zaw:<source-name>' alt "<func-name|action description>"
Copy link
Contributor

@termoshtt termoshtt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feature should be merged, but some implementations are not good :< Please revise them.

zaw.zsh Outdated
@@ -70,6 +70,29 @@ function zaw-register-src() {
eval "zle -N ${widget_name}"
}

function zaw-replace-descriptions-with-action-names() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically, specifying the action by name is not good idea. We should use zstyle ':zaw:git-files' alt zaw-callback-edit-file style setting.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. If I do that I might add some code for action name discovery as well.

zaw.zsh Outdated
fi
done
zstyle_name="${(L)name// /-}"
zstyle -s ":zaw:${zstyle_name}" default action_default
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

action_default and action_alt should be local

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two values are required outside the function in the current implementation. I’ll see what I can do.

zaw.zsh Outdated
;;
select-action)
if [[ ${#actions} -eq 1 ]]; then
action="${actions[1]}"
else
act_descriptions[${actions[(ie)$action_default]}]+=" (Enter)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can change key map of accept-line and accept-search using bindkey. Then the keymap may be different from Enter and Meta-Enter. This marker is then misleading.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. Did not realise that. I’ll adjust.

@shanematley
Copy link
Author

I think I've addressed your comments @termoshtt. Thanks for the feedback.

@termoshtt
Copy link
Contributor

OK, looks good for me. Thanks your contribution!

@termoshtt termoshtt merged commit 91c5e1a into zsh-users:master Feb 24, 2018
@shanematley
Copy link
Author

No worries.

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

Successfully merging this pull request may close these issues.

None yet

2 participants