We were previously aborting the main event loop before calling fish_exit
in the event of a SIGHUP. This patch causes the SIGHUP to be stored in a
separate state variable from a regular "must exit" condition so the
associated event can be fired before we terminate the loop.
All streams are redirected before the event is called to prevent a
SIGTTIN/SIGTTOU due to the user script reading/writing from a disposed
tty.
Closes#7014
This error only happens on recent versions of gcc, see previous
commit e6bb7fc973 for more info.
Instead of using `ignore_result()` here, I've added a `system_assert`
function/macro that mimics the behavior of all the other `system()`
calls in the file.
Previously fish weak-linked wcsdup, wcsncasecmp, and wcscasecmp.
This enabled fish to be used on 10.6. However the minimum Mac version
is now 10.9, where these symbols are available.
This reworks the "a=" detection to be simpler.
If we detect a variable assignment that produces an error,
simply consume it.
We also take the opportunity to not highlight it as an error,
and add some tests.
Original commit is 1ca05d32d3.
Typing that command in an interactive prompt would make the highlighter thread
eat up CPU and memory. Probably not the right fix; I think the token should
already have been consumed when the error is detected, then there is no need
to consume it when unwinding.
When selectiong a large completion entry in the pager, it would clobber the
prompt. To reproduce, first run this command
complete -c : -xa '(
# completion entries that, when applied to the commandline
# need one, two, or three lines respectively
echo 1
echo 2(string repeat -n (math $COLUMNS - 5) x)
echo 3(string repeat -n $COLUMNS x)
printf %s\n n(seq $LINES)
)'
then type ": " and hit Tab repeatedly. When cycling through completion
entries, observe that fish always tries to render the pager with the same
size, even though the number of lines occupied by the command line buffer
changes due to soft wrapping.
Fix this by rendering the pager after the command line has been rendered, so
we know how many lines we have left.
This switches fish_indent from parsing with parse_tree
to the new ast.
This is the most difficult transition because the new ast retains less
lexical information than the old parse tree. The strategy is:
1. Use parse_util_compute_indents to compute indenting for each token.
2. Compute the "gap text" between the text of significant tokens. This
contains whitespace, comments, etc.
3. "Fix up" the gap text while leaving the significant tokens alone.
This switches parse_util_compute_indents from parsing with parse_tree to
the new ast.
It also reworks the parse_util_compute_indents tests, because
parse_util_compute_indents will be the backing for fish_indent.
This is the first commit of a series intended to replace the existing
"parse tree" machinery. It adds a new abstract syntax tree and uses a more
normal recursive descent parser.
Initially there are no users of the new ast. The following commits will
replace parse_tree -> ast for all usages.
Prior to this commit, fish used NUL ('\0') to disable control
functions (for example, the function that generates SIGTSTP).
However NUL may in fact be bindable and is on macOS via
control-space.
Use instead _POSIX_VDISABLE if defined and not -1.
This was always awkward as fish script, and had problems with
interrupting the autoloading.
Note that we still leave the old function intact to facilitate easier
upgrading for now.
Fixes#7145.
Page-Down seems to deactivate history search, so trying to undo
would leave the command line in an inconsistent state.
Fixes#7162 which was introduced in
12a9cb29 Fix assertion failure on page up / page down
It is used exclusively as vector at the moment since we only ever append
at the end. Making it a deque would be useful when allowing to edit the
search string and subsequently resume the search at an arbitrary position
in the history.
When editing a multiline command line and pressing "up" with the cursor at the
first line, fish attempts a hsitory search. If the search fails, don't move
the cursor to the end of the multiline command because this can be annoying
when the user does not actually want to perform a history search.
After profiling bottlenecks in job execution, the calls to `tcgetpgrp`
were identified to take a good amount of the execution time. Collecting
metrics on which branches were taken revealed that in all "normal"
cases, there is no benefit to calling `tcgetpgrp` before calling
`tcsetpgrp` as it can instead be called only in the error case to
determine what sort of error handling behavior should be applied.
This makes the best-case scenario of a single syscall much more likely
than in the previous situation.
Profiling revealed string comparison in variable lookups to be a
significant hotspot. This change causes `make test` to complete ~4.5%
faster per `hyperfine`.
This was originally comparing two pointers for equality but after the
refactor to wcstring it ended up comparing a const string pointer to the
_contents_ of the wcstring.
I really kinda hate how insistent clang-format is to have line
breaks *IFF THE LINE IS TOO LONG*.
Like... lemme just add a break if it looks better, will you?
But it is the style at this time, so we shall tie an onion to our
belt.
This makes binding \cz possible.
We already ignore the SIGTSTP signal it sends, so until now it was useless.
(also STOP and START for good measure, but since we disable flow
control in fish anyway these already shouldn't have been sent)
Fixes#7152
Profiling shows that parsing color names still took much longer than it
should.
wcscasecmp is so slow that using it directly causes `try_parse_special`
to consume up to 3% of all of fish's cpu time due to extremely
inefficient invariant case lookups for wide characters (tested: Fedora
Server 32 w/ glibc 2.31 with -O2).
These control the disambiguation between ctrl-j and ctrl-m.
This can cause the enter key to send a ctrl-m, which programs might be
unprepared for.
(This is why you need to do `stty sane<ctrl-j>`)
The `reserve` here can, under certain circumstances, reserve more than
strictly needed.
The simple workaround is to just never look at more than we feed in.
(really what we'd *want* is to look at the length of the *color
names*, but those are wchar, so length lookup is crappy NULL-lookup)
This was profiled to be a hotspot during startup. The usage of
wcscasecmp in a loop caused repeated transforms to lowercase, which is
incredibly slow for wide characters.
This makes it possible to expand the signals checked by the type. I can't merge
the sigttin fixes for #7060 yet because they introduce new breakage, but this
will make merging any future fix easier.
In #7133, neovim crashing caused "OPOST" to be turned off, which
caused a weird staircase display.
So we just force a set of settings that don't seem useful to change to
avoid breaking the terminal with something like that.
Fixes#7133.
A broken/missing optspec or `--` is a bug in the script using
argparse, an unknown option or invalid argument is a bug in using that script.
So in the former case print a stacktrace, because the person writing
the `argparse` call is at fault, in the latter don't.
Fixes#6703.
Prior to this change, the posix_spawn code paths used a fair amount of
manual management around its allocated structures (attrs and file actions).
Encapsulate this into a new class that manages memory management and error
handling.
Finish the transition to termsize.h. Remove the scary termsize bits
from common.cpp, which can throw off events at arbitrary calls and are
dangerously reentrant. Migrate everyone to the new termsize.h.
fish's handling of terminal sizes is currently rather twisted. The
essential problem is that the terminal size may change at any point from a
SIGWINCH, and common_get_{width,height} may modify it and post variable
change events from arbitrary locations.
Tighten up the semantics. Assign responsibility for managing the tty size
to a new class, `termsize_container_t`. Rationalize locking and reentrancy.
Explicitly nail down the relationship between $COLUMNS/$LINES and the tty
size. The new semantics are: whatever changed most recently takes
precendence.
Prior to this fix, fish would attempt to resize the terminal via
TIOCSWINSZ, which was added as part of #3740. In practice this probably
never did anything useful since generally only the tty master can use
this. Remove the support and note it in the changelog.
Prior to this fix, s_reset would attempt to reset the screen, optionally
using the PROMPT_SP hack to go to the next line. This in turn required
passing in the screen width even if it wasn't needed (because we were
not going to abandon the line). Factor this into two functions:
- s_reset_line which does not apply the hack
- s_reset_abandoning_line which applies the PROMPT_SP hack
common_get_width will "lazily" decide the screen width, which means
changing the environment variable stack. This is a surprising thing
to do from the middle of screen rendering.
Switch to passing in widths explicitly to screen.
The removed comparison ({begin,end,field} == INT_MIN) always evaluates
to false, because at this point in evaluation, `begin <= 0` has already
been evaluated to be false. Since INT_MIN <= 0, the second conditional
in all three of the affected cases is always false. The C++ standard
seems to guarantee left-to-right evaluation of logical operators, but
not necessarily bitwise operators.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
We are 1-indexed, and so it's weird to have `test` count its arguments
from 0.
For `test 1 =` this changes the error from
test: Missing argument at index 2
1 =
^
to
test: Missing argument at index 3
1 =
^
test loves error messages like
test: Missing argument at index 2
without explaining where that "index 2" is.
So now, we print the arguments below that, with a caret pointing to
the place where the error occured.
For example:
> test 1 = 2 and echo true or echo false
test: Expected a combining operator like '-a' at index 3
1 = 2 and echo true or echo false
^
(Type 'help test' for related documentation)
Fixes#6030.
There's a terrible number of fishscripts that start with
set path (dirname (status filename))
And that's really just a bit boring.
So let's let it be
set path (status dirname)
This change is necessary to fix dynamic titles for the Alacritty
terminal. We do this by simply adding the (wchar_t *) literal
L"alacritty" to the end of the title_terms array. This variable is
ultimately used in the subsequent function
does_term_support_setting_title (dtsst) for the purposes of whitelisting
certain terminals.
If an Alacritty user does not have the terminfo for alacritty present in
their terminfo database, Alacritty sets the TERM variable to
"xterm-256color", but if the terminfo for Alacritty is present, TERM is
instead set to "alacritty".
Prior to this change, none of the "fallback patterns" in the dtsst
function (which is used to ultimately decide whether or not a given
value of the TERM environment variable is supported) would apply to a
value of "alacritty". Ordinarily, the dtsst function would return true
if nothing matches, but one of the final checks involves testing the
result of ttyname_r to see if it contains the substring "tty", which
causes dtsst to return false. In the case where TERM="alacritty", this
is erroneous, because Alacritty does, indeed, support changing its title
and will also silently ignore attempts to change the title if that
behavior has been disabled by the user [1].
The changed file, src/env_dispatch.cpp, was reformatted by clang-format
in accordance with the documented procedures for contributors.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
[1]: 1dacc99183/alacritty_terminal/src/term/mod.rs (L896-L900)
When fish exits, it tries to restore the foreground process group.
However this may actually steal control of the fg process group
from another process. Fix this by clearing the SIGTTOU handler so
that tcsetpgrp() will fail.
Credit to @mqudsi for awesome debugging.
Fixes#7060
Prior to this change, if the user's prompt was wider than the terminal, we
would reduce it to just `> `. With this change, attempt to truncate the
prompt.
For each line of the prompt, calculate its width. If the width exceeds
COLUMNS, prepend ellipsis to that line, and start removing characters
until it fits. Escape sequences are skipped.
Fixes#904
Initially I wanted to pick a different name to avoid confusion with
process groups, but really job trees *are* process groups. So name them
to reflect that fact.
Also rename "placeholder" to "internal" which is clearer.
Prior to this, jobs all had a pgid, and fish has to work hard to ensure
that pgids were inherited properly for nested jobs. But now the job tree
is the source of truth and there is only one location for the pgid.
job_lineage was used to track "where jobs came from" but the job tree idea is
a better abstraction. It groups jobs together similar to how a process group
would in other shells. Begin to remove the notion of lineage.
Job trees come in two flavors: “placeholders” for jobs which are only fish
functions, and non-placeholders which need to track a pgid. This adds
logic to allow a job to decide if its parent's job tree is appropriate,
and allocating a new tree if not.
job_tree represents the data that should be shared between a job and any
jobs that may be spawned by functions or eval run as part of that job. It
reifies shared data that before was handled piecemeal.
Currently fish aborts execution mid-pipeline if a file redirection
failed, which can leave the shell in a broken state (job abandoned after
giving control of the terminal to an already-executed job in the
pipeline).
This patch replaces a failed fd with a closed fd and continues execution
if the affected process wasn't the first in the pipeline.
While this is a hack to address the regression behind fish-shell/#7038
introduced in d62576c, it can also be argued that this behavior is
actually more correct... right?
Closes#7038.
* Add an "_" builtin to call into gettext
We already have gettext in C++ (if available), so it seems weird to
fork off a command to start it from script.
This is only for fish's own translations. There's no way to call into
other catalogs, it just translates all arguments separately.
This is faster by a factor of ~1000, which allows us to call
translations much more, especially from scripts.
E.g. making fish_greeting global by default would hurt cost-wise,
given that my fish starts up in 8ms and just calling the current `_`
function takes 2ms, and that would have two calls.
Incidentally, this also makes us rely on a weirdly defined function
less, so it:
Fixes#6804.
* docs: Add `_` docs
Let's see if that filename works out.
* Reword _ docs
Variables like $status and $history showed up in all scopes, including
universal, when querying with `set -q` or `set -S`.
This makes it so they all only count as set in global scope, because
we already only allow assignment to electric variables in global scope.
Fixes#7032
This patch fixes an underflow in the jump family of readline commands
when called via `commandline -f` outside of a bind context such as
`commandline -f backward-jump`. To reproduce, run that command at a
prompt and the shell will crash with a buffer underlow.
This happens because the jump commands have non-zero arity, requiring a
character event to be pushed on the function args stack. Pushing the
character event is handled in `function_push_args`, called by
`inputter_t::mapping_execute`, which checks the arity of the function
and enqueues the required number of charcter events. However,
`builtin_commandline` calls `reader_queue_ch`, which in turn calls
`inputter_t::queue_ch`, which immediately enqueues the readline event
without calling `function_push_args`, so the character event is never
pushed on the arg stack.
This patch adds a check in inputter_t::queue_ch which checks if the
character event is a readline event, and if so, calls
`function_push_args`.
When sending SIGCONT to a stopped job, this behaves now
a bit more like a job that was continued by the bg builtin;
bg uses job_t::continue_job which seems overkill here.
This just produced a spurious "Unknown signal" error on NetBSD and OpenBSD, and
the number picked was arbitrary. So let's just use the maximum that
appears to work everywhere.
(I will hate this if I test it elsewhere and need to reduce it to 62)
(This is a squashed commit, I did indeed hate it when I moved from
NetBSD to OpenBSD)
The default implementation will not print any output in that case, but this provides users with additional flexibility when it comes to customising the shell's behaviour.
This allows users to customise the behaviour of the shell by redefining the function. This is similar to how fish_title or fish_greeting behave, where the default implementation can be easily overridden.
The function receives as arguments the job id, command line, signal name and signal description.
This allows tools like `stty` to set the terminal modes and fish will
honor them, for external commands.
The modes for fish are kept as they are.
Until now, the only change fish would do to the external modes is to
disable flow control *every time*, this changes it to only disabling
it on startup.
After that we don't apply *any* changes to the external modes (no
checks or validation or...), because we've never done that (other than
flow control), and it's not been a problem.
Fixes#2315.
If we output text and end up in the last column, the sticky right edge
will cause a clr_eos to erase the last character. Ensure this doesn't
happen by not issuing clr_eos in that case.
Fixes#6951
If a readline command is bound to a key sequence which also sends a
signal, then fish will set the cancel flag in addition to handling the
command. But this cancel flag is then persistent. Ensure it gets cleared
after each command.
Fixes#6937
The manual page for statfs(2) only lists SMB_SUPER_MAGIC and
CIFS_MAGIC_NUMBER, but it turns out there's a third type of CIFS/SMB
mount, represented by SMB2_MAGIC_NUMBER.
Haunting me from #6609.
Use inline initializers rather than the constructor, and adopt some
maybe_t.
Also move post_buff_1 and post_buff_2 to local variables instead of
member variables.
Commit 5fccfd83ec, with the fix for #6806,
switched eval to buffer its output (like other builtins do). But this
prevents using eval with commands that wants to see the tty, especially
fzf. So only buffer the output if the output is piped to the next process.
This will solve #6955 (which needs to go into a point release).
builtin_eval needs to know whether to set up bufferfills to capture its
output and/or errput; it should do this specifically if the output and
errput is piped (and not, say, directed to a file). In preparation for
this change, add bools to io_streams_t which track whether stdout and
stderr are specifically piped.
Prior to this fix, builtin_eval would direct output to the io_chain of the
job. The problem is with pipes: `builtin_eval` might happily attempt to
write unlimited output to the write end of a pipe, but the corresponding
reading process has not yet been launched. This results in deadlock.
The fix is to buffer all the output from `builtin_eval`. This is not fun
but the best that can be done until we have real concurrent processes.
Fixes#6806
Give string expansion an (optional) parent pgroup. This is threaded all
the way into eval(). This ensures that in a mixed pipeline like:
cmd | begin ; something (cmd2) ; end
that cmd2 and cmd have the same pgroup.
Add a test to ensure that command substitutions inherit pgroups
properly.
Fixes#6624
Changes it from
```
$fish_color_user: not set in local scope
$fish_color_user: set in global scope, unexported, with 1 elements
$fish_color_user[1]: length=3 value=|080|
$fish_color_user: set in universal scope, unexported, with 1 elements
$fish_color_user[1]: length=7 value=|brgreen|
```
(with the trailing empty line - not just a newline)
to
```
$fish_color_user: set in global scope, unexported, with 1 elements
$fish_color_user[1]: |080|
$fish_color_user: set in universal scope, unexported, with 1 elements
$fish_color_user[1]: |brgreen|
```
* Fire fish_postexec event after tokenization error
This is a fix for issue #6816 "shell integration with tokenization error"
* Pass command-line to fish_postexec on tokenization error
* Rename and move event for tokenization error