Commit Graph

17844 Commits

Author SHA1 Message Date
Fabian Boehm
0f8bcb0414
wildcard: Rationalize file/command completions (#10052)
* wildcard: Remove file size from the description

We no longer add descriptions for normal file completions, so this was
only ever reached if this was a command completion, and then it was
only added if the file wasn't a regular file... in which case it can't
be an executable.

So this was dead.

* Make possible_link() a maybe

This gives us the full information, not just "no" or "maybe"

* wildcard: Rationalize file/command completions

This keeps the entry_t as long as possible, and asks it, so especially
on systems with working d_type we can get by without a single stat in
most cases.

Then it guts file_get_desc, because that is only used for command
completions - we have been disabling file descriptions for *years*,
and so this is never called there.

That means we have no need to print descriptions about e.g. broken symlinks, because those are not executable.

Put together, what this means is that we, in most cases, only do
an *access(2)* call instead of a stat, because that might be checking
more permissions.

So we have the following constellations:

- If we have d_type:
  - We need a stat() for every _symlink_ to get the type (e.g. dir or regular)
    (this is for most symlinks, if we want to know if it's a dir or executable)
  - We need an access() for every file for executables
- If we do not have d_type:
  - We need a stat() for every file
  - We need an lstat() for every file if we do descriptions
    (i.e. just for command completion)
  - We need an access() for every file for executables

As opposed to the current way, where every file gets one lstat whether
with d_type or not, and an additional stat() for links, *and* an
access.

So we go from two syscalls to one for executables.

* Some more comments

* rust link option

* rust remove size

* rust accessovaganza

* Check for .dll first for WSL

This saves quite a few checks if e.g. System32 is in $PATH (which it
is if you inherit windows paths, IIRC).

Note: Our WSL check currently fails for WSL2, where this would
be *more* important because of how abysmal the filesystem performance
on that is.
2023-10-14 08:45:15 +02:00
Johannes Altmanninger
773a507b01 fish.rs: fix regression in fish_xdm_login_hack_hack_hack_hack
This is off by one from the C++ version.

It wasn't super obvious why this worked in the first place.
Looks like args[0] is "-" because we are invoked like

    fish -c 'exec "${@}"' - "${@}"

and it looks like "-" is treated like "--" by bash, so we emulate that.
See https://github.com/fish-shell/fish-shell/issues/367#issuecomment-11740812
2023-10-13 19:58:50 +02:00
Johannes Altmanninger
b8c5627eb1 io: use Vec::with_capacity 2023-10-13 19:53:45 +02:00
Fabian Boehm
c6e905a1b9 docs/read: Mention the more common mode first
Printing to stdout is a thing it can do, yes, but writing to variables
is the more typical way to use it.
2023-10-12 22:35:43 +02:00
Johannes Altmanninger
bba0103103 build.rs: re-run if compat.c changed 2023-10-12 21:55:11 +02:00
David Adam
0f70b2c0d3 README: bump CMake requirements for Rust build
file(real_path) added in 35baa883 requires CMake 3.19.
2023-10-12 15:48:38 +08:00
ridiculousfish
57335ebb02 Reformat colorutils.js using Prettier 2023-10-08 12:27:39 -07:00
ridiculousfish
98018753e5 Replace references to angular with alpine
Updates our license references.
2023-10-08 12:25:43 -07:00
ridiculousfish
5e06e80136 Remove angular "partials"
These are no longer used as we are fully on Alpine.js
2023-10-08 12:22:56 -07:00
Mahmoud Al-Qudsi
0233c0c437 fix is_windows_subsystem_for_linux(), check for post-fork-safety
This function only ever returns true if target_os=linux, so we need to invert
the OS check.

In the first invocation, this function may allocate heap memory.
Clarify that this is safe.

[ja: I don't have the original commit handy so I made up the log message]
2023-10-08 20:48:24 +02:00
Johannes Altmanninger
0a48f4b55c common: remove deprecated methods 2023-10-08 20:46:53 +02:00
Johannes Altmanninger
b583c51238 Sort clippy lints 2023-10-08 20:46:53 +02:00
Johannes Altmanninger
d15e475440 event: reduce lock scope to allow re-locking in event handler
The following "Port execution" commit will use RefCell for the wait handle
store.  If we hold a borrow while we are running an event (which may run
script code) there will be a borrowing conflict. Avoid this by returning
the borrow earlier.
2023-10-08 20:46:53 +02:00
Johannes Altmanninger
575c271461 job_group: reuse RelaxedAtomicBool 2023-10-08 20:46:53 +02:00
Johannes Altmanninger
d764625069 getcwd: fix bad error message 2023-10-08 20:46:53 +02:00
Johannes Altmanninger
ad75c72621 flog: reuse write_to_fd 2023-10-08 20:46:53 +02:00
Johannes Altmanninger
637926a7fd env: fix porting regression recording inherited vars 2023-10-08 20:46:53 +02:00
Johannes Altmanninger
d8de497ebc Use shorter escape() function 2023-10-08 20:46:53 +02:00
Johannes Altmanninger
0b25793097 wildcard: use "zelf" over "this" for consistency
The following "Port execution" commit will add lots of variables called "zelf".
2023-10-08 20:46:53 +02:00
Johannes Altmanninger
6ef5ae0935 env: skip env lines without equal sign
Given an env like

    foo
    bar=baz

we would set "foo" to empty due to a typo.
The typo is pointed out by a PORTING comment.

Luckily I don't think we ever hit this case because that would mean our
parent process has a serious bug.  Rust's std::env::vars_os() skips env
lines that don't contain a "=" char.  This seems like a reasonable behavior
for us too. Do that.
2023-10-08 20:46:53 +02:00
Johannes Altmanninger
e8712af0c3 builtin random: make option parsing consistent with other builtins again
As suggested in a comment on2fb352a9e (Address some clippy lints from nightly
clippy, 2023-10-03).
2023-10-08 20:46:53 +02:00
Fabian Boehm
86803e4442
Reduce stat calls for wildcards ending in "/" (#10032)
This makes it so expand_intermediate_segment knows about the case
where it's last, only followed by a "/".

When it is, it can do without the file_id for finding links (we don't
resolve the files we get here), which allows us to remove a stat()
call.

This speeds up the case of `...*/` by quite a bit.

If that last component was a directory with 1000 subdirectories we
could skip 1000 stat calls!

One slight weirdness: We refuse to add links to directories that we already visited, even if they are the last component and we don't actually follow them. That means we can't do the fast path here either, but we do know if something is a link (if we get d_type), so it still works in common cases.
2023-10-08 16:46:59 +02:00
Fabian Boehm
c4ca1a68d3
Add a clear-screen bind function to clear the screen (#10044)
This can be bound like `bind \cl clear-screen`, and is, by default

In contrast to the current way it doesn't need the external `clear`
command that was always awkward.

Also it will clear the screen and first draw the old prompt to remove
flicker.
Then it will immediately trigger a repaint, so the prompt will be overwritten.
2023-10-08 11:41:30 +02:00
ridiculousfish
f7e7396c69 Fix a deadlock affecting fish_config
This fixes the following deadlock. The C++ functions path_get_config and
path_get_data lazily determine paths and then cache those in a C++ static
variable. The path determination requires inspecting the environment stack.
If these functions are first called while the environment stack is locked
(in this case, when fetching the $history variable) we can get a deadlock.

The fix is to call them eagerly during env_init. This can be removed once
the corresponding C++ functions are removed.

This issue caused fish_config to fail to report colors and themes.

Add a test.
2023-10-07 15:20:14 -07:00
ridiculousfish
b315b66cb0 Minor comment cleanup of main.rs 2023-10-07 14:39:24 -07:00
Fabian Boehm
e62f32c16b CI: Remove --deny=warnings from clippy test
This was pretty annoying on rust release day, because it introduced
new warnings.

Specifically 1.73 introduced a spurious one about PartialOrd and Ord
disagreeing when both were in fact #derive-d.
2023-10-07 19:48:54 +02:00
Johannes Altmanninger
79bbf5247a builtin set_color: use naming convention 2023-10-07 19:30:46 +02:00
Johannes Altmanninger
28a38946a5 common: port err!() test helper
Unlike our C++ tests, our Rust tests fail as soon as an assertion fails.
Whether this is desired is debatable; it seems fine for
most cases and is easier to implement.

This means that Rust tests usually don't need to print anything besides
what assert!/assert_eq! already provide.
One exception is the history merge test. Let's add a simple err!() macro to
support this. Unlike the C++ err() it does not yet print colors.

Currently all of our macros live in common.rs, to keep the import graph simple.
2023-10-07 19:30:46 +02:00
Johannes Altmanninger
618834c4b5 Port UVAR_FILE_SET_MTIME_HACK
Notably this exposes config.h to Rust (for UVAR_FILE_SET_MTIME_HACK).
In future we should move the CMake checks into build.rs so we can potentially
get rid of CMake.
2023-10-07 19:30:46 +02:00
Johannes Altmanninger
3020c90856 Upgrade bitflags
This allows us to use some newer functionality (I forgot which one I ended
up using).
2023-10-07 19:30:46 +02:00
Johannes Altmanninger
1bfdc33f76 Make stream.append call sites consistent
Maybe the wrong direction.. but this seems to be the majority.
2023-10-07 19:30:46 +02:00
Johannes Altmanninger
2fb352a9e4 Address some clippy lints from nightly clippy
Note that in general we should not respect nightly clippy because it might
contradict stable clippy which is run in CI.
2023-10-07 19:30:46 +02:00
Johannes Altmanninger
10fed02572 Work around ASan complaining about buffer overflow in DirIter
On the following "Port execution" commit, ASan will complain if we read
beyond a terminating null byte in get_autosuggestion_performer().  This is
actually working as intended but we need to appease ASan somehow..
2023-10-07 19:30:46 +02:00
Johannes Altmanninger
55683b29cd CMakeLists: sort 2023-10-07 19:30:46 +02:00
Johannes Altmanninger
379ad03d9d parse_util: return Result in parse_util_detect_errors_in_argument
This makes it consistent with some other public parse_util_* functions.
2023-10-07 19:30:46 +02:00
Johannes Altmanninger
2334424234 parse_util: fix regressions from port
Tested by the upcoming highlighting unit tests.
2023-10-07 19:30:46 +02:00
Johannes Altmanninger
c7c0bb9bb2 env: fix boolean sense in get_pwd_slash()
get_pwd_slash() uses "if var.is_empty()" but it should be "if !var.is_empty()".
This wasn't a problem so far because in practice most code paths use the
get_pwd_slash() override from EnvStackImpl. The generic one is used in the
upcoming unit tests.
2023-10-07 19:30:46 +02:00
Johannes Altmanninger
48ce8f8721 Remove test_history_speed benchmark
Doesn't seem terribly important? We can add it back easily.
2023-10-07 19:30:46 +02:00
Johannes Altmanninger
ffbb56c4a9 common: port test_format 2023-10-07 19:30:46 +02:00
Johannes Altmanninger
408161f4d6 Port test_tokenizer 2023-10-07 19:30:46 +02:00
Mathijs Henquet
a809672412
Fix out of scope opt variable (#10020)
* Fix out of scope opt variable

* Update ls.fish
2023-10-07 18:00:17 +02:00
Fabian Boehm
098b7093da fish_config: Fix save with variable with multiple values
Your basic quoting problem, regressed in 3.6.0
2023-10-06 22:15:35 +02:00
Fabian Boehm
496d65fb5d Apply variable overrides for exec
Fixes #9995
2023-10-06 18:15:25 +02:00
Fabian Boehm
6775b0b1ad Implement PartialEq manually to shut up clippy 2023-10-06 17:10:59 +02:00
Fabian Boehm
1073f59929 Shut up Clippy 1.72 2023-10-06 16:54:16 +02:00
Fabian Boehm
ff433b0cb2 reader: Only move cursor if needed for repaint-mode
This uses "screen.reset_line" to move the cursor without informing the
reader's machinery (because that deals with positions *in the
commandline*), but then only repainted "if needed" - meaning if the
reader thought anything changed.

That could lead to a situation where the cursor stays at column 0
until you do something, e.g. in

```fish
bind -m insert u undo
```

when you press alt+u - because the *escape* calls repaint-mode, which
puts the cursor in column 0, and then the undo doesn't, which keeps it
there.

Of course this binding should also `repaint-mode`, because it changes
the mode.

Some changes might be ergonomic:

1. Make repaint-mode the default if the mode changed (we would need to
skip it for bracketed-paste)
2. Make triggering the repaint easier - do we need to set
force_exec_prompt_and_repaint to false here as well?

Anyway, this

Fixes #7910
2023-10-06 16:38:26 +02:00
Fabian Boehm
3ce67ecbd2 printf: Fix octal escapes with leading zeroes
Octal escapes can be written as `\057` or as `\0057`.

Simply ported wrong initially.
2023-10-05 15:39:50 +02:00
Fabian Boehm
8cc0bdeed8 pexpect: Remove some unnecessary empty lines
This strips the newline from "code_context" (which is really just the
called function), and from the unescaped output.

Rather, in case the output doesn't end with a newline it'll mark it
with an explicit message "(no trailing newline)".
2023-10-04 18:51:44 +02:00
Fabian Boehm
7a22dcb687 pexpect: Check if the process exited with a signal
This would have been helpful in #10044:

> signals.py:28: SIGNAL SIGSEGV from expect_prompt()

instead of "EOF".
2023-10-04 16:02:13 +02:00
Fabian Boehm
f8e38819a5 open: Don't run xdg-open in the background
This was introduced as a workaround to #7215 - xdg-open's generic path
wouldn't background graphical apps.

This has been fixed a month ago in xdg-open, so we can stop doing it.

The good news is this also allows terminal apps to be used again, so
it

Fixes #10045
2023-10-04 15:57:32 +02:00