`exec` now exhibits the same behavior as `exit` and prompts the user to
confirm their intention to end the current process if there are
background jobs running. Running `exec` again immediately thereafter
will force the exec to go through.
Additionally, background jobs are reaped upon exec to prevent process
leaking (same as `exit`).
Fix#5133 changed builtins to acquire the terminal, but this regressed
caused fish to be stopped when running in background via `sudo fish`.
Fix this by only acquiring the terminal if the terminal was owned by the
builtin's pgroup.
Fixes#5147
- Add support for:
- Jumping to the character before a target.
- Repeating the previous jump (same direction, same precision).
- Repeating the previous jump in the reverse order.
- Enhance vi bindings.
When running a builtin, if we are an interactive shell and stdin is a tty,
then acquire ownership of the terminal via tcgetpgrp() before running the
builtin, and set it back after.
Fixes#4540
Factor the history search fields into a new class.
As a side effect, this shares the deduplication logic, so that token search
no longer returns duplicates.
Fixes#4795
This changes the behavior of builtin math to floating point by default.
If the result of a computation is an integer, then it will be printed as an
integer; otherwise it will be printed as a floating point decimal with up to
'scale' digits past the decimal point (default is 6, matching printf).
Trailing zeros are trimmed. Values are rounded following printf semantics.
Fixes#4478
This reverts commit e2a3dae58b.
This idea failed because ./share was not complete when bliding via cmake;
it misses critical files such as config.fish.
fish tries to be relocatable by looking for directories relative to its
executable. These directories are not found when running fish from
within a cmake build because the etc directory is not present. Stop requiring
this directory to be present since it's not critical for running fish.
Fixes#4825
Don't mmap history files on remote file systems
This merges some changes to history that may help to mitigate the crashes seen in #5088 . These SIGBUS crashes occur when reading a memory mapping whose underlying file was truncated. It's not clear why this should occur more often on NFS (or ever). However memory mapping over NFS is sketchy anyways so this is desirable regardless.
Migrate the mmap() logic into a new class history_file_contents_t which
will serve to encapsulate conditional logic if we choose to use read()
instead of mmap().
This adds a new string command split0, which splits on zero bytes.
split0 has superpowers because its output is not further split on
newlines when used in command substitutions.
separated_buffer_t encapsulates the logic around discarding (which
was previously duplicated between output_stream_t and io_buffer_t),
and will also encapsulate the logic around explicitly separated
output.
If just one of the range ends is negative, this now forces direction away from it.
I.e. if the beginning is negative, we go in reverse.
If the end is negative, we go forwards.
This fixes cases like
$var[2..-1]
if $var only has one element.
While supported by gcc and clang, \e is a gcc-specific extension and not
formally defined in the C or C++ standards.
See [0] for a list of valid escapes.
[0]: https://stackoverflow.com/a/10220539/17027
We've tried numerous approaches to mitigate the race condition between
`posix_spawn` and the `setpgid` call, but unfortunately due to the flags
we pass to `posix_spawn`, it (rarely? never?) results in `vfork()` being
used, which means it is never executed atomically. Since it is executed
out-of-band, we must manually call `setpgid` in case `posix_spawn`
hasn't gotten around to doing that yet, but in the event that it has, an
EACCES error can be returned.
Closes#4884. Closes#4715. See also #4778.
On systems where the terminfo for TERM does not contain a string for
attributes such as enter_underline_mode, etc. fish was crashing with a
fatal error message and a note to email the developers.
These are non-essential text attribute changes and should not trigger
such a failure.
[9/13] Building CXX object CMakeFiles/fishlib.dir/src/builtin_string.cpp.o
../src/builtin_string.cpp:1221:12: warning: mangled name of 'string_transform' will change in C++17 due to non-throwing exception specification in function signature [-Wc++17-compat-mangling]
static int string_transform(parser_t &parser, io_streams_t &streams, int argc, wchar_t **argv, decltype(std::towlower) func) {
^
1 warning generated.
Our completion machinery calls our `__fish_describe_command` function
to describe commands via apropos. Only it trusts the output a bit too
much, so it crashes when any line from that is shorter than the
original string.
Fix this by skipping any string that is shorter than the original,
since it can't be a match anyway.
Also stop doing wcslen so often - std::strings are nice!
Fixes#5014.
There really is no need to
- Timeout just because the _first_ character was a control character
- Timeout because of any control character other than escape
The reason to timeout because the '\e' sequence can appear by itself (signifying
pressing the escape key) and still make
sense - e.g. vi-mode has it bound to a rather important function!
But a \c can't appear by itself, so we can just block.
This allows binding sequences like \cx\ce and inputting them at a
leisurely pace rather than the frantic escape_timeout one.
It should also improve sequences that _include_ escape somewhere else.
E.g. something like a\eb ("a, then alt+b") should now time out for the "\eb" part,
allowing users to bind a\e ("a, then escape") to something else. Why you'd want to do
that, I have no idea. But it's more consistent, and that's nice!
For regex-mode, this should be enough to read NUL-delimited strings to act on, but not
quite patterns and replacements.
Glob-mode requires more work - it uses wcscmp internally, which is unsuitable.
Also the various styles have one function each with barely any
difference - mostly passing the corresponding STYLE argument.
Pack them into one function for escape and one for unescape to save
about 100 lines.
We're now actually handling wchar_t here, so comparing the 0x80 bit
would break for UTF-16, causing ASCII false-positives.
Also simplifies a bit, since we no longer need a second variable.
printf 'a\0b' | string length
used to print "1". Now it prints "3".
Note that this switches to using C++'s std::string::length, which
might give differing results.
The prompt is a fallback that is overridden via a function file
anyway.
Do that with the title as well, so we can use just builtins.
This removes error messages when $fish_function_path is borked.
Introduced by #4849 (add wait for processes by name)
../src/builtin_wait.cpp:23:14: warning: using the result of an assignment as a condition without parentheses [-Wparentheses]
while (j = jobs.next()) {
~~^~~~~~~~~~~~~
../src/builtin_wait.cpp:23:14: note: place parentheses around the assignment to silence this warning
while (j = jobs.next()) {
^
( )
../src/builtin_wait.cpp:23:14: note: use '==' to turn this assignment into an equality comparison
while (j = jobs.next()) {
^
==
1 warning generated.
Turns out the segfaults we've been getting in our tests are because we set $TERM to "dumb".
So we only clear the line if the terminal isn't dumb.
This reverts commit 745a88f2f6.
Fixes#2320.
One key use of process expansion, used in currently-shipped code, is for running a function on
current shell exit.
Restore the use of %self as a valid argument (and add `self`) and document this change.
(faho: Remove bare "self")
This enables users to opt in (or out) of specific features by setting
the fish_features environment variable.
For example `set -U fish_features stderr-nocaret` to opt into removing the
caret redirection.
This partially reverts 5b489ca30f, with
carets acting as redirections unless the stderr-nocaret flag is set.
This flag is off by default but may be enabled on the command line:
fish --features stderr-nocaret
This introduces a new command line option --features which can be used for
enabling or disabling features for a particular fish session.
Examples:
fish --features stderr-nocaret
fish --features 3.0,no-stderr-nocaret
fish --features all
Note that the feature set cannot be changed in an existing session.
This teaches the status command to work with features.
'status features' will show a table listing all known features and whether
they are currently on or off.
`status test-feature` will test an individual feature, setting the exit status to
0 if the feature is on, 1 if off, 2 if unknown.
This introduces a new type features_t that exposes feature flags. The intent
is to allow a deprecation/incremental adoption path. This is not a general
purpose configuration mechanism, but instead allows for compatibility during
the transition as features are added/removed.
Each feature has a user-presentable short name and a short description. Their
values are tracked in a struct features_t.
We start with one feature stderr_nocaret, but it's not hooked up yet.
This was done in share/config.fish, but leads to surprising results if
that isn't read - e.g. because someone just built fish in the git
directory to test it without installing.
It's also not something that is any more or less complicated.
For compatibility, keep it in config.fish as well for the time being.
complete.cpp strips the path from commands before parsing for
completions, meaning that when we called `path_get_path()` against
`cmd`, if `./cmd` were typed in at the command line but `cmd` does not
exist in the PATH, then the command would incorrectly be flagged as not
present and the completions would be skipped.
This is also faster when an absolute/relative path is used for a
command, as we now search with the original path which skips searching
PATH directories unnecessarily.
Found when debugging why completions for `./configure` wouldn't work.
This brings back expansion of `%n` where `n` is a job id, but not as a
general parser syntax. This makes `jobs -p %n` work, which can be used
as part of the job control command chain, i.e.
```
cat &
fg (jobs -p %1)
```
fg/bg/wait can either be wrapped in a function to call `jobs -p` for
`%n` arguments, or they can be updated to take `%n` arguments
themselves.
The order of this list does not need to be strictly maintained any
longer.
Benchmarked with `hyperfine` as follows, where `bench1` is the existing
approach of binary search and `bench2` is the new unordered_set code,
(executed under bash because fish would always return non-zero). The
benchmark code checks each argv to see if it is a builtin keyword (both
return the same result):
```
hyperfine './bench1 $(shuf /usr/share/dict/words)' './bench2 $(shuf /usr/share/dict/words)'
Benchmark #1: ./bench1 $(shuf /usr/share/dict/words)
Time (mean ± σ): 68.4 ms ± 3.0 ms [User: 28.8 ms, System: 38.9 ms]
Range (min … max): 60.4 ms … 75.4 ms
Benchmark #2: ./bench2 $(shuf /usr/share/dict/words)
Time (mean ± σ): 61.4 ms ± 2.3 ms [User: 23.1 ms, System: 39.8 ms]
Range (min … max): 58.1 ms … 67.1 ms
Summary
'./bench2 $(shuf /usr/share/dict/words)' ran
1.11x faster than './bench1 $(shuf /usr/share/dict/words)'
```
Prior to this fix, the fish universal variables file claimed that
changes to it would be overwritten. This no longer true and has not
been true for a long time. Remove that warning.
This switches the universal variables file from a machine-specific
name to the fixed '.config/fish/fish_universal_variables'. The old file
name is migrated if necessary.
Fixes#1912
This removes the caret as a shorthand for redirecting stderr.
Note that stderr may be redirected to a file via 2>/some/path...
and may be redirected with a pipe via 2>|.
Fixes#4394
The previous commit caused the tests to fail since env_remove() was
returning a blanket `!0` when a variable couldn't be unset because it
didn't exist in the first place. This caused the wrong message to be
emitted since the code clashed with a return code for `env_set()`.
Added `ENV_NOT_FOUND` to signify that the variable requested unset
didn't exist in the first place, but _not_ printing the error message
currently so as not to break existing behavior before checking if this
is something we want.
Variables set in if and while conditions are in the enclosing block, not
the if/while statement block. For example:
if set -l var (somecommand) ; end
echo $var
will now work as expected.
Fixes#4820. Fixes#1212.
Currently, there are two possibilities for holes in the background:
- When there are two candidates with the same meaning (a long and a
short option or two candidates with the same description)
- When a candidate does not have a description (meaning the color
won't continue after it)
This changes both so the background just goes on.
In addition, it avoids making the background multiple times.
Fixes#4866.
The official fish documentation makes no mention of how `string split`
treats empty tokens, e.g. splitting 'key1##key2' on '#' or (more
confusingly) splitting '/path' on '/'. With this commit, `string split`
now has an option to exclude zero-length substrings from the resulting
array with a new `--no-empty/-n`. The default behavior of preserving
empty entries is kept so as to avoid breakage.
The two unicode glyphs used to represent missing new lines and redacted
characters for secure entry are both not present in the glyph tables of
the default font under Windows (Consolas and Lucida Console), use an
alternative glyph instead.
The "return" symbol is replaced with a pilcrow (¶) and the "redacted
character" symbol is replaced with a bullet (•). Both of these are
well-defined in almost all fonts as they're very old symbols. This
change only takes place if -DWSL is supplied by the build toolchain.
Note: this means a Windows SSH client connecting to a fish remote
instance on a non-Windows machine will still use the (unavailable)
default glyphs instead.
The newly added `:` command is implemented as a function (to avoid
increasing complexity by making it a builtin), but it is saved to a path
that does not match its filename (since its name is somewhat of a
special character that might cause problems during installation).
Directly probing the `colon` function for autoload causes `:` to be
correctly loaded, so doing just that after function paths are loaded
upon startup.
This is a hack since the CPP code shouldn't really be aware of
individual functions, perhaps there is a better way of doing this.
Fixes an issue introduced in 4414d5c888
where functions loaded from custom directories are not detected as being
valid for purposes of determining whether or not completions should be
called.
Work around #4810 by retrieving localizations at runtime to avoid issues
possibly caused by inserting into the static unordered_map during static
initialization.
Closes#810.
Line continuations (i.e. escaped new lines) now make sense again. With
the smart pipe support (pipes continue on to next line) recently added,
this hack to have continuations ignore comments makes no sense.
This is valid code:
```fish
echo hello |
# comment here
tr -d 'l'
```
this isn't:
```fish
echo hello | \
# comment here
tr -d 'l'
```
Reverts @snnw's 318daaffb2Closes#2928. Closes#2929.
From the discussion in #3802, handling spaces within braces more
gracefully. Leading and trailing whitespace that isn't quoted or escaped
is stripped, whitespace in the middle is preserved. Any whitespace
encountered within expansion tokens is treated as a single space,
similar to how programming languages that don't hard break tokens/quotes
on line endings would.
The value is not electrified or tied and is read-only. It isn't cached
in the get_hostname_identifier() function as the ENV_GLOBAL $hostname
will cache it for its duration.
The behavior of `gethostname` in case of an insufficient buffer is
library and version dependent. Work around this by using a big enough
buffer then truncating the output to our desired max length.
The 0th index of the array was tested inside the loop instead of just
once outside it.
Also explain `input_mapping_is_match` control code behavior and
reasoning and simplify control flow.
Drops the % notation for process expansion. The existing notation was a
mess and expanded jobs, process ids, and process names via dark magic.
With this change, % is no longer a special character and can be used
unescaped with impunity.
The variables %self and %last, referring to fish's own pid and the pid
of the last backgrounded job respectively, have been replaced with $pid
and $last_pid. These are read-only variables, protected against being
redefined by the user.
Author's note: I would have personally preferred $fish_pid instead of
$pid but since we debated changing $version to $fish_version and then
reverted that change (with much acrimony), it makes no sense to break
with that precedent here. Additionally, $fish_last_pid is quite wordy.
Closes#4230. Closes#1202.
When number is infinite, not a number, larger than LONG_MAX or smaller
than LONG_MIN, print a corresponding error and return STATUS_CMD_ERROR.
This should fix the worst of the problems, by at least making them clear.
Fixes#4479.
Fixes#4768.
This allows prompts to react to $COLUMNS by e.g. omitting some parts.
We still fallback to a ">" prompt if that's still not short enough,
but now the user has a way of making a nicer prompt.
Fixes#904.
Fixes#4381.
If the head is not a valid, existent command, do not load and run custom
completion sources. This applies to both the autosuggestion provider and
manual user completions. File-based completions will still be offered.
Supersedes #4782 and #4783. Closes#4783. Closes#4782. Closes#2365.
This promotes "and" and "or" from a type of statement to "job
decorators," as a possible prefix on a job. The point is to rationalize
how they interact with && and ||.
In the new world 'and' and 'or' apply to a entire job conjunction, i.e.
they have "lower precedence." Example:
if [ $age -ge 0 ] && [ $age -le 18 ]
or [ $age -ge 75 ] && [ $age -le 100 ]
echo "Child or senior"
end
This should speed things up on slower PCs given that the vast majority
of shell commands are simple jobs consisting of a single command without
any pipelines, in which case there's no need for a keepalive process at
all. Applies to WSL only.
As a temporary workaround for the behavior described in
Microsoft/WSL#2997 wherein WSL does not correctly assign the spawned
child its own PID as its PGID, explicitly set the PGID for the newly
spawned process.
This now reports "TOO_MANY_ARGS" instead of no error (and triggering
an assertion).
We might want to add a new error type or report the missing operator
before, but this is okay for now.
This turns a bunch of ifs on their heads.
We often see this pattern in te:
```c
if (s->type != SOME_TYPE) {
// error handling
} else {
// normal code
}
```
Only, since we want to return the first error, we do
```c
if (s->type == SOME_TYPE) {
// normal code
} else if (s->type != TOK_ERROR) {
// Add a new error - if it already has type error
// this should already be handled.
}
```
One big issue is the comma operator, that means arity-1 functions can
take an arbitrary number of arguments. E.g.
```fish
math "sin(5,9)"
```
will return the value of sin for _9_, since this is read as "5 COMMA
9".
This enables some limited use of arguments for wrapping completions. The
simplest example is that complete gco -w 'git checkout' now works like
you would want: `gco <tab>` now invokes git's completions with the
`checkout` argument prepended.
Fixes#1976
Previously, in
ls ^a bcd
(with "^" as the cursor), kill-word would delete the "a" and then go
on, remove the space and the "bcd".
With this, it will only kill the "a".
Fixes#4747.
This is part of an effort to improve fish's Unicode handling. This commit
attempts to grapple with the fact that, certain characters (principally
emoji) were considered to have a wcwidth of 1 in Unicode 8, but a width of
2 in Unicode 9.
The system wcwidth() here cannot be trusted; terminal emulators do not
respect it. iTerm2 even allows this to be set in preferences.
This commit introduces a new function is_width_2_in_Uni9_but_1_in_Uni8() to
detect characters of version-ambiguous width. For these characters, it
returns a width guessed based on the value of TERM_PROGRAM and
TERM_VERSION, defaulting to 1. This value can be overridden by setting the
value of a new variable fish_emoji_width (presumably either to 1 or 2).
Fixes#4539, #2652.