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.