Skip to content
Myr

Add alternative execute notation that does not require closing char

Before adoption: this commit came in with the history the project adopted, so no landing records it.

This can be used to avoid parse errors that can happen when the command contains the closing character. Since the command does not finish at a certain character, the key binding should be the last one in the group. Suggested by @tiziano88. (#265) e.g. fzf --bind "ctrl-m:execute=COMMAND..." --bind ctrl-j:accept

authored by Junegunn Choi · committed by Junegunn Choi · parent e720f56 · Browse files · 2 files+11 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+11 added−5 removed

  • other:+11 added−5 removed

2 files+11 added−5 removed

modified:src/options_test.go+3 added-1 removed
161 unmodified lines
162 keymap, execmap, toggleSort :=163 parseKeymap(keymap, execmap, false,164 "ctrl-a:kill-line,ctrl-b:toggle-sort,c:page-up,alt-z:page-down,"+165 "f1:execute(ls {}),f2:execute/echo {}, {}, {}/,f3:execute[echo '({})'],f4:execute:less {}:,"+166 "alt-a:execute@echo (,),[,],/,:,;,%,{}@,alt-b:execute;echo (,),[,],/,:,@,%,{};")166 "alt-a:execute@echo (,),[,],/,:,;,%,{}@,alt-b:execute;echo (,),[,],/,:,@,%,{};"+167 ",X:execute=foobar,Y:execute(baz)")168 if !toggleSort {169 t.Errorf("toggleSort not set")170 }171 check(actKillLine, keymap[curses.CtrlA])
9 unmodified lines
181 checkString("echo '({})'", execmap[curses.F3])182 checkString("less {}", execmap[curses.F4])183 checkString("echo (,),[,],/,:,;,%,{}", execmap[curses.AltA])184 checkString("echo (,),[,],/,:,@,%,{}", execmap[curses.AltB])185 checkString("foobar,Y:execute(baz)", execmap[curses.AltZ+'X'])186187 for idx, char := range []rune{'~', '!', '@', '#', '$', '%', '^', '&', '*', '|', ':', ';', '/'} {188 keymap, execmap, toggleSort =189 parseKeymap(keymap, execmap, false, fmt.Sprintf("%d:execute%cfoobar%c", idx%10, char, char))
55 unmodified lines
modified:src/options.go+8 added-4 removed
410 unmodified lines
411 if executeRegexp == nil {412 // Backreferences are not supported.413 // "~!@#$%^&*:;/|".each_char.map { |c| Regexp.escape(c) }.map { |c| "#{c}[^#{c}]*#{c}" }.join('|')414 executeRegexp = regexp.MustCompile(415 ":execute(\\([^)]*\\)|\\[[^\\]]*\\]|~[^~]*~|![^!]*!|@[^@]*@|\\#[^\\#]*\\#|\\$[^\\$]*\\$|%[^%]*%|\\^[^\\^]*\\^|&[^&]*&|\\*[^\\*]*\\*|:[^:]*:|;[^;]*;|/[^/]*/|\\|[^\\|]*\\|)")415 ":execute=.*|:execute(\\([^)]*\\)|\\[[^\\]]*\\]|~[^~]*~|![^!]*!|@[^@]*@|\\#[^\\#]*\\#|\\$[^\\$]*\\$|%[^%]*%|\\^[^\\^]*\\^|&[^&]*&|\\*[^\\*]*\\*|:[^:]*:|;[^;]*;|/[^/]*/|\\|[^\\|]*\\|)")416 }417 masked := executeRegexp.ReplaceAllStringFunc(str, func(src string) string {418 return ":execute(" + strings.Repeat(" ", len(src)-10) + ")"419 })
82 unmodified lines
502 toggleSort = true503 default:504 if isExecuteAction(act) {505 keymap[key] = actExecute506 if pair[1][7] == '=' {507 execmap[key] = pair[1][8:]508 } else {506 execmap[key] = pair[1][8 : len(act)-1]509 execmap[key] = pair[1][8 : len(act)-1]510 }511 } else {512 errorExit("unknown action: " + act)513 }514 }
6 unmodified lines
521 return false522 }523 b := str[7]524 e := str[len(str)-1]521 if b == e && strings.ContainsAny(string(b), "~!@#$%^&*:;/|") ||522 b == '(' && e == ')' || b == '[' && e == ']' {525 if b == '=' || b == '(' && e == ')' || b == '[' && e == ']' ||526 b == e && strings.ContainsAny(string(b), "~!@#$%^&*:;/|") {527 return true528 }529 return false530}
221 unmodified lines