Skip to content
Myr

Change alternative notation for execute action (#265)

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

e.g. fzf --bind "ctrl-m:execute:COMMAND..." --bind ctrl-j:accept

authored by Junegunn Choi · committed by Junegunn Choi · parent 794ad57 · Browse files · 3 files+9 added−9 removed
This commit

State

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

Diff stats

3 files+9 added−9 removed

  • tests:+1 added−1 removed
  • other:+8 added−8 removed

3 files+9 added−9 removed

modified:src/options_test.go+3 added-3 removed
160 unmodified lines
161 check(actBeginningOfLine, keymap[curses.CtrlA])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 {}:,"+165 "f1:execute(ls {}),f2:execute/echo {}, {}, {}/,f3:execute[echo '({})'],f4:execute;less {};,"+166 "alt-a:execute@echo (,),[,],/,:,;,%,{}@,alt-b:execute;echo (,),[,],/,:,@,%,{};"+167 ",X:execute=\nfoobar,Y:execute(baz)")167 ",X:execute:\nfoobar,Y:execute(baz)")168 if !toggleSort {169 t.Errorf("toggleSort not set")170 }171 check(actKillLine, keymap[curses.CtrlA])
11 unmodified lines
183 checkString("echo (,),[,],/,:,;,%,{}", execmap[curses.AltA])184 checkString("echo (,),[,],/,:,@,%,{}", execmap[curses.AltB])185 checkString("\nfoobar,Y:execute(baz)", execmap[curses.AltZ+'X'])186187 for idx, char := range []rune{'~', '!', '@', '#', '$', '%', '^', '&', '*', '|', ':', ';', '/'} {187 for idx, char := range []rune{'~', '!', '@', '#', '$', '%', '^', '&', '*', '|', ';', '/'} {188 keymap, execmap, toggleSort =189 parseKeymap(keymap, execmap, false, fmt.Sprintf("%d:execute%cfoobar%c", idx%10, char, char))190 checkString("foobar", execmap[curses.AltZ+int([]rune(fmt.Sprintf("%d", idx%10))[0])])191 }
53 unmodified lines
modified:src/options.go+5 added-5 removed
408 unmodified lines
409410func parseKeymap(keymap map[int]actionType, execmap map[int]string, toggleSort bool, str string) (map[int]actionType, map[int]string, bool) {411 if executeRegexp == nil {412 // Backreferences are not supported.413 // "~!@#$%^&*:;/|".each_char.map { |c| Regexp.escape(c) }.map { |c| "#{c}[^#{c}]*#{c}" }.join('|')413 // "~!@#$%^&*;/|".each_char.map { |c| Regexp.escape(c) }.map { |c| "#{c}[^#{c}]*#{c}" }.join('|')414 executeRegexp = regexp.MustCompile(415 "(?s):execute=.*|:execute(\\([^)]*\\)|\\[[^\\]]*\\]|~[^~]*~|![^!]*!|@[^@]*@|\\#[^\\#]*\\#|\\$[^\\$]*\\$|%[^%]*%|\\^[^\\^]*\\^|&[^&]*&|\\*[^\\*]*\\*|:[^:]*:|;[^;]*;|/[^/]*/|\\|[^\\|]*\\|)")415 "(?s):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] == '=' {506 if pair[1][7] == ':' {507 execmap[key] = pair[1][8:]508 } else {509 execmap[key] = pair[1][8 : len(act)-1]510 }
10 unmodified lines
521 return false522 }523 b := str[7]524 e := str[len(str)-1]525 if b == '=' || b == '(' && e == ')' || b == '[' && e == ']' ||526 b == e && strings.ContainsAny(string(b), "~!@#$%^&*:;/|") {525 if b == ':' || b == '(' && e == ')' || b == '[' && e == ']' ||526 b == e && strings.ContainsAny(string(b), "~!@#$%^&*;/|") {527 return true528 }529 return false530}
221 unmodified lines
modified:test/test_go.rb+1 added-1 removed
594 unmodified lines
595 end596597 def test_execute598 output = '/tmp/fzf-test-execute'599 opts = %[--bind \\"alt-a:execute(echo '[{}]' >> #{output}),alt-b:execute[echo '({}), ({})' >> #{output}],C:execute:echo '({}), [{}], @{}@' >> #{output}:\\"]599 opts = %[--bind \\"alt-a:execute(echo '[{}]' >> #{output}),alt-b:execute[echo '({}), ({})' >> #{output}],C:execute:echo '({}), [{}], @{}@' >> #{output}\\"]600 tmux.send_keys "seq 100 | #{fzf opts}", :Enter601 tmux.until { |lines| lines[-2].include? '100/100' }602 tmux.send_keys :Escape, :a, :Escape, :a603 tmux.send_keys :Up
227 unmodified lines