mirror of
https://github.com/junegunn/fzf.git
synced 2025-09-01 04:43:49 -07:00
Change alternative notation for execute action (#265)
e.g. fzf --bind "ctrl-m:execute:COMMAND..." --bind ctrl-j:accept
This commit is contained in:
@@ -410,9 +410,9 @@ var executeRegexp *regexp.Regexp
|
|||||||
func parseKeymap(keymap map[int]actionType, execmap map[int]string, toggleSort bool, str string) (map[int]actionType, map[int]string, bool) {
|
func parseKeymap(keymap map[int]actionType, execmap map[int]string, toggleSort bool, str string) (map[int]actionType, map[int]string, bool) {
|
||||||
if executeRegexp == nil {
|
if executeRegexp == nil {
|
||||||
// Backreferences are not supported.
|
// Backreferences are not supported.
|
||||||
// "~!@#$%^&*:;/|".each_char.map { |c| Regexp.escape(c) }.map { |c| "#{c}[^#{c}]*#{c}" }.join('|')
|
// "~!@#$%^&*;/|".each_char.map { |c| Regexp.escape(c) }.map { |c| "#{c}[^#{c}]*#{c}" }.join('|')
|
||||||
executeRegexp = regexp.MustCompile(
|
executeRegexp = regexp.MustCompile(
|
||||||
"(?s):execute=.*|:execute(\\([^)]*\\)|\\[[^\\]]*\\]|~[^~]*~|![^!]*!|@[^@]*@|\\#[^\\#]*\\#|\\$[^\\$]*\\$|%[^%]*%|\\^[^\\^]*\\^|&[^&]*&|\\*[^\\*]*\\*|:[^:]*:|;[^;]*;|/[^/]*/|\\|[^\\|]*\\|)")
|
"(?s):execute:.*|:execute(\\([^)]*\\)|\\[[^\\]]*\\]|~[^~]*~|![^!]*!|@[^@]*@|\\#[^\\#]*\\#|\\$[^\\$]*\\$|%[^%]*%|\\^[^\\^]*\\^|&[^&]*&|\\*[^\\*]*\\*|;[^;]*;|/[^/]*/|\\|[^\\|]*\\|)")
|
||||||
}
|
}
|
||||||
masked := executeRegexp.ReplaceAllStringFunc(str, func(src string) string {
|
masked := executeRegexp.ReplaceAllStringFunc(str, func(src string) string {
|
||||||
return ":execute(" + strings.Repeat(" ", len(src)-10) + ")"
|
return ":execute(" + strings.Repeat(" ", len(src)-10) + ")"
|
||||||
@@ -503,7 +503,7 @@ func parseKeymap(keymap map[int]actionType, execmap map[int]string, toggleSort b
|
|||||||
default:
|
default:
|
||||||
if isExecuteAction(act) {
|
if isExecuteAction(act) {
|
||||||
keymap[key] = actExecute
|
keymap[key] = actExecute
|
||||||
if pair[1][7] == '=' {
|
if pair[1][7] == ':' {
|
||||||
execmap[key] = pair[1][8:]
|
execmap[key] = pair[1][8:]
|
||||||
} else {
|
} else {
|
||||||
execmap[key] = pair[1][8 : len(act)-1]
|
execmap[key] = pair[1][8 : len(act)-1]
|
||||||
@@ -522,8 +522,8 @@ func isExecuteAction(str string) bool {
|
|||||||
}
|
}
|
||||||
b := str[7]
|
b := str[7]
|
||||||
e := str[len(str)-1]
|
e := str[len(str)-1]
|
||||||
if b == '=' || b == '(' && e == ')' || b == '[' && e == ']' ||
|
if b == ':' || b == '(' && e == ')' || b == '[' && e == ']' ||
|
||||||
b == e && strings.ContainsAny(string(b), "~!@#$%^&*:;/|") {
|
b == e && strings.ContainsAny(string(b), "~!@#$%^&*;/|") {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
@@ -162,9 +162,9 @@ func TestBind(t *testing.T) {
|
|||||||
keymap, execmap, toggleSort :=
|
keymap, execmap, toggleSort :=
|
||||||
parseKeymap(keymap, execmap, false,
|
parseKeymap(keymap, execmap, false,
|
||||||
"ctrl-a:kill-line,ctrl-b:toggle-sort,c:page-up,alt-z:page-down,"+
|
"ctrl-a:kill-line,ctrl-b:toggle-sort,c:page-up,alt-z:page-down,"+
|
||||||
"f1:execute(ls {}),f2:execute/echo {}, {}, {}/,f3:execute[echo '({})'],f4:execute:less {}:,"+
|
"f1:execute(ls {}),f2:execute/echo {}, {}, {}/,f3:execute[echo '({})'],f4:execute;less {};,"+
|
||||||
"alt-a:execute@echo (,),[,],/,:,;,%,{}@,alt-b:execute;echo (,),[,],/,:,@,%,{};"+
|
"alt-a:execute@echo (,),[,],/,:,;,%,{}@,alt-b:execute;echo (,),[,],/,:,@,%,{};"+
|
||||||
",X:execute=\nfoobar,Y:execute(baz)")
|
",X:execute:\nfoobar,Y:execute(baz)")
|
||||||
if !toggleSort {
|
if !toggleSort {
|
||||||
t.Errorf("toggleSort not set")
|
t.Errorf("toggleSort not set")
|
||||||
}
|
}
|
||||||
@@ -184,7 +184,7 @@ func TestBind(t *testing.T) {
|
|||||||
checkString("echo (,),[,],/,:,@,%,{}", execmap[curses.AltB])
|
checkString("echo (,),[,],/,:,@,%,{}", execmap[curses.AltB])
|
||||||
checkString("\nfoobar,Y:execute(baz)", execmap[curses.AltZ+'X'])
|
checkString("\nfoobar,Y:execute(baz)", execmap[curses.AltZ+'X'])
|
||||||
|
|
||||||
for idx, char := range []rune{'~', '!', '@', '#', '$', '%', '^', '&', '*', '|', ':', ';', '/'} {
|
for idx, char := range []rune{'~', '!', '@', '#', '$', '%', '^', '&', '*', '|', ';', '/'} {
|
||||||
keymap, execmap, toggleSort =
|
keymap, execmap, toggleSort =
|
||||||
parseKeymap(keymap, execmap, false, fmt.Sprintf("%d:execute%cfoobar%c", idx%10, char, char))
|
parseKeymap(keymap, execmap, false, fmt.Sprintf("%d:execute%cfoobar%c", idx%10, char, char))
|
||||||
checkString("foobar", execmap[curses.AltZ+int([]rune(fmt.Sprintf("%d", idx%10))[0])])
|
checkString("foobar", execmap[curses.AltZ+int([]rune(fmt.Sprintf("%d", idx%10))[0])])
|
||||||
|
@@ -596,7 +596,7 @@ class TestGoFZF < TestBase
|
|||||||
|
|
||||||
def test_execute
|
def test_execute
|
||||||
output = '/tmp/fzf-test-execute'
|
output = '/tmp/fzf-test-execute'
|
||||||
opts = %[--bind \\"alt-a:execute(echo '[{}]' >> #{output}),alt-b:execute[echo '({}), ({})' >> #{output}],C:execute:echo '({}), [{}], @{}@' >> #{output}:\\"]
|
opts = %[--bind \\"alt-a:execute(echo '[{}]' >> #{output}),alt-b:execute[echo '({}), ({})' >> #{output}],C:execute:echo '({}), [{}], @{}@' >> #{output}\\"]
|
||||||
tmux.send_keys "seq 100 | #{fzf opts}", :Enter
|
tmux.send_keys "seq 100 | #{fzf opts}", :Enter
|
||||||
tmux.until { |lines| lines[-2].include? '100/100' }
|
tmux.until { |lines| lines[-2].include? '100/100' }
|
||||||
tmux.send_keys :Escape, :a, :Escape, :a
|
tmux.send_keys :Escape, :a, :Escape, :a
|
||||||
|
Reference in New Issue
Block a user