Commit Graph

19019 Commits

Author SHA1 Message Date
Mahmoud Al-Qudsi
d14d8d5733 Remove wcstringutil::split_string()
It is short and simple enough to write yourself if you need it and it encourages
bad behavior by a) always returning owned strings, b) always allocating them in
a vector. If/where possible, it is better to a) use &wstr, b) use an iterator.

In rust, it's an anti-pattern to unnecessarily abstract over allocating
operations. Some of the call sites even called split_string(..).into_iter().
2024-05-21 12:54:52 -05:00
Mahmoud Al-Qudsi
96b979077c Add unit tests for path_normalize_for_cd() 2024-05-21 12:54:51 -05:00
Mahmoud Al-Qudsi
8c62f733b3 Extend certain WSL workarounds to WSLv2
This updates is_windows_subsystem_for_linux() to take a WSL version to test for
(any, v1, or v2) and returns the boolean result depending on the system. I've
benchmarked and when running on regular Linux, this is still just as fast as the
previous binary check; it's only when it's WSL that this takes about 20ns
longer to figure out which variant.

Note that older WSLv2 kernels had a `-microsoft-standard` suffix while newer
ones appear to have a `-microsoft-standard-WSL2` suffix, so we make sure to test
for the least common denominator. (It doesn't matter to us, but note that newer
WSLv2 kernels have four dots in the version string!)

WSL workarounds pertaining to the default Windows terminal or executable
behavior of win32 binaries under a WSL shell are extended to WSLv2 while those
specific to oddities in kernel behavior are confined to WSLv1 only. (It
technically wouldn't hurt to extend them to WSLv2 but there's no good reason to
do so, either.)
2024-05-20 14:14:25 -05:00
Mahmoud Al-Qudsi
3374692b91
Work around $PATH issues under WSL (#10506)
A common complaint has been the massive amount of directories Windows appends to
$PATH slowing down fish when it attempts to find a non-existent binary (which it
does a lot more often than someone not in the know might think). The typical
workaround suggested is to trim unneeded entries from $PATH, but this a) has
considerable friction, b) breaks resolution of Windows binaries (you can no
longer use `clip.exe`, `cmd.exe`, etc).

This patch introduces a two-PATH workaround. If the cmd we are executing does
not contain a period (i.e. has no extension) it by definition cannot be a
Windows executable. In this case, we skip searching for it in any of the
auto-mounted, auto-PATH-appended directories like `/mnt/c/Windows/` or
`/mnt/c/Program Files`, but we *do* include those directories if what we're
searching for could be a Windows executable. (For now, instead of hard-coding a
list of known Windows executable extensions like .bat, .cmd, .exe, etc, we just
depend on the presence of an extension at all).

e.g. this is what starting up fish prints with logging enabled (that has been
removed):

    bypassing 100 dirs for lookup of kill
    bypassing 100 dirs for lookup of zoxide
    bypassing 100 dirs for lookup of zoxide
    bypassing 100 dirs for lookup of fd
    not bypassing dirs for lookup of open.exe
    not bypassing dirs for lookup of git.exe

This has resulted in a massive speedup of common fish functions, especially
anywhere we internally use or perform the equivalent of `if command -q foo`.

Note that the `is_windows_subsystem_for_linux()` check will need to be patched to
extend this workaround to WSLv2, but I'll do that separately.

