Commit Graph

4941 Commits

Author SHA1 Message Date
Mahmoud Al-Qudsi
45285b3870 Refactor error handling in binary_semaphore_t 2024-01-28 12:43:53 -06:00
Bartłomiej Maryńczak
2ca102193c
Statically type binary_semaphore_t mode of operation (#10272)
* Cleanup binary_semaphore_t by removing `sem_ok_` checks

* Fix unused import on non-Linux platforms

---------

Co-authored-by: Mahmoud Al-Qudsi <mqudsi@neosmart.net>
2024-01-28 12:21:15 -06:00
Fabian Boehm
aa5649ca99 Add # as a path component char
Fixes #10271
2024-01-28 10:41:15 +01:00
PolyMeilex
05ac1b770c Use AsFd for maybe_lock_file 2024-01-27 20:42:13 +01:00
PolyMeilex
341fd7ca16 Revert to octal mode repr in autoload and io 2024-01-27 20:42:13 +01:00
PolyMeilex
6ef8125c96 Return OwnedFd from open_cloexec 2024-01-27 20:42:13 +01:00
PolyMeilex
2512849ece Use nix OFlag for open_cloexec 2024-01-27 20:42:13 +01:00
PolyMeilex
6915aeb44c Use nix mode for open_cloexec 2024-01-27 20:42:13 +01:00
PolyMeilex
23301e4895 Return Result from wopen_cloexec 2024-01-27 20:42:13 +01:00
Fabian Boehm
019a082d5d Remove unused import 2024-01-27 18:47:38 +01:00
Johannes Altmanninger
9a1226684e Fixup formatting 2024-01-27 18:08:02 +01:00
Johannes Altmanninger
b768b9d3f5 Use fuzzy subsequence completion for options names as well
Version 2.1.0 introduced subsequence matching for completions but as the
changelog entry mentions, "This feature [...] is not yet implemented for
options (like ``--foobar``)".  Add it. Seems like a strict improvement,
pretty much.
2024-01-27 17:57:48 +01:00
Johannes Altmanninger
033f64fde6 Fix indentation in bitflags macro 2024-01-27 17:57:48 +01:00
Johannes Altmanninger
623ad21b47 Remove code clone in completion insertion 2024-01-27 17:57:48 +01:00
Fabian Boehm
1e5a585875 builtins: Remove some uses of .unwrap()
.unwrap() is in effect an assert(). If it is applied mistakenly, the
program crashes and there isn't a good error.

I would like it to be used as a last resort. In these cases there are
nicer ways to do it that handle a missing result properly.
2024-01-27 16:06:36 +01:00
Johannes Altmanninger
368017905e builtin commandline: -x for expanded tokens, supplanting -o
Issue #10194 reports Cobra completions do

    set -l args (commandline -opc)
    eval $args[1] __complete $args[2..] (commandline -ct | string escape)

The intent behind "eval" is to expand variables and tildes in "$args".
Fair enough. Several of our own completions do the same, see the next commit.

The problem with "commandline -o" + "eval" is that the former already
removes quotes that are  relevant for "eval". This becomes a problem if $args
contains quoted () or {}, for example this command will wrongly execute a
command substituion:

    git --work-tree='(launch-missiles)' <TAB>

It is possible to escape the string the tokens before running eval, but
then there will be no expansion of variables etc.  The problem is that
"commandline -o" only unescapes tokens so they end up in a weird state
somewhere in-between what the user typed and the expanded version.

Remove the need for "eval" by introducing "commandline -x" which expands
things like variables and braces. This enables custom completion scripts to
be aware of shell variables without eval, see the added test for completions
to "make -C $var/some/dir ".

This means that essentially all third party scripts should migrate from
"commandline -o" to "commandline -x". For example

    set -l tokens
    if commandline -x >/dev/null 2>&1
        set tokens (commandline -xpc)
    else
        set tokens (commandline -opc)
    end

Since this is mainly used for completions, the expansion skips command
substitutions.  They are passed through as-is (instead of cancelling or
expanding to nothing) to make custom completion scripts work reasonably well
in the common case. Of course there are cases where we would want to expand
command substitutions here, so I'm not sure.
2024-01-27 09:28:06 +01:00
Johannes Altmanninger
1b9e5258b5 Fix regression when erasing word in search field
This fixes a crash introduced in the reader port.

The tmux tests are not great but at least easy to write.
2024-01-27 03:46:26 +01:00
Fabian Boehm
bfc17079be qmark-noglob: Set group back
These are the version the flag was *introduced*, so they should stay
the same over the lifetime of the flag.
2024-01-25 18:26:48 +01:00
Fabian Boehm
ac9c5ed1b2 Retry open_cloexec for signals other than SIGINT
Fixes #10250
2024-01-25 11:14:31 +01:00
Mahmoud Al-Qudsi
ea980c19db Make string_tests.rs deterministic regardless of qmark-noglob
Move all qmark tests to `scoped_test()` sections with explicitly set feature
flags. We already test the default qmark behavior in the functionality tests.
2024-01-24 22:42:02 -06:00
Mahmoud Al-Qudsi
34a5443cfd Disable ? as a glob by default
aka, enable the qmark-noglob feature by default.
2024-01-24 21:17:36 -06:00
Fabian Boehm
d74519081e fish_key_reader: Exit after "--version" 2024-01-22 17:18:11 +01:00
Mahmoud Al-Qudsi
977b97a236 Fix assertion failure in FZF keybindings
It seems the logic for calculating the cursor position was not ported correctly,
because the correct place to insert it is at the cursor_pos regardless of
range.start, going by the parameters submitted to the function and the expected
result.
2024-01-21 23:11:20 -06:00
ridiculousfish
ce19f82c19 Fix some clippy warnings 2024-01-21 19:12:33 -08:00
ridiculousfish
9a0728eed6 Stop using num_traits in common.rs
This was a rather silly usage only for estimating string capacity in a rarely
used function. We can do without it.
2024-01-21 18:19:40 -08:00
ridiculousfish
1a42bdf182 Stop using num_traits in builtin return
This can be simplified using the builtin abs() function.
2024-01-21 18:19:40 -08:00
ridiculousfish
66ebd88c44 Stop using num_traits in printf
This wasn't needed at all.
2024-01-21 18:19:40 -08:00
ridiculousfish
26abb97198 Clean up builtin status
This is a cleanup with no user-visible changes. In particular we stop using
num_derive and num_traits.
2024-01-21 18:19:40 -08:00
ridiculousfish
3ce6a5fdd1 Make sets_bind_mode in input an Option<WString>
Previously this used an empty string to mean a sentinel; use an option instead.

Fixes a TODO.
2024-01-21 18:19:40 -08:00
ridiculousfish
b4b5cff3d8 Move input tests into their own module in the tests dir 2024-01-21 18:19:40 -08:00
Johannes Altmanninger
38397734e2 Fix build on OpenSUSE Tumbleweed
Fix a search & replace gone wrong in 1234c77b1 (Support linking against
reentrant-configured curses, 2024-01-21).
2024-01-21 22:22:30 +01:00
Fabian Boehm
89282fd9bc Use CARGO_MANIFEST_DIR to see if we're running from build dir
This allows running a fish built from `cargo build` *and* built via
cmake.

In future, we should make this an optional thing that's removed from
installed builds.
2024-01-21 21:25:05 +01:00
ridiculousfish
3ecd835f58 Clean up some stale comments and restore libc usage in flog_safe
flog_safe should be explicitly async-signal-safe functions; let's avoid
nix in that module for this reason.
2024-01-21 12:03:56 -08:00
PolyMeilex
f3e8272c5d Move from libc read/write to nix read/write
Replace std from_raw_fd/into_raw_fd dance with nix write

Fixup notifyd build
2024-01-21 11:49:40 -08:00
Johannes Altmanninger
1234c77b15 Support linking against reentrant-configured curses
NCurses headers contain this conditional "#define cur_term":

	print  "#elif @cf_cv_enable_reentrant@"
	print  "NCURSES_WRAPPED_VAR(TERMINAL *, cur_term);"
	print  "#define cur_term   NCURSES_PUBLIC_VAR(cur_term())"
	print  "#else"

OpenSUSE Tumbleweed uses this configuration option; For reentrancy, cur_term
is a function.  If the NCurses autoconf variable @NCURSES_WRAP_PREFIX@
is not changed from its default, the function is called _nc_cur_term.

I'm not sure if we have a need to support non-default @NCURSES_WRAP_PREFIX@
but if we do there are various ways;
- search for the symbol with the cur_term suffix
- figure out the prefix based on the local curses installation,
  for example by looking at the header files.

Fixes #10243
2024-01-21 11:26:07 +01:00
Fabian Boehm
f7b541af99 tests/parse_util: Check against localized message
This is run in the current locale, without resetting to en_US.UTF-8
like our integration tests do.

So if you want to check for a specific message you need to check the
localized version.
2024-01-20 12:28:59 +01:00
Himadri Bhattacharjee
e014c981f2 Disallow background operator before && or ||
Co-authored-by: Johannes Altmanninger <aclopte@gmail.com>

Closes #10228
Fixes #9911
2024-01-20 11:32:44 +01:00
Johannes Altmanninger
87d434a98d Improve failure message in test_error_messages 2024-01-20 11:30:13 +01:00
Johannes Altmanninger
c52c03b03c Fix clippy warnings 2024-01-20 11:30:13 +01:00
Johannes Altmanninger
2059e5a171 Allow finding for empty strings with wstr::find
I hit this temporarily in a test; it seems reasonable to allow this.
std::str does too.
2024-01-20 11:30:13 +01:00
Johannes Altmanninger
f356e2d82f Remove redundant fallbacks for installation dir variables
They are redundant as of a5e35abeb (build.rs: Default variables, 2024-01-15).
2024-01-20 10:26:54 +01:00
Fabian Boehm
6be6890fa3 Remove config.h
We don't actually use anything in there anymore.

We keep the WCHAR_T_BITS define in cmake because that's
used to find pcre2.
2024-01-20 08:56:29 +01:00
ridiculousfish
9747ab19d1 Eliminate UVAR_FILE_SET_MTIME_HACK checks
This was previously limited to Linux predicated on the existence
of certain headers, but Rust just exposes those functions unconditionally. So
remove the check and just perform the mtime hack on Linux and Android.
2024-01-19 09:33:33 -08:00
ridiculousfish
70ed4806b4 Use libc O_EXLOCK instead of our own
Rust libc supports O_EXLOCK on supported platforms (BSD/macOS), use that instead
of re-exposing it.
2024-01-19 09:33:33 -08:00
Johannes Altmanninger
7597288c18 test_error_messages: add back missing validation
Make sure to also look for the error part that occurs after the last format
specifier.

Still not great because it won't fail if there's unexpected output at the
beginning or end of the string.
2024-01-19 06:26:31 +01:00
Johannes Altmanninger
800f2414fb Fix regression in split_string_tok()
If there's no more separator we break early but dont update pos, so we go
into the code path that asserts we have reached the limit.
2024-01-18 10:24:40 +01:00
Johannes Altmanninger
fff8e8163b Control-C to simply clear commandline buffer again
Commit 5f849d0 changed control-C to print an inverted ^C and then a newline.

The original motivation was

> In bash if you type something and press ctrl-c then the content of the line
> is preserved and the cursor is moved to a new line. In fish the ctrl-c just
> clears the line. For me the behaviour of bash is a bit better, because it
> allows me to type something then press ctrl-c and I have the typed string
> in the log for further reference.

This sounds like a valid use case in some scenarios but I think that most
abandoned commands are noise. After all, the user erased them. Also, now that
we have undo that can be used to get back a limited set of canceled commands.

I believe the original motivation for existing behavior (in other shells) was
that TERM=dumb does not support erasing characters. Similarly, other shells
like to leave behind other artifacts, for example when using tab-completion
or in their interactive menus but we generally don't.

Control-C is the obvious way to quickly clear a multi-line commandline.
IPython does the same. For the other behavior we have Alt-# although that's
probably not very well-known.

Restore the old Control-C behavior of simply clearing the command line.

Our unused __fish_cancel_commandline still prints the ^C. For folks who
have explicitly bound ^C to that, it's probably better to keep the existing
behavior, so let's leave this one.

Previous attempt at #4713 fizzled.

Closes #10213
2024-01-17 19:54:57 +01:00
Fabian Boehm
34c09b1816 reader: Fix infinite loop for up/downcase bindings
This could *probably* be rewritten nicer with a for-loop

Fixes #10222
2024-01-16 18:13:18 +01:00
Fabian Boehm
5d3aea363e Fix PagerAndSearch not focusing the search field
Boolean confusion

Fixes #10220
2024-01-16 16:39:05 +01:00
ridiculousfish
9bd4b3f878 Adopt count_newlines in additional places 2024-01-14 10:04:55 -08:00