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

fzy should ignore bracketed paste characters. #42

Closed
fff7d1bc opened this issue May 5, 2017 · 5 comments
Closed

fzy should ignore bracketed paste characters. #42

fff7d1bc opened this issue May 5, 2017 · 5 comments

Comments

@fff7d1bc
Copy link

fff7d1bc commented May 5, 2017

Zsh since 5.1 have a bracketed-paste support. When I run fzy via hotkey, and paste anything, additional characters are pasted into the output.

The zsh snippet:

# Insert path selected with fzy into command line on ^F press.
_select_path_with_fzy() {
    local selected_path
    if ! command -v fzy >/dev/null 2>&1; then
        echo 'No fzy binary found in $PATH.'
        return 1
    fi
    echo
    selected_path="$(find -L . | cut -c 3- | fzy)"
    if [ "${selected_path}" ]; then
        LBUFFER+="${(q)selected_path}"
    fi
    zle reset-prompt
}
zle -N _select_path_with_fzy
bindkey "^F" _select_path_with_fzy

fzf seems to ignore[1] them, how about fzy dropping them too?

[1] junegunn/fzf@b8737b7

@keith
Copy link
Contributor

keith commented Jul 21, 2017

I get this case as well, for example if I copy the title of this issue, and paste it in my shell I see this:

screen shot 2017-07-21 at 11 14 15

My integration looks like this:

fuzzy_git_status_widget() {
  trap "" INT

  result="$(git status --short | cut -c4- | ./fzy)"
  if [ -n "$result" ]; then
    LBUFFER="${LBUFFER}\"$(trim_quotes $result)\""
  fi

  zle redisplay
  trap INT
}

zle     -N   fuzzy_git_status_widget
bindkey '^F' fuzzy_git_status_widget

@keith
Copy link
Contributor

keith commented Jul 21, 2017

I think ideally we could solve this here the one problem right now is that each character is handled individually

@keith
Copy link
Contributor

keith commented Jul 21, 2017

A possible hack fix for this is to pretend like these are keybindings. This patch works for me locally:

diff --git i/src/tty_interface.c w/src/tty_interface.c
index 9bc732b..db4bef1 100644
--- i/src/tty_interface.c
+++ w/src/tty_interface.c
@@ -152,6 +152,8 @@ static void action_prev(tty_interface_t *state) {
 	choices_prev(state->choices);
 }
 
+static void action_ignore(__unused tty_interface_t *state) {}
+
 static void action_next(tty_interface_t *state) {
 	update_state(state);
 	choices_next(state->choices);
@@ -236,6 +238,8 @@ static const keybinding_t keybindings[] = {{"\x7f", action_del_char},	/* DEL */
 					   {"\x1bOB", action_next}, /* DOWN */
 					   {"\x1b[5~", action_pageup},
 					   {"\x1b[6~", action_pagedown},
+					   {"\e[200~", action_ignore},
+					   {"\e[201~", action_ignore},
 					   {NULL, NULL}};
 
 #undef KEY_CTRL

@keith
Copy link
Contributor

keith commented Jul 21, 2017

I've created a PR with this approach for discussion: #45

@jhawthorn
Copy link
Owner

Fixed in 59d80ed. Thanks

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

3 participants