Commit Graph

3609 Commits

Author SHA1 Message Date
Fabian Homborg
a7df92e187 Fix crash with set_color --print-colors --background normal
Found in conjunction with #7805.
2021-03-09 13:46:08 +01:00
Fabian Homborg
4762d52e52 output: A background is set if it's not a special non-color
For reasons unclear to me, fish enables bold mode unconditionally if
the background is set.

However, this called a background "set" if it wasn't exactly the
"normal" color, whereas set_color --print-colors would set a color
of *none*.

We have three special non-color colors:

- "normal"
- "reset"
- "none"

All of these specify some form of absence of background color, so all
of them should be checked.

Fixes #7805
2021-03-09 13:25:00 +01:00
Ilya Grigoriev
762f3aa0ce
Rewrite the real file if history file is a symlink (#7754)
* Rewrite the real file if history file is a symlink

When the history file is a symbolic link, `fish` used to overwrite
the link with a real file whenever it saved history. This makes
it follow the symlink and overwrite the real file instead.

The same issue was fixed for the `fish_variables` file in 622f2868e
from https://github.com/fish-shell/fish-shell/pull/7728.
This makes `fish_history` behave in the same way. The implementation
is nearly identical.

Since the tests for the two issues are so similar, I combined them
together and slightly expanded the older test.

This also addresses https://github.com/fish-shell/fish-shell/issues/7553.

* Add user-facing error when history renaming fails

Currently, when history file renaming fails, no message is shown to the
user. This happens, for instance, if the history file is a symlink
pointing to another filesystem.

This copies code (with a bit of variation, after reviewer comments) from

589eb34571/src/env_universal_common.cpp (L486-L491)

into `history.cpp`, so that a message is shown to the user.

* fixup! Rewrite the real file if history file is a symlink
2021-03-08 17:46:17 +01:00
Fabian Homborg
dbb74f87ba Re-read terminal modes after config.fish
Before now, we would be getting the terminal modes before config.fish,
then running config.fish without any of the term "stealing" and modes
copying. This meant that changes made to the terminal modes in there
were simply lost.

So, what we do is simply set the modes before config and then copy
them after, once.

Note that this does *not* turn off flow control again - if you turn it
on in config.fish that should work.

Fixes #7783.
2021-03-07 11:23:59 +01:00
Fabian Homborg
371516382d Create job-exit caller events inside event handlers
f7e2e7d26b forbid any job exit events
from happening inside jobs that were themselves event handlers, but
that causes e.g.

```fish
function f --on-event fish_prompt
source (echo "echo hello world" | psub)
end
```

to not trigger psub's cleanup, so it leaves files in $TMPDIR behind.

This was hit by pyenv, because that still uses `source (thing |
psub)`.

Fixes #7792.
2021-03-07 10:00:52 +01:00
Fabian Homborg
25d85bdc64 path_get_path: Remove error on unknown errno
This seems like a good idea, but there isn't anything we or anyone
else can *do* in this case. All we ever do is pile on additional
errors on the ignore pile, we can't handle any of them differently.
The command isn't a thing, so we check the next path.

The impetus for this is Cygwin apparently returning a wonderfully
useless 0, and it's not even the first one to do so.

Fixes #7785
2021-03-06 08:12:27 +01:00
Mahmoud Al-Qudsi
11951a245f Optimize pruning of job/proc exit handlers
Pre-emptively delete the handler while we have possession of the lock
before calling the event itself. It's crude, but it works.
2021-03-05 22:40:06 -06:00
Mahmoud Al-Qudsi
e7398c0248 Prune job exit handlers after running
While pid values may be reused, it is logical to assume that fish event
handlers coded against a particular job or process id mean just the job
that is currently referred to be any given pid/pgrp rather than in
perpetuity.

This trims the list of registered event handlers nice and early, and as
a bonus avoids the issue described in #7721.

The cleanup song-and-dance is extremely ugly due to the repeated locking
and unlocking of the event handler list.

Closes #7221.
2021-03-05 22:32:57 -06:00
Fabian Homborg
6bc0064a2a demangled_backtrace: Cast a thing to const char* instead of char*
Apparently this is const char* on NetBSD, so it complains.

Since it should be harmless to allow this one to be const, just do
that.
2021-03-05 19:40:44 +01:00
Fabian Homborg
c96a07dc96 Revert "Prevent redirecting internal processes to file descriptors above 2"
FDs are inherited, and redirecting those is harmless, and forbidding
that is worse than allowing all.

Fixes #7769.

This reverts commit 11a373f121.
2021-03-03 22:26:33 +01:00
Fabian Homborg
791b42f065 Disable SIGIO notifier
It doesn't work on WSL, Solaris and Archlinux (and presumably that
means future versions of other linux distros).

