This commit causes all simple commands that are not built-ins or functions to be
invoked via `command` in order to protect them from alias substitution or from
accidentally taking functions of the same name.
It was decided to not “protect” `fzf` and `fzf-tmux` for now.
Maybe a better solution should be implemented for that in the future.
Signed-off-by: Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>
* [bash] return instead of not executing an if-block, when non-interactive
This should keep the code more readable, be less error prone (accidentally doing
something outside the if-block and aligns the code with what’s already done for
zsh.
`0` is returned, because it shall not be considered an error when the script is
(accidentally) sourced from a non-interactive shell.
If executed as a script (rather than sourced), the results are not specified by
POSIX but depend on the shell, with bash giving an error in that case.
Signed-off-by: Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>
* [shell] exit immediately when called from non-interactive shell
The shell execution environment shouldn’t be modified at all, when called from a
non-interactive shell.
It shall be noted that the current check may become error prone for bash, namely
in case there should ever be a differentiation between `i` and `I` in the
special variable `-` and bash’s `nocasematch`-shell-option be used.
Signed-off-by: Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>
`find`’s `-path`-option is described to use shell patterns (i.e. POSIX’ pattern
matching notation).
In that, `.` is not a special character, thus escaping it shouldn’t be
necessary.
Signed-off-by: Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>
While awk is POSIX, perl isn't pre-installed on all *nix flavors.
This commit eliminates the mandatory dependency on perl by using awk
when perl is not available.
Related: #3295, #3309, #3310.
Test suite passed:
* `make error` all test sections 'PASS'
* `make docker-test` 215 runs, 1884 assertions, 0 failures, 0 errors, 0 skips.
Manually tested in the following environments:
* Linux amd64 with bash 3.2, 4.4, 5.2; gawk -P, one true awk, mawk, busybox awk.
* macOS Catalina, bash 3.2, macOS awk 20070501.
**Performance comparison:**
Mawk turned out the fastest, then perl.
One true awk's implementation should be the closest to macOS awk.
Test data: 230 KB history, 15102 entries, including multi-line and duplicates.
Linux, bash 4.4. Times in milliseconds.
| Command | Mean | Min | Max | Relative |
| :--- | ---: | ---: | ---: | -------: |
| `mawk 1.3.4` | 22.9 | 22.3 | 25.6 | **1.00** |
| `perl 5.26.1` | 34.3 | 33.6 | 35.1 | 1.49 |
| `one true awk 20221215` | 41.9 | 40.6 | 46.3 | 1.83 |
| `gawk 5.1.0` | 46.1 | 44.4 | 50.3 | 2.01 |
| `busybox awk 1.27.0` | 64.8 | 63.2 | 70.0 | 2.82 |
**Other Notes**
A bug affects bash, which fails restoring a saved multi-line history entry as a single entry. Bug fixed in version 5.0.[^1]
While developing this PR I discovered two unsubmitted issues affecting the current perl script. The output stream ends with `$'\n\0000'` instead of `$'\0000'`. Because of this, the script does not deduplicate a duplicated entry located at the end of the history list; therefore fzf displays two identical (not necessarily adjacent) entries. A minor point about the first issue is that the top fzf entry ends with a dangling line feed symbol, which is visible in the terminal.
[^1]: ec8113b986/CHANGES (L1511)
To enable: `shopt -s cmdhist lithist; HISTTIMEFORMAT='%F %T '`.
- 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'
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%'
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>
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)
CTRL-R binding used to start with --no-sort to list the matched commands
in chronological order. However, it has been a constant source of
confusion. Let's enable it by default from now on. The sorted result
shouldn't be too confusing as we use --tiebreak=index.
Faster startup. Use internal bash globbing instead of external grep binary (adapter from Gentoo's `/etc/bash/bashrc` TERM checking). Insignificant on Linux, but on Cygwin this cuts startup time by 40 ms on my Core i7 laptop.