This is a rewrite of __fzf_parse_commandline function, that fixes the
following issues, when CTRL-T/ALT-C is used and current command line
token contains:
- Escaped newlines (\n): This never worked correctly, but after 282884a,
the string would split, and the script would enter an infinite loop
while trying to set $dir.
- Escaped bell (\a, \cg), backspace (\b), form feed (\v, \cl), carriage
return (\r), vertical tab (\v, \ck): walker-root would not set
correctly for existing directories containing any of those characters.
- Regular expression special characters (^, +, ? etc): $dir would not be
be stripped from $fzf_query if it contained any of those characters.
The lowest supported fish version is v3.1b. For optimal operation, the
function uses more recent commands when supported by the running
version. Specifically, for versions equal or newer than:
- v3.2.0: Sets variables using PCRE2 capture groups of `string match
--regex` when needing to preserve any trailing newlines and
simultaneously omit the extra newline that is appended by `string
collect -N`.
- v3.5.0: Uses the builtin path command for path normalization, dirname
extraction and existing directories check.
- v4.0.0: Uses the --tokens-expanded option of commandline, for
expansion and dealing with unbalanced quotes and incomplete escape
sequences. It also uses the regex style of string-escape, to prepare
variable contents for regex operations. This is not used in older
versions, because they don't escape newlines.
CTRL-T/ALT-C now works correctly when selecting files or directories
that contain newlines in their names. When external commands defined by
$FZF_CTRL_T_COMMAND/$FZF_ALT_C_COMMAND are used (for example the fd
command with -0 switch), the --read0 option must also be set through
$FZF_CTRL_T_OPTS/$FZF_ALT_C_OPTS.
Enable inserting multiple history commands. To disable, set `--no-multi`
through `$FZF_CTRL_R_OPTS`.
Also, remove the usage of `become` action, to avoid leaving behind
temporary files.
Co-authored-by: Junegunn Choi <junegunn.c@gmail.com>
- Remove check/set of FZF_TMUX_HEIGHT variable. It is already done by
__fzf_defaults.
- Remove unnecessary begin/end block.
- Simplify result variable check.
- Set the command line using a single call to commandline.
- Remove check/set of FZF_TMUX_HEIGHT variable. It is already done by
__fzf_defaults.
- Remove unnecessary begin/end block.
- Pass all fzf options (except query) through FZF_DEFAULT_OPTS variable.
- Remove check/set of FZF_TMUX_HEIGHT variable. It is already done by
__fzf_defaults.
- Remove unnecessary begin/end block.
- Simplify result variable check.
- Insert file names using a single call to commandline.
Append all arguments after the first one, so that functions don't have
to pass all appending options as a single string. Also, output
everything as a single string (an array of one item).
More natural processing of the query taken from command line, by
unquoting/unescaping the token. Unescaped open quotes are removed.
Because of how `string unescape` works, if both single and double quotes
are present, with the outer quotes open, only the outer quotes are
removed.
Examples:
`'foo bar'`, `"foo bar"`, `foo\ bar` becomes `foo bar`
`"foobar`, `'foobar`, `foo"bar`, `foo'bar` becomes `foobar`
`'"foo"'`, `'"foo"` becomes `"foo"`
`"'foo'"`, `"'foo'` becomes `'foo'`
`"'foo` becomes `'foo`
`'"foo` becomes `"foo`
Using CTRL-T or ALT-C when the current command line token contained a
directory with special characters, the script would fail to detect it.
For exampe, an existing directory named `it\'s\ a\ test`, instead of
using it as walker-root, it would use it as the query.
Instead of exporting a local `$SHELL` containing the location of fish in
`$PATH` when global `$SHELL` is not fish, always set `--with-shell` with
the actual binary path of fish that the function is running from.
* [fish] Drop support for versions older than 3.0b1
* [fish] Use `set` instead of `read` for `$result`
This effectively makes CTRL-R non-blocking (the previous attempt was
unsuccessful).
* [fish] Allow FZF_CTRL_R_OPTS to set multi-select
Fix the removal of the leading dot character from the query, when
<Ctrl-T> was pressed and the current command line token started with a
dot. It was also removed when <Alt-C> was pressed and the directory
didn't exist under the current path.
- Use `string collect` instead of cat to get the contents of
$FZF_DEFAULT_OPTS_FILE. Also, check if the file is readable first.
- Use `string split` instead of cut to set $FISH_MAJOR, $FISH_MINOR.
- Use `string replace` instead of perl to strip leading tabs.
- Enable using unescaped quotes for exact-match, exact-boundary-match.
- Enable suffix-exact-match.
- Enable inverse-exact-match, inverse-prefix/suffix-exact-match.
- Allow searching for double quotes and backslashes.
- Combine multiple consecutive slashes into one.
- Workaround for test command bug, allowing $dir or $commandline be a
single `!`.