Unlike awk, which is even defined in POSIX, perl is not pre-installed
on all *nix systems. This awk command is functionally equivalent to
the original perl command.
- extract logical parts to separate variables (e.g. $opts)
- put options in $opts in similar order
- move +/-m into $opts (at the end, so they won't be overridden)
- split pipelines into multiple lines
- remove "echo" that seems to be redundant
All this should help with readability and also result in cleaner diffs
when changes are made.
This makes it easier to make customizations, for example instead of
bind -x '"\C-o\C-i": FZF_CTRL_T_COMMAND="fasd -Rl" FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --tiebreak=index " fzf-file-widget'
it's enough to just
bind -x '"\C-o\C-i": FZF_CTRL_T_COMMAND="fasd -Rl" fzf-file-widget --tiebreak=index'
I forgot to add the "not _fzf" check into __fzf_orig_completion, so
invoking it twice would rewrite the _fzf_orig_completion_xxx variables
and then cause an endless loop when completion is requested.
Fixes: ef2c29d5d4 ("[bash-completion] Optimize __fzf_orig_completion_filter")
Commit d4ad4a25 slowed loading of completion.bash significantly (on my
laptop from 10 ms to 30 ms), then 54891d11 improved that (to 20 ms) but
it still stands out as the heavy part of my .bashrc.
Rewriting __fzf_orig_completion_filter to pure bash without forking to
sed/awk brings this back under 10 ms.
before:
$ HISTFILE=/tmp/bashhist hyperfine 'bash --rcfile shell/completion.bash -i'
Benchmark #1: bash --rcfile shell/completion.bash -i
Time (mean ± σ): 21.2 ms ± 0.3 ms [User: 24.9 ms, System: 6.4 ms]
Range (min … max): 20.7 ms … 23.3 ms 132 runs
after:
$ HISTFILE=/tmp/bashhist hyperfine 'bash --rcfile shell/completion.bash -i'
Benchmark #1: bash --rcfile shell/completion.bash -i
Time (mean ± σ): 9.6 ms ± 0.3 ms [User: 8.0 ms, System: 2.2 ms]
Range (min … max): 9.3 ms … 11.4 ms 298 runs
Fixes: d4ad4a25db ("[bash-completion] Fix default alias/variable completion")
Fixes: 54891d11e0 ("[bash-completion] Minor optimization")
This prevents mistakes like the one fixed by the previous commit, and
also speeds bash startup a tiny bit:
before:
$ HISTFILE=/tmp/bashhist hyperfine 'bash --rcfile shell/completion.bash -i'
Benchmark #1: bash --rcfile shell/completion.bash -i
Time (mean ± σ): 22.4 ms ± 0.6 ms [User: 28.7 ms, System: 7.8 ms]
Range (min … max): 21.7 ms … 25.2 ms 123 runs
after:
$ HISTFILE=/tmp/bashhist hyperfine 'bash --rcfile shell/completion.bash -i'
Benchmark #1: bash --rcfile shell/completion.bash -i
Time (mean ± σ): 21.2 ms ± 0.3 ms [User: 24.9 ms, System: 6.4 ms]
Range (min … max): 20.7 ms … 23.3 ms 132 runs
This doesn't look right:
$ complete | grep ' _.$'
complete _a
complete _v
The __fzf_orig_completion_filter invocation in _fzf_setup_completion
needs the /-F/ filter, just like all the other invocations.
Fixes: d4ad4a25db ("[bash-completion] Fix default alias/variable completion")
Ideally, we could only use `print -sr` to update the command history.
However, the "cd" command by ALT-C is added to the history only after we
finalize the current command by pressing an additional enter key.
i.e. The cd command from ALT-C is not visible when you hit Up arrow. But
it appears once you hit enter key.
So when the current buffer is empty, we use `zle accept-line` so that
the command history is immediately updated.
Close#2200
Requires latest tmux built from source (e.g. brew install tmux --HEAD)
Examples:
# 50%/50% width and height on the center of the screen
fzf-tmux -p
# 80%/80%
fzf-tmux -p80%
# 80%/40%
fzf-tmux -p80%,40%
# Separate -w and -h
fzf-tmux -w80% -h40%
# 80%/40% at position (0, 0)
fzf-tmux -w80% -h40% -x0 -y0
You can configure key bindings and fuzzy completion to open in tmux
popup window like so:
FZF_TMUX_OPTS='-p 80%'
At the top of each zsh file options are set to their
standard values (those marked with <Z> in `man zshoptions`)
and `aliases` option is disabled.
At the bottom of the file the original options are restored.
Fix#1938
To make it easier to write more complex fzf options. Although this
does not break backward compatibility, users are encouraged to update
their code accordingly.
# Before
_fzf_complete "FZF_ARG1 FZF_ARG2..." "$@" < <(
# Print candidates
)
# After
_fzf_complete FZF_ARG1 FZF_ARG2... -- "$@" < <(
# Print candidates
)
Restore the original line when search is aborted. Add --query
"$READLINE_LINE" and fall back to the current behavior pre Bash 4.
Co-authored-by: Junegunn Choi <junegunn.c@gmail.com>
Close#1370
Parses the history list, converts it to a NUL-delimited list of possibly
multiline entries. Adds the fzf --read0 option. Works with and without
histexpand enabled.
Co-authored-by: Junegunn Choi <junegunn.c@gmail.com>
Make C-t more consistent pre and post Bash 4. It already kills the
command line separately before and after the insertion point. Add
set-mark and exchange-point-and-mark to restore the insertion point
after yanking back and apply the same behavior to M-c.
* CTRL-T should put extra space after pasted items
Co-authored-by: Junegunn Choi <junegunn.c@gmail.com>
This commit fixes a bug where lines that declare multiple hostnames get
omitted from completion entirely if one of the hostnames matches *. For
example:
Host foo.com bar.dev baz.*
The zsh version of the cd widget sets the variable `dir` to the path of
the target directory before invoking `cd`. This causes zsh to treat the
target directory as a named directory, which has the effect of zsh
substituting '%~' with '~dir' instead of the proper path when it
performs prompt expansion.
This commit will cause the widget to unset `dir` before redrawing the
prompt to fix this issue.
Details of zsh prompt expansion can be found in:
http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html
While we can attach `_fzf_path_completion` or `_fzf_dir_completion` to
any command using the standard bash complete command, the functionality
of the existing completion function is lost.
Use _fzf_setup_completion if you want to extend the existing function
with fuzzy completion instead of completely replacing it.
e.g. _fzf_setup_completion path kubectl
Perl was used to remove the trailing newline character, but fzf already
has --print0 to use null character as terminators, and fish read -z is
expecting null character as terminators. There is no reason to depend on
perl if --print0 is passed to fzf invocation.
This change is not required if you use the install script to generate
~/.fzf.bash or ~/.fzf.zsh which already has the proper guard statement.
Close#1474
* Correctly exclude SSH config options with Host
SSH config files have 14 options containing 'Host'.
Previously The zsh and bash completion scripts would include lines
containing these options when doing command-line completion of SSH hosts
with `ssh **`.
This commit fixes that problem by only including lines with 'host '.
* Don't autocomplete SSH hostnames using ?
SSH config files support ? as well as * for wildcards in Host lines.
This commit excludes lines containing ? for zsh/bash command line
completeion using `ssh **`
$FISH_VERSION is dropped in 2.7, but every version has $version
- https://github.com/fish-shell/fish-shell/issues/4414
- fb8ae04f80
Comment from @faho in #1316:
Unfortunately, $FISH_VERSION was only ever a thing from fish 2.0 to fish 2.7.1.
All fish versions from the very beginning though used a variable called simply "$version" to store their version, so that is the one that should be used.
* [bash/zsh] Fix missing fuzzy completions
`cat foo**<TAB>` did not display the file `foobar` if there was a directory
named `foo`.
Fixes#1301
* [zsh] Evaluate completion prefix
cat $HOME**
cat ~username**
cat ~username/foo**
Close#1216
1. Append a single space so that step 3 won't fail
2. CTRL-E to move to the end of the line
3. CTRL-U to delete the whole line before the cursor
4. CTRL-Y to paste the deleted line
5. ESC+Y to rotate the kill ring and bring back the previous yank before step 3
6. CTRL-U to delete the whole line again
7. Paste `__fzf_history__`
8. ESC+CTRL-E to expand the command substitution
9. ESC+R to redraw the line
10. ESC+^ to expand the history entry (!NUMBER)
After _completion_loader is called, instead of loading the entire
completion.bash file, just restore the fzf completion for the current
command. `_fzf_orig_completion_$cmd` is only set if _completion_loader
actually changed the completion options to avoid infinite loop.
Close#1170
When `ps` is aliased for something uncommon, like `alias ps=grc ps` which colorizes ps output, the output of `ps` can be unexpected and/or undesired.
This change makes ps to be always executed as command, even if it's aliased.
Handles records like "[20.20.7.168]:9722 ssh-rsa ..."
This is a standard format for servers running on custom port according to http://man.openbsd.org/sshd.8#SSH_KNOWN_HOSTS_FILE_FORMAT
A hostname or address may optionally be enclosed within ‘[’ and ‘]’
brackets then followed by ‘:’ and a non-standard port number.
* Don't do shell quoting for weird chars
This would prevent tabs from being escaped as `$'\t'` (definitely not what I would want to see as initial value in the search).
* Do different escape.
This also modifies <C-t> behaviour.
The longest file path in the input is used as root directory for `find`
command. The remainder of the input is passed to fzf's --query as a
initial search parameters.
If "." is given as the argument to begin <C-t> completion, the leading
"." is not correctly removed. In general, if user selects a fzf
completion, the current token should be "consumed".