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
Provenance
- Commit
6d647e1- Tree
828aa4d- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
d2af3ff
6 files changed+63 added−26 removed
modified:man/man1/fzf-tmux.1+1 added-1 removed
19 unmodified lines20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN22 THE 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"25 26 .SH NAME27 fzf-tmux - open fzf in tmux split pane28 40 unmodified linesmodified:man/man1/fzf.1+34 added-24 removed
19 unmodified lines20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN22 THE 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"25 26 .SH NAME27 fzf - a command-line fuzzy finder28 731 unmodified lines760 \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\fR47 unmodified lines816 817 Multiple actions can be chained using \fB+\fR separator.818 819 e.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'\fR822 821-.SS COMMAND EXECUTION823+.SS ACTION ARGUMENT824 823-With \fBexecute(...)\fR action, you can execute arbitrary commands without824-leaving fzf. For example, you can turn fzf into a simple file browser by825-binding \fBenter\fR key to \fBless\fR command like follows.825+An action denoted with \fB(...)\fR suffix takes an argument.826 827- \fBfzf --bind "enter:execute(less {})"\fR827+e.g.828+ \fBfzf --bind 'ctrl-a:change-prompt(NewPrompt> )'\fR829+ \fBfzf --bind 'ctrl-v:preview(cat {})' --preview-window hidden\fR830 829-You can use the same placeholder expressions as in \fB--preview\fR.830-831-If the command contains parentheses, fzf may fail to parse the expression. In831+If the argument contains parentheses, fzf may fail to parse the expression. In832 that case, you can use any of the following alternative notations to avoid833 parse errors.834 835- \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 .RS850 The last one is the special form that frees you from parse errors as it does851 not expect the closing character. The catch is that it should be the last one852 in the comma-separated list of key-action pairs.853 .RE854 855+.SS COMMAND EXECUTION856+857+With \fBexecute(...)\fR action, you can execute arbitrary commands without858+leaving fzf. For example, you can turn fzf into a simple file browser by859+binding \fBenter\fR key to \fBless\fR command like follows.860+861+ \fBfzf --bind "enter:execute(less {})"\fR862+863+You can use the same placeholder expressions as in \fB--preview\fR.864+865 fzf switches to the alternate screen when executing a command. However, if the866 command is expected to complete quickly, and you are not interested in its867 output, you might want to use \fBexecute-silent\fR instead, which silently868 executes the command without the switching. Note that fzf will not be59 unmodified linesmodified:src/options.go+7 added-1 removed
733 unmodified lines734 func 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 }740 741 func parseKeymap(keymap map[int][]action, str string) {742 masked := executeRegexp.ReplaceAllStringFunc(str, func(src string) string {5 unmodified lines748 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 lines923 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 lines964 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 actExecuteSilent600 unmodified linesmodified:src/terminal.go+4 added
212 unmodified lines213 actBackwardDeleteChar214 actBackwardDeleteCharEOF215 actBackwardWord216 actCancel217+ actChangePrompt218 actClearScreen219 actClearQuery220 actClearSelection221 actDeleteChar2001 unmodified lines2223 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 linesmodified:test/test_go.rb+9 added
1821 unmodified lines1822 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 end1826+1827+ 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+ end1835 end1836 1837 module TestShell1838 def setup478 unmodified linesmodified:CHANGELOG.md+8 added
1 CHANGELOG2 =========3 4+0.24.45+------6+- Added `change-prompt` action7+ ```sh8+ fzf --prompt 'foo> ' --bind $'a:change-prompt:\x1b[31mbar> '9+ ```10+- Bug fixes and improvements11+12 0.24.313 ------14 - Added `--padding` option15 ```sh1014 unmodified lines