Under WSL:
* Benchmark `external_cmds` improves by 10%
* Benchmark `load_completions` improves by an incredible 77%
2024-05-20 10:29:32 -05:00
Jannik Vieten
bd4e5fe69a
completions ip: silence stderr in case -d does not exist (busybox) (#10509) 2024-05-20 07:28:40 -05:00
Peter Yates
56a168d37f Prevent loading of psqlrc when listing databases
Users have the ability to override the way records are displayed in psql by
changing the format[1] and linestyle[2] settings. These settings also affect the
output of psql commands used for autocompletion, like listing databases and
users - so they inadvertantly break Fish's completion.

If we suppress the loading of psqlrc[3] the default settings are used instead.

[1] https://www.postgresql.org/docs/current/app-psql.html#APP-PSQL-META-COMMAND-PSET-FORMAT
[2] https://www.postgresql.org/docs/current/app-psql.html#APP-PSQL-META-COMMAND-PSET-LINESTYLE
[3] https://www.postgresql.org/docs/current/app-psql.html#APP-PSQL-OPTION-NO-PSQLRC
2024-05-20 14:04:38 +02:00
ridiculousfish
efefeda392 Restore some iTerm2 default key bindings
c0bcd817ba removed some key bindings, including the bindings of
ESC ESC [ C for Alt-Right. the commit claimed that
"Sequences like \e\eOC are Escape followed by an SS3 arrow key which we
can already decode separately." but for whatever reason this doesn't work:
Alt-Right is broken in iTerm2 by default.

Restore the default ESC ESC [ X bindings for iTerm2 compatibility.
2024-05-19 11:01:14 -07:00
ridiculousfish
42f8672f34 Remove an errant {} from a FLOG 2024-05-19 10:27:45 -07:00
Klaus Hipp
4659fdf704
Add git-lfs completions (#10490) 2024-05-19 09:09:33 -05:00
tesuji
255c8da22d
add completions for ibus (#10500) 2024-05-19 09:05:40 -05:00
Jannik Vieten
66d28f5fda
completions: improved ip completions (#10505)
- complete routing table names/IDs
- rudimentary completions for ip rule subcommand
2024-05-19 09:00:29 -05:00
Johannes Altmanninger
d40d2b786f Work around wants_terminal not begin set inside eval
On this binding we fail to disable CSI u

    bind c-t '
        begin
            set -lx FZF_DEFAULT_OPTS --height 40% --bind=ctrl-z:ignore
            eval fzf | while read -l r; echo read $r; end
        end
    '

because for "fzf", ParseExecutionContext::setup_group() returns early with the
parent process group (which should be fish's own) , hence "wants_terminal"
is false. This seems questionable, I don't think the eval should make a
difference here.

For now, don't touch it; use the more accurate way of detecting whether
a process may read keyboard input. In many of such cases "wants_terminal"
is false, like

    echo (echo 1\n2\n3 | fzf)

Fixes #10504
2024-05-18 20:55:06 +02:00
Mahmoud Al-Qudsi
ef614ba2d9 Speed up rustc completions, filter out deprecated options
Don't unconditionally execute the plumbing to get `rustc -C` completions (use it
only when trying to complete `rustc -C`), filter out deprecated options, and use
fewer calls to the `string` builtin to optimize further.

Need to do the same thing for the `-Z` completions next, those hang the shell
for a good 1.5+ seconds.
2024-05-18 12:37:18 -05:00
Mahmoud Al-Qudsi
0a7725e469 Add comment re accuracy of cargo --target completions
[ci skip]
2024-05-18 12:00:45 -05:00
Mahmoud Al-Qudsi
cbb399f2ed completions/cargo.fish: Add python fallback for jq 2024-05-17 18:45:19 -05:00
Mahmoud Al-Qudsi
79f7b9f92a completions/cargo.fish: Dynamically generate --features completion 2024-05-17 18:17:53 -05:00
Mahmoud Al-Qudsi
f342ae6a1c Add a completion helper function to generate permutation completions
I've been needing this for some time to generate completions for functions that
we can dynamically generate completions for that take one or more
comma-separated values in any order.
2024-05-17 18:15:41 -05:00
Mahmoud Al-Qudsi
6dbae76b24 Update cargo-asm completions
Try not to let `cargo asm` build a large project and hang the terminal (and make
the fans go crazy) if we try to generate a list of functions/paths and the
project is in a dirty state. Also support dynamic completion of --target.
2024-05-17 17:10:10 -05:00
Mahmoud Al-Qudsi
1d36c6ad8c completions/cargo.fish: Generate dynamic --target options
If rustup is installed, use the existing `__rustup_installed_targets` to get a
list of installed targets to compile for. If it's not, print a list of all
targets known to rustc.

It sucks that the completions file is currently architected in a way where we
have to manually specify the arguments for each subcommand. 🤷
2024-05-17 16:57:40 -05:00
Mahmoud Al-Qudsi
d8e9a17c1f Inline extract_prefix_and_unescape_yaml()
We sometimes call it but discard half its results, so force it to be inlined to
make sure we don't perform work we then throw away.
2024-05-17 16:11:46 -05:00
Mahmoud Al-Qudsi
bcb1e2ed85 Further optimize unescape_yaml_fish_2_0()
This hot function dominates the flamegraphs for the completions thread, and any
optimizations are worthwhile.

A variety of different approaches were tested and benchmarked against real-world
fish-history file inputs and this is the one that won out across all rustc
target-cpu variations tried.

Benchmarks and code at https://github.com/mqudsi/fish-yaml-unescape-benchmark
2024-05-17 16:06:08 -05:00
Mahmoud Al-Qudsi
9ab1ec2a9e Tweak newly added rustc completion descriptions
Addendum to https://github.com/fish-shell/fish-shell/pull/10491
2024-05-17 12:33:59 -05:00
tesuji
d3758d3751
completion: add more arguments for rustc --print (#10491)
Based off of rustc 1.80.0-nightly
2024-05-17 12:32:41 -05:00
Ian Chamberlain
1462da3ae2
Complete cargo check bin targets like build (#10499)
Since `check` operates on basically the same things as `build`, it makes
sense to complete binary targets the same way (i.e. tests, bins, examples)
2024-05-17 12:31:30 -05:00
Mahmoud Al-Qudsi
0271d91d3a Add completions for cargo-asm 2024-05-17 12:31:02 -05:00
David Adam
f4a79cc138 debian packaging: disable LTO build profile
Fixes the build on Ubuntu distributions with aggressive enabling of LTO
for all builds.

This build profile sets CFLAGS and CXXFLAGS in a way that prevents cargo
tests from linking. This manifests as errors like:

= note: make[5]: *** read jobs pipe: Bad file descriptor.  Stop.
        make[5]: *** Waiting for unfinished jobs....
        lto-wrapper: fatal error: make returned 2 exit status
        compilation terminated.
        /usr/bin/ld: error: lto-wrapper failed
        collect2: error: ld returned 1 exit status
2024-05-17 23:41:54 +08:00
Mahmoud Al-Qudsi
3d648e6e04 Remove Arc from environment::globals() (take 2)
We don't forward this variable for storage in any structs, so there's no reason
to go through an Arc instead of returning the `&'static EnvStack` directly.

NB: This particular change was safe, and passes all tests on its own.
2024-05-16 21:17:15 -05:00
Mahmoud Al-Qudsi
45e249dd94 Revert removal of Arc from principal() and global()
This reverts commit c6d3bde0c6.
This reverts commit 4ce13f0adb.
2024-05-16 21:08:06 -05:00
Mahmoud Al-Qudsi
c6d3bde0c6 Remove Arc from environment::globals()
We don't forward this variable for storage in any structs, so there's no reason
to go through an Arc instead of returning the `&'static EnvStack` directly.
2024-05-16 20:50:23 -05:00
Mahmoud Al-Qudsi
4ce13f0adb Simplify lifetime of environment::principal()
It's clearer that using it with `Rc::from_raw()` is safe since we don't have to
go through an `Arc<T>`.
2024-05-16 20:46:28 -05:00
Mahmoud Al-Qudsi
ec1bf60941 Add note about possible safety issue with GLOBAL_NODE 2024-05-16 20:33:43 -05:00
Mahmoud Al-Qudsi
66618d64cb Convert some lazy_static to OnceCell/OnceLock
These have clearer sync/unsync semantics and now ship with rust itself.
They don't paper over any possible cross-thread issues, and we can specifically
choose which we want for the purpose.
2024-05-16 20:33:43 -05:00
Mahmoud Al-Qudsi
0f18480559 Simplify Parser and EnvStack singletons and clarify thread semantics
`Parser` is a single-threaded `!Send`, `!Sync` type and does not need to use
`Arc` for anything. We were using it because that's all we had for the parser's
`EnvStack`, but though that is *technically* protected internally by a mutex
(shared with global EnvStack), there's nothing to say that other parsers with a
narrower scope/lifetime on other threads will be necessarily using the same
backing mutex.

We can safely marshal the existing `Arc<EnvStack>` we get from
`environment::principal()` into an `Rc<EnvStack>` since the underlying reference
is always valid. To prove this point, we could have PRINCIPAL_STACK be a static
`EnvStack` and have `environment::principal()` use `Arc::from_raw()` to turn
that into an `Arc<EnvStack>`, but there's no need to factorize this process.
2024-05-16 20:33:39 -05:00
Mahmoud Al-Qudsi
e4282f3798 Remove all locking from principal_parser()
By inverting the order of storage, we can use an `OnceCell`/`unsync::Lazy`
inside the Send/Sync `MainThread<T>` and remove the need for a lock altogether.
2024-05-16 14:23:25 -05:00
Fabian Boehm
5dc07c9e7e completions: More shortening
Also removes a few deprecated options - there's really no need to
offer these.
2024-05-16 18:29:42 +02:00
Johannes Altmanninger
29f2da8d18 Toggle terminal protocols lazily
Closes #10494
2024-05-16 12:26:47 +02:00
Johannes Altmanninger
6f9d5cf44c Address clippy lint 2024-05-16 12:25:29 +02:00
Mahmoud Al-Qudsi
b82170aded Change extract_prefix_and_unescape_yaml() assert!() to debug_assert!()
It's reasonable since this is only checking to see that the history file
contains the expected format and if it's corrupted but we at least got what we
expect to be the correct key/value pairs, then that's all we can do.

Of course the real motivation is to speed up this very hot function in any way
possible!
2024-05-15 22:42:19 -05:00
Mahmoud Al-Qudsi
51275525c1 Speed up extract_prefix_and_unescape_yaml
On the completions and history thread, the parent function
HistoryFileContents::decode_item() is responsible for ~60% of the CPU time, and
extract_prefix_and_unescape_yaml() alone comprising 14% (of the total).

This change removes allocations in the event that the history item is either
fully or partially plain yaml with no escapes to begin with, and brings down the
execution time of this function to only 7% of the total execution time.

The bulk of the remaining time is spent in wcs2string(), which is called
unconditionally and is naturally alloc-heavy.
2024-05-15 22:42:19 -05:00
ridiculousfish
caef202551 Fix some more clippies and enable more warnings 2024-05-15 20:05:35 -07:00
Fabian Boehm
fc5eb0a98a fish_for_bash_users: Put explanation on subshells first
and *then* explain things that aren't subshells.
2024-05-15 22:44:07 +02:00
Fabian Boehm
b6bebec513 docs: Simplify Combining Lists section
This was a bit dense.
2024-05-15 20:18:17 +02:00
Fabian Boehm
8bac13360b completions/gcc: More cleanup
These options, I tell you
2024-05-15 20:07:28 +02:00
Fabian Boehm
173bcf29ab completions/gcc: Cleanup options
- Remove duplicated options - we had `-type` 9 times!
- Remove deprecated options and synonyms
- Make descriptions shorter, even removing some - when they're inscrutable they might as well not be there.

Really, 99.8% of these options are of interest to nobody except possibly (a subset of) gcc developers, so it pays to have *less* on your screen that you don't use anyway.
2024-05-15 17:05:02 +02:00
Fabian Boehm
4cadaa4041 completions/gcc: Fix some options
Especially the "-l" one was *always* offered.
2024-05-15 17:05:02 +02:00
Johannes Altmanninger
35b689335a Strip control characters from pasted text
We ignore typed control characters 33a7172ee (Revert to not inserting control
characters from keyboard input, 2024-03-02).

We used to do the same for bracketed paste but that changed in 8bf8b10f6
(Extended & human-friendly keys, 2024-03-30) which made bracketed paste
behave like fish_clipboard_paste; it inserts the exact input (minus leading
whitespace etc). At that time it wasn't clear to me which behavior was the
right one (because of the inconsistency between terminal and bracketed paste).

As reported in
https://matrix.to/#/!YLTeaulxSDauOOxBoR:matrix.org/$PEEOAoyJY-644amIio0CWmq1TkpEDdSy2QnfJdK-dco
trailing tabs in pasted text can be confusing.

There seems to be not real need to insert raw control characters into the
command line, so let's strip them when pasting.

Now the only way to insert a raw control character into the command line is
to recall it from command history.  Not sure what the behavior should be for
that case, we can revisit that later. If we get rid of raw control characters
entirely, then we can also delete the new "control pictures" rendering :)
2024-05-14 23:14:49 +02:00
Fabian Boehm
a72ba0408f CHANGELOG 2024-05-14 17:32:17 +02:00
Fabian Boehm
24836f9652 Use set --no-event in the key binding functions
This is how we can use it in a backwards-compatible way. Eventually we
would remove the compatibility guff.
2024-05-14 17:31:47 +02:00
Fabian Boehm
f1e19884fb Add set --no-event
This allows running `set` without triggering any event handlers.

That is useful, for example, if you want to set a variable in an event
handler for that variable - we could do it, for example, in the
fish_user_path or fish_key_bindings handlers.

This is something the `block` builtin was supposed to be for, but it
never really worked because it only allows suppressing the event for
the duration, they would fire later. See #9030.

Because it is possible to abuse this, we only have a long-option so
that people see what is up.
2024-05-14 17:31:47 +02:00
Fabian Boehm
403920e9d6 input: Remove all_mappings_cache
Replace it with a chained iterator.

This not only simplifies the code, but also removes a RefCell.
2024-05-14 16:14:02 +02:00