In its current state I don't trust it enough to enable it anywhere by
default, especially since I'm not aware of an actual issue with the
named pipe (other than that the code is ugly).

Fixes #7774
2021-03-03 22:26:28 +01:00
Fabian Homborg
955c0003ca fd_monitor: Explicity include <thread>
Might fix issues with gcc 11.0.1.

See #7764.
2021-03-02 15:27:13 +01:00
Fabian Homborg
119b978cbc type: Add --quiet back
It's supposed to be *deprecated*, not removed. The documentation even
specifically calls it out.

Fixes #7766
2021-03-02 14:53:02 +01:00
Érico Rolim
d948b34420 Include <termios.h> instead of <sys/termios.h>.
Slipped by with ffa24eb361. Given
daf5ef1bbd, fish should be using
<termios.h> in all cases.
2021-03-02 12:05:07 +01:00
Fabian Homborg
abaa057e5c Replace our only dynamic_cast with old-school casting
dynamic_cast requires rtti to be enabled. Now, this isn't a big
problem, but since this is our only dynamic_cast in the entire
codebase, and it's not serving an important function, we can just
replace it.

See #7764
2021-03-02 09:44:23 +01:00
Fabian Homborg
6b6f8d2295 Avoid changing how custom fish_titles are called
This half-reverts commit a3cb1e2dcd,
avoiding the bit that passed arguments differently.

Note that this means the initial bug is kept in the hardcoded fallback title.

Fixes #7749.
2021-02-28 08:40:39 +01:00
Fabian Homborg
459ac2b566 Reset the readline loop state when setting the buffer
Fixes #7740.
2021-02-25 16:19:28 +01:00
Mahmoud Al-Qudsi
42d9f33e16 Use a platform whitelist for opting into the SIGIO notifier
My bet is that the Illumos, Cygwin, and WSL are not the only Unix-like
systems where the SIGIO notifier won't work, and since we have a good
enough and portable alternative that we can use be default on other
platforms where we don't specifically know it'll work, it doesn't make
sense not to go with that one instead.

Even if this patch is reverted at some point and we go back to
blacklisting platforms that *don't* support the SIGIO strategy, this is
almost certainly the right choice for inclusion in a minor release like
3.2.0.

See discussion in #6585.
2021-02-24 14:40:17 -06:00
Mahmoud Al-Qudsi
ffa24eb361 Fix build on Solaris (and hopefully OpenIndiana)
* memset/memzero needs cstring/string.h (again)
 * winsize_t requires an impl from <sys/termios.h>

With this patch, I was able to get fish master to build on Solaris 11.4
without any additional dependencies (after installing gcc 7, git, and
cmake). I think the ncurses dependency can be dropped from the
OpenIndiana package?
2021-02-23 11:02:55 -06:00
Mahmoud Al-Qudsi
d95e99f2d4 Fix missing memset/memzero on Illumos
Tested w/ GCC 9 under OpenIndiana 2020.
2021-02-22 20:58:42 -06:00
Mahmoud Al-Qudsi
17926a9197 Allow low-level tests to at least run to completion under Cygwin
They still don't pass due to path differences, but at least they run to
completion so we can tell just how broken everything is.
2021-02-22 16:27:45 -06:00
Mahmoud Al-Qudsi
d769582023 Ignore intentional redundant move under GCC
This bubbled up after Wredundant-move was added to the build script and
was observed under the CI environment running GCC 9.3.0.
2021-02-22 15:55:40 -06:00
Fabian Homborg
d0a8493844 Don't open pager with only one completion
Since smartcase, we could land in a situation where we offer one
option in the pager, which is awkward.

So detect this and just insert the option directly, we can add any
more smartness later.

Fixes #7738.
2021-02-22 22:51:52 +01:00
Mahmoud Al-Qudsi
1305a0899c Fix comparison warnings on UTF-16 platforms
Without true handling of UTF-16 surrogate pairs, all we can do is
properly detect the BMP range in UTF-16 environments and bail if the
input is in a non-BMP region.

There isn't much else we can do as it is incorrect to encode the
surrogate pairs themselves (fish doesn't know what to do with them and
they're illegal under either of UTF-8 or UTF-32).

(I'm not aware of fish being used in any UTF-16 platforms other than
Cygwin.)
2021-02-22 15:03:49 -06:00
Mahmoud Al-Qudsi
215df7eec6 Extend PCRE2 wchar_t interop support to 16-bit wchar_t impls
Previously, the interop glue for more friendly access to PCRE2's
fixed-size values was only used when char32_t/wchar_t were
interchangeable and PCRE2 was used with a global 32-bit unit width set;
this patch extends the same to char16_t when wchar_t is also 16-bits
(namely on Cygwin) to avoid compilation fpermissive warnings about casts
between types of potentially different sizes.

Reported in #6585.
2021-02-22 13:51:29 -06:00
Mahmoud Al-Qudsi
2cf5fd3d5d Avoid hard compilation errors on platforms w/out O_ASYNC
Those platforms should not be using the sigio notifier in the first
place, this just stops them from failing to be able to compile fish
altogether.

See #6585
2021-02-21 22:39:32 -06:00
ridiculousfish
11a373f121 Prevent redirecting internal processes to file descriptors above 2
The user may write for example:

    echo foo >&5

and fish would try to output to file descriptor 5, within the fish process
itself. This has unpredictable effects and isn't useful. Make this an
error.

Note that the reverse is "allowed" but ignored:

    echo foo 5>&1

this conceptually dup2s stdout to fd 5, but since no builtin writes to fd
5 we ignore it.
2021-02-20 16:16:45 -08:00
Ilya Grigoriev
622f2868e1 Fix set -U when fish_variables is a symlink
Previously, `set -U` would overwrite the symlink with a
regular file.

Fixes https://github.com/fish-shell/fish-shell/issues/7466
2021-02-20 14:24:11 -08:00
ridiculousfish
8648f52857 Use wcs2string when outputting the screen
The screen output code predates the ENCODE_DIRECT scheme, and
directly-encoded bytes were not being properly output. This manifested as
private-user characters being mangled when printed as part of fish_prompt.
Just use str2wcstring instead.

Fixes #7723
2021-02-17 15:38:46 -08:00
ridiculousfish
f1b6a5939d Introduce wcs2string_appending
wcs2string_appending is like wcs2string, but appends to a std::string
instead of creating a new one. This will be more efficient when a string
can be reused, or if we want to accumulate multiple wcstrings into a
single std::string.
2021-02-17 15:36:22 -08:00
ridiculousfish
fce485e6a8 Rename bufferCount_ to buffer_count_
fish uses snake case for naming.
2021-02-17 14:25:32 -08:00
Mahmoud Al-Qudsi
774488686c Correct handling of SGR mouse tracking events
They are of variable length, taking semicolon-separated ASCII characters
and not single chars/bytes as the parameters. Additionally, the global
maximum size for a CSI is 16 characters (NPAR), even though I believe
the maximum possible mouse-tracking CSI is 12 characters.
2021-02-17 15:45:35 -06:00
ridiculousfish
7e77dc8964 Add a test for round-tripping characters in the private use area
I wrote this test believing that fish had a bug, but actually fish is
behaving correctly here. Still the test is nice so I am checking it in.
2021-02-17 12:29:51 -08:00
ridiculousfish
c0b39aaeb7 Do not reset terminal color when donating term for running key bindings
fish maintains two tty modes: one for itself and one for external
commands. The external command mode is also used when executing
fish-script key bindings, which was added in 5f16a299a7 (note that
commit had the wrong issue, the correct issue is #2114).

Prior to this fix, when switching to external modes, we would also reset
the tty's foreground color. This bumped tty's timestamp, causing us to
believe that the tty had been modified, and then repainting the prompt. If
the prompt were multi-line, we would repaint the whole prompt starting
from its second line, leaving a trailing line above it.

It would be reasonable to save the tty timestamp after resetting the
color, but given that using external modes for keybindings is new, it's
better to instead not reset the color in this case. So migrate the color
resetting to only when we run external commands.

Fixes #7722
2021-02-17 11:10:51 -08:00
Mahmoud Al-Qudsi
75af89699a Patch fish_tests to work with changed const_strlen requirements 2021-02-17 12:55:21 -06:00
Mahmoud Al-Qudsi
70b06a899d Bypass recursion in case of single trailing nul in const_strlen()
The default case for string literals like `"foo"` is a single trailing
nul, and that's what we have almost everywhere. By checking the
second-to-last index for a non-nul byte, we can skip the recursive
invocation, thus speeding up compilation that teeny, tinsy bit faster.
2021-02-17 12:26:40 -06:00
Mahmoud Al-Qudsi
071b9b13cd Reverse const_strlen() recursion logic
Rather than making the run-time complexity of the algorithm 𝒪(n) where n
is the length of the string, make it 𝒪(k) where k is the number of
trailing nul bytes.

The second parameter `index` with a default non-value is in lieu of a
helper function that would have had a name like `count_trailing_nuls()`.
2021-02-17 12:26:40 -06:00
Fabian Homborg
313b70a0c2 math: Set LC_NUMERIC to C again
e94f86e6d2 removed it in favor of using
fish_wcstod, but this broke the *output* - math currently prints
numbers with "," and then can't read them.

So we partially revert it until we come up with something better.
Maybe set $LC_NUMERIC globally inside fish?
2021-02-17 09:07:40 +01:00
Johannes Altmanninger
c0af8dae20 fish_indent: fix extra indent of continuation lines inside blocks
fish_indent used to increment the indentation level whenever we saw an escaped
newline.  This broke because of recent changes to parse_util_compute_indents().
Since parse_util_compute_indents() function already indents continuations
there is not much to do for fish_indent - we can simply query the indentation
level of the newline.  Reshuffle the code since we need to pass the offset
of the newline. Maybe this can even be simplified further.

Fixes #7720
2021-02-16 18:39:03 +01:00
Johannes Altmanninger
444c05dfb1 Do not indent after escaped newline in comment
We do something similar in fish_indent.  This fixes the spurious indent
after comments in share/completions/emerge.fish.

See #7720
2021-02-16 18:39:03 +01:00
Fabian Homborg
00fabb4fe1 Enhance fallback keybindings a bit
Bind \cc like normal, since we now no longer use a function, and bind
some important control bindings like \cs and the ever-important emacs \cb/f/p/n.

What really kills the usability here is the up-line vs up-or-search.
2021-02-15 20:54:35 +01:00
Fabian Homborg
65a760528a Skip figuring out config with --no-execute
Cuts the time to check all our fish scripts in the
check-all-fish-files.fish test roughly in half, from 3.3s
to 1.8s.
2021-02-15 18:59:54 +01:00
Fabian Homborg
c83436d050 Don't overwrite IXON/IXOFF for startup modes
We actually restore those before exit, so this would force-disable
flow control whenever fish exits.
2021-02-15 17:30:50 +01:00
Fabian Homborg
1426d61bc9 Stop disabling VSTOP/VSTART
Without flow control enabled these won't be interpreted any way.
2021-02-15 17:30:50 +01:00
Fabian Homborg
2be720b6cc Set flow control settings also in the shell
Since, unlike e.g. OPOST, this can sometimes be useful, just copy
whatever flow control settings the terminal ends up with.

We still *default* flow control to off (because it's an awful default
and allows us to bind ctrl-s), but if the user decides to enable it so
be it.

Note that it's _possible_ flow control ends up enabled accidentally, I
doubt this happens much and it won't render the shell unusable (and
good terminals might even tell you you've stopped the app).

Fixes #7704
2021-02-15 17:30:50 +01:00
Fabian Homborg
c27fb9b802 source: Escape filenames in errors
Otherwise this would look weird if you had, say, a tab in there.

See #7716.

(note that this doesn't handle e.g. zero-width-joiners, because those
aren't currently escaped. we might want to add an escape mode for
unprintable characters, but for combining codepoints that's tricky!)
2021-02-15 17:08:26 +01:00
Mahmoud Al-Qudsi
ef5db47cf7 Make const_strlen return an unsigned value 2021-02-14 11:42:26 -06:00
Fabian Homborg
552c7bc40b Don't add a space if completion only added a single "/"
This added a space if only one character was added, e.g.

```fish
cd dev<TAB>
```

would complete to

```fish
cd dev/<SPACE>
```

which makes picking deeper directories awkward.

So just go back to the old behavior of doing it for any length.

This is a regression from e27d97b02e.

cc @krobelus
2021-02-14 13:50:43 +01:00
ridiculousfish
9a165b93fb handle_builtin_output to take io_chain by const reference
There was no reason for this to be a pointer or mutable.
2021-02-13 20:05:33 -08:00
ridiculousfish
ee15bc2a36 Add a variant of valid_var_name which accepts const wchar_t *
This avoids creating some unnecessary strings.
2021-02-13 18:49:43 -08:00