Skip to content
Myr

Add change-prompt action

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

Close #2270

authored by Junegunn Choi · committed by Junegunn Choi · parent d2af3ff · Browse files · 6 files+63 added−26 removed
This commit

State

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

Diff stats

6 files+63 added−26 removed

  • tests:+9 added−0 removed
  • other:+54 added−26 removed

6 files+63 added−26 removed

modified:man/man1/fzf-tmux.1+1 added-1 removed
19 unmodified lines
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN22THE SOFTWARE.23..24.TH fzf-tmux 1 "Nov 2020" "fzf 0.24.3" "fzf-tmux - open fzf in tmux split pane"24.TH fzf-tmux 1 "Dec 2020" "fzf 0.24.3" "fzf-tmux - open fzf in tmux split pane"2526.SH NAME27fzf-tmux - open fzf in tmux split pane28
40 unmodified lines
modified:man/man1/fzf.1+34 added-24 removed
19 unmodified lines
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN22THE SOFTWARE.23..24.TH fzf 1 "Nov 2020" "fzf 0.24.4" "fzf - a command-line fuzzy finder"24.TH fzf 1 "Dec 2020" "fzf 0.24.4" "fzf - a command-line fuzzy finder"2526.SH NAME27fzf - a command-line fuzzy finder28
731 unmodified lines
760 \fBbackward-kill-word\fR \fIalt-bs\fR761 \fBbackward-word\fR \fIalt-b shift-left\fR762 \fBbeginning-of-line\fR \fIctrl-a home\fR763 \fBcancel\fR (clear query string if not empty, abort fzf otherwise)764 \fBchange-prompt(...)\fR (change prompt to the given string)765 \fBclear-screen\fR \fIctrl-l\fR766 \fBclear-selection\fR (clear multi-selection)767 \fBclear-query\fR (clear query string)768 \fBdelete-char\fR \fIdel\fR
47 unmodified lines
816817Multiple actions can be chained using \fB+\fR separator.818819e.g.819 \fBfzf --bind 'ctrl-a:select-all+accept'\fR820 \fBfzf --multi --bind 'ctrl-a:select-all+accept'\fR821 \fBfzf --multi --bind 'ctrl-a:select-all' --bind 'ctrl-a:+accept'\fR822821.SS COMMAND EXECUTION823.SS ACTION ARGUMENT824823With \fBexecute(...)\fR action, you can execute arbitrary commands without824leaving fzf. For example, you can turn fzf into a simple file browser by825binding \fBenter\fR key to \fBless\fR command like follows.825An action denoted with \fB(...)\fR suffix takes an argument.826827 \fBfzf --bind "enter:execute(less {})"\fR827e.g.828 \fBfzf --bind 'ctrl-a:change-prompt(NewPrompt> )'\fR829 \fBfzf --bind 'ctrl-v:preview(cat {})' --preview-window hidden\fR830829You can use the same placeholder expressions as in \fB--preview\fR.830831If the command contains parentheses, fzf may fail to parse the expression. In831If the argument contains parentheses, fzf may fail to parse the expression. In832that case, you can use any of the following alternative notations to avoid833parse errors.834835 \fBexecute[...]\fR836 \fBexecute~...~\fR837 \fBexecute!...!\fR838 \fBexecute@...@\fR839 \fBexecute#...#\fR840 \fBexecute$...$\fR841 \fBexecute%...%\fR842 \fBexecute^...^\fR843 \fBexecute&...&\fR844 \fBexecute*...*\fR845 \fBexecute;...;\fR846 \fBexecute/.../\fR847 \fBexecute|...|\fR848 \fBexecute:...\fR835 \fBaction-name[...]\fR836 \fBaction-name~...~\fR837 \fBaction-name!...!\fR838 \fBaction-name@...@\fR839 \fBaction-name#...#\fR840 \fBaction-name$...$\fR841 \fBaction-name%...%\fR842 \fBaction-name^...^\fR843 \fBaction-name&...&\fR844 \fBaction-name*...*\fR845 \fBaction-name;...;\fR846 \fBaction-name/.../\fR847 \fBaction-name|...|\fR848 \fBaction-name:...\fR849.RS850The last one is the special form that frees you from parse errors as it does851not expect the closing character. The catch is that it should be the last one852in the comma-separated list of key-action pairs.853.RE854855.SS COMMAND EXECUTION856857With \fBexecute(...)\fR action, you can execute arbitrary commands without858leaving fzf. For example, you can turn fzf into a simple file browser by859binding \fBenter\fR key to \fBless\fR command like follows.860861 \fBfzf --bind "enter:execute(less {})"\fR862863You can use the same placeholder expressions as in \fB--preview\fR.864865fzf switches to the alternate screen when executing a command. However, if the866command is expected to complete quickly, and you are not interested in its867output, you might want to use \fBexecute-silent\fR instead, which silently868executes the command without the switching. Note that fzf will not be
59 unmodified lines
modified:src/options.go+7 added-1 removed
733 unmodified lines
734func init() {735 // Backreferences are not supported.736 // "~!@#$%^&*;/|".each_char.map { |c| Regexp.escape(c) }.map { |c| "#{c}[^#{c}]*#{c}" }.join('|')737 executeRegexp = regexp.MustCompile(738 `(?si)[:+](execute(?:-multi|-silent)?|reload|preview):.+|[:+](execute(?:-multi|-silent)?|reload|preview)(\([^)]*\)|\[[^\]]*\]|~[^~]*~|![^!]*!|@[^@]*@|\#[^\#]*\#|\$[^\$]*\$|%[^%]*%|\^[^\^]*\^|&[^&]*&|\*[^\*]*\*|;[^;]*;|/[^/]*/|\|[^\|]*\|)`)738 `(?si)[:+](execute(?:-multi|-silent)?|reload|preview|change-prompt):.+|[:+](execute(?:-multi|-silent)?|reload|preview|change-prompt)(\([^)]*\)|\[[^\]]*\]|~[^~]*~|![^!]*!|@[^@]*@|\#[^\#]*\#|\$[^\$]*\$|%[^%]*%|\^[^\^]*\^|&[^&]*&|\*[^\*]*\*|;[^;]*;|/[^/]*/|\|[^\|]*\|)`)739}740741func parseKeymap(keymap map[int][]action, str string) {742 masked := executeRegexp.ReplaceAllStringFunc(str, func(src string) string {
5 unmodified lines
748 if strings.HasPrefix(src[1:], "reload") {749 prefix = symbol + "reload"750 } else if strings.HasPrefix(src[1:], "preview") {751 prefix = symbol + "preview"752 } else if strings.HasPrefix(src[1:], "change-prompt") {753 prefix = symbol + "change-prompt"754 } else if src[len(prefix)] == '-' {755 c := src[len(prefix)+1]756 if c == 's' || c == 'S' {757 prefix += "-silent"
165 unmodified lines
923 case actReload:924 offset = len("reload")925 case actPreview:926 offset = len("preview")927 case actChangePrompt:928 offset = len("change-prompt")929 case actExecuteSilent:930 offset = len("execute-silent")931 case actExecuteMulti:932 offset = len("execute-multi")
31 unmodified lines
964 case "reload":965 return actReload966 case "preview":967 return actPreview968 case "change-prompt":969 return actChangePrompt970 case "execute":971 return actExecute972 case "execute-silent":973 return actExecuteSilent
600 unmodified lines
modified:src/terminal.go+4 added
212 unmodified lines
213 actBackwardDeleteChar214 actBackwardDeleteCharEOF215 actBackwardWord216 actCancel217 actChangePrompt218 actClearScreen219 actClearQuery220 actClearSelection221 actDeleteChar
2001 unmodified lines
2223 t.cx--2224 }2225 case actPrintQuery:2226 req(reqPrintQuery)2227 case actChangePrompt:2228 t.prompt, t.promptLen = t.parsePrompt(a.a)2229 req(reqPrompt)2230 case actPreview:2231 togglePreview(true)2232 refreshPreview(a.a)2233 case actRefreshPreview:
392 unmodified lines
modified:test/test_go.rb+9 added
1821 unmodified lines
1822 tmux.send_keys %{seq 100 | #{FZF} --preview 'for i in $(seq 300); do (( i % 200 == 0 )) && printf "\\033[2J"; echo "[$i]"; sleep 0.001; done'}, :Enter1823 tmux.until { |lines| lines.item_count == 100 }1824 tmux.until { |lines| lines[1]&.include?('[200]') }1825 end18261827 def test_change_prompt1828 tmux.send_keys "#{FZF} --bind 'a:change-prompt(a> ),b:change-prompt:b> ' --query foo", :Enter1829 tmux.until { |lines| assert_equal '> foo', lines[-1] }1830 tmux.send_keys 'a'1831 tmux.until { |lines| assert_equal 'a> foo', lines[-1] }1832 tmux.send_keys 'b'1833 tmux.until { |lines| assert_equal 'c> foo', lines[-1] }1834 end1835end18361837module TestShell1838 def setup
478 unmodified lines
modified:CHANGELOG.md+8 added
1CHANGELOG2=========340.24.45------6- Added `change-prompt` action7 ```sh8 fzf --prompt 'foo> ' --bind $'a:change-prompt:\x1b[31mbar> '9 ```10- Bug fixes and improvements11120.24.313------14- Added `--padding` option15 ```sh
1014 unmodified lines