Commit graph

122 commits

Author SHA1 Message Date
Fabian Boehm
fc95eca257 share/config.fish: Skip __fish_set_locale if $LANG is already set
This is the most common and sensible env var, we check it outside,
so we can skip loading the function at all if we already know it's not
gonna do anything.

This is done on every startup of every single fish, and it saves ~0.2ms.
2023-09-09 15:53:20 +02:00
Fabian Boehm
4e3b3b3b0a share/config.fish: Quit if job expansion hack errors
This prevents something like `fg %5` to foreground the first job if
there is no fifth.

Fixes #9835
2023-06-10 15:36:36 +02:00
Fabian Boehm
7ac2fe2bd3 share/config: Erase on_interactive before doing __fish_config_interactive
This removes a possibility of an infinite loop where something in
__fish_config_interactive triggers a fish_prompt or fish_read event,
which calls __fish_on_interactive which calls
__fish_config_interactive again, ...

Fixes #9564
2023-02-11 14:15:44 +01:00
Fabian Boehm
dd7d432cd6 Only define kill wrapper if we have a kill to wrap 2023-01-29 14:44:45 +01:00
Fabian Boehm
3ba1170ca5 Store the vendor directories in global variables
This lets us query them later, which helps with fish_delta
2022-10-19 20:06:35 +02:00
Fabian Boehm
af3a5b86d8 Call __fish_config_interactive also for interactive read
Not doing this results in our emergency keybindings being set up for
`read`.

Fixes #9227
2022-09-21 17:02:25 +02:00
Fabian Boehm
96a064d679 share/config.fish: Fix outdated comment 2022-08-11 17:07:59 +02:00
Gregory Anders
55f0f2de4c Search $__fish_user_data_dir for vendor additions 2022-05-12 20:29:05 +02:00
Fabian Homborg
f13979bfbb Move executable-check to C++
This was already apparently supposed to work, but didn't because we
just overrode errno again.

This now means that, if a correctly named candidate exists, we don't
start the command-not-found handler.

See #8804
2022-03-31 15:16:01 +02:00
Fabian Homborg
666032abbd Translate command-not-found message
I have no idea why this function is defined twice.
2022-03-17 18:19:03 +01:00
Fabian Homborg
fb283cfe4a Move $__fish_initialized to config_interactive
This is no longer used in share/config.fish, and it's quite cheesy.

The only thing we use it for is defaulting the colorscheme.
2022-03-17 18:15:11 +01:00
Fabian Homborg
49c16cc9a6 Stop migrating old abbrs
This tried migrating old abbreviations *twice* - once from the 2.3
scheme to the 2.4 one, and once from that to the 3.0 scheme.

Since this is purely for upgrading from fishes < 3.0, and basically
untested, let's remove it.

If anyone does that upgrade, they'll simply have to reexecute the abbrs.
2022-03-17 18:15:11 +01:00
Fabian Homborg
71cfd25c1d Command-not-found: Warn if a file exists but isn't executable
This simply adds a nice error so you can better see if your command
isn't available because it's not executable.

Fixes #8804.
2022-03-17 18:06:36 +01:00
Aaron Gyes
c6166f8ced Shorten more.
More vain attempts to get a bare <TAB> showing as 2 columns in the
pager. This now happens in a 101 column terminal.
2022-01-27 16:21:22 -08:00
Aaron Gyes
1262469aea Shorten two more command's descriptions
Two columns at 119 width.
2022-01-22 21:04:26 -08:00
Aaron Gyes
ed0b6cdc9d Shorten fish_sigtrap_handler description.
We can now get two columuns in the pager hitting <TAB> at 124 cols
2022-01-22 20:57:48 -08:00
Ilan Cosman
30400f3ced Use test command instead of bracket command 2021-11-26 16:55:50 -08:00
Fabian Homborg
e013422143 Deduplicate $fish_user_paths automatically
In the variable handler, we just go through the entire thing and keep
every element once.

If there's a duplicate, we set it again, which calls the handler
again.

This takes a bit of time, to be paid on each startup. On my system,
with 100 already deduplicated elements, that's about 4ms (compared to
~17ms for adding them to $PATH).

It's also semantically more complicated - now this variable
specifically is deduplicated? Do we just want "unique" variables that
can't have duplicates?

However: This entirely removes the pathological case of appending to
$fish_user_paths in config.fish (which should be an FAQ entry!), and the implementation is quite simple.
2021-07-14 16:37:30 +02:00
Johannes Altmanninger
943cf03d8e Only send the PID of the last process in a job to builtin fg
jobs -p %1 prints all processes in the first job.
fg is special because it only takes one argument.  Using the last process
in the pipeline works for the cases I can think of.

Fixes #7406
2020-10-18 19:36:48 +02:00
Fabian Homborg
340de73172 Call "fish_command_not_found" if a command wasn't found
Previously, when a command wasn't found, fish would emit the
"fish_command_not_found" *event*.

This was annoying as it was hard to override (the code ended up
checking for a function called `__fish_command_not_found_handler`
anyway!), the setup was ugly,
and it's useless - there is no use case for multiple command-not-found handlers.

Instead, let's just call a function `fish_command_not_found` if it
exists, or print the default message otherwise.

The event is completely removed, but because a missing event is not an error
(MEISNAE in C++-speak) this isn't an issue.

Note that, for backwards-compatibility, we still keep the default
handler function around even tho the new one is hard-coded in C++.

Also, if we detect a previous handler, the new handler just calls it.

This way, the backwards-compatible way to install a custom handler is:

```fish
function __fish_command_not_found_handler --on-event fish_command_not_found
    # do a little dance, make a little love, get down tonight
end
```

and the new hotness is

```fish
function fish_command_not_found
    # do the thing
end
```

Fixes #7293.
2020-09-06 11:15:54 +02:00
Fabian Homborg
be3a7c03ba Move truecolor detection to C++
This allows us to send proper debug messages via FLOG, and it removes
more things from share/config.fish.

Note that the logic differs in some subtle ways. For instance it will
now obey $COLORTERM, so if that isn't "truecolor" or "24bit" it will
deactivate truecolor.
2020-08-31 16:49:57 +02:00
Mahmoud Al-Qudsi
9f8e4ab524 Don't load vendor extensions when running unit tests
a) they can screw up our expected output/behavior
b) they can blow up your system

In my case, the unit tests were calling Pantheon's fish integration
script which would then proceed to blow up dbus with messages about each
individual test completing.
2020-07-12 19:14:35 -05:00
Mahmoud Al-Qudsi
2d52335fed Don't fire fish_prompt when read is used
Apart from being semantically incorrect, this was causing `fish_prompt`
to fire twice after commands that used `read` (e.g. `cdh`).

Closes #7039.
2020-05-26 15:24:31 -05:00
Johannes Altmanninger
6746060c14 Run fish_indent on all fish files in share/ 2020-05-19 21:15:39 +02:00
Fabian Homborg
713ceddf0b Add another test for Konsole
For some reason my current version doesn't have $KONSOLE_PROFILE_NAME
anymore, it has $KONSOLE_VERSION.

Urgh
2020-04-25 18:01:43 +02:00
Fabian Homborg
5dfaff4281 Make "." a builtin as well
Yeah, it's not going anywhere. This is one line in builtin.cpp vs 9
lines of script, most of which used to print an error that is never triggered.
2020-04-06 18:55:59 +02:00
Fabian Homborg
be0de5e2de Just define a ":" builtin
It's *less code* to define this as a builtin, and it's not going
anywhere. Plus it makes fish just a little more usable without share/config.fish.
2020-04-06 18:55:59 +02:00
Fabian Homborg
54d580cf94 Simplify __fish_expand_pid_args 2020-03-28 09:50:37 +01:00
Fabian Homborg
9367d4ff71 Reindent functions to remove useless quotes
This does not include checks/function.fish because that currently
includes a "; end" in a message that indent would remove, breaking the test.
2020-03-09 19:46:43 +01:00
David Adam
43edbf4a91 config.fish: drop PATH modifications on Solaris-derived systems
Fixes #6556.

Although present since 2006, fish no longer relies on POSIX-compliant tools to the same degree. This
code causes a platform specific change that makes the tests fail, so remove it.
2020-02-07 20:43:15 +08:00
Fabian Homborg
d972623191 Fix vendor paths without $XDG_DATA_DIRS
We'd use $__fish_data_dir, but that already had the "/fish" component,
and then we'd add it again later, so we would try to find vendor
functions in places like

/usr/share/fish/fish/vendor_functions.d

which obviously don't exist.

Instead let's add the "/fish" component to the xdg dirs early, which
also saves us from having to repeat it later.

Fixes #6428
See #6508

[ci skip]
2020-01-19 09:28:56 +01:00
Johannes Altmanninger
e3782603ec Load vendor configuration from $XDG_DATA_DIRS/vendor_*.d
$XDG_DATA_DIRS/vendor_{completions,conf,functions}.d
Additionally, CMake variables extra_{completions,conf,functions}dir are
appended, if they are not already contained in $XDG_DATA_DIRS.

If XDG_DATA_DIRS is not defined, we fall back to

$__fish_datadir/vendor_completions.d:${extra_completionsdir}

for completions. Same for conf and functions.
2020-01-12 16:12:41 +01:00
Johannes Altmanninger
0afc5258cf Unify detection of fish version upgrade with $__fish_initialized
This variable holds an integer that resembles the fish version up to
that initializations were performed. It should be incremented whenever
some new initialization is required after upgrading fish.  This should
not change the behavior for existing fish installations, except for a
minor message on installations that upgrade from fish<2.3.0.

[ci skip]
2019-12-30 14:00:22 +01:00
Klaus Alexander Seistrup
7046d251d9 Make sure nop command always suceeds 2019-08-03 18:14:12 +02:00
Tim Riley
d1be300ac7 Emulate path_helper more faithfully when constructing paths on macOS
Previously, elements already existing in the path variable would keep their position when the path was being constructed from the config files. This caused issues given that $PATH typically already contains "/usr/bin:/bin" when fish initializes within a macOS terminal app. In this case, these would keep their position at the front of the $PATH, even though the system path_helper configs explicitly place them _after_ other paths, like "/usr/local/bin". This would render binaries in "/usr/local/bin" as effectively "invisible" if they also happen to live in "/usr/bin" as well. This is not the intended

This change makes the __fish_macos_set_env config function emulate the macOS standard path_helper behavior more faithfully, with:

1. The path list being constructed *from scratch* based on the paths specified in the config files
2. Any distinct entries in the exist path environment variable being appended to this list
3. And then this list being used to *replace* the existing path environment variable

The result, for a vanilla fish shell on macOS, is that the $PATH is now set to:

    /usr/local/bin /usr/local/sbin /usr/bin /bin /usr/sbin /sbin

Where previously it was set to:

    /usr/bin /bin /usr/local/bin /usr/sbin /sbin

This new $PATH exactly matches the order of paths specified in `/etc/paths`.
2019-07-02 22:17:46 +02:00
Aaron Gyes
90547a861a __fish_macos_set_env: don't create empty PATH components
It was creating empty entries for blank lines, which will actually
create '.' for colon-separated vars

Fixes #5809
2019-04-11 02:52:18 -07:00
Fabian Homborg
7aaa3b8553
Keep the order for $PATH and $MANPATH when reading /etc/paths (#5767)
* Keep the order for $PATH and $MANPATH when reading /etc/paths

Fixes #5456.
2019-03-30 19:25:09 +01:00
Aaron Gyes
619a248a35 Clean up uvar initialization with a wrapper function
Adds __init_uvar
2019-02-14 17:09:16 -08:00
Fabian Homborg
13eb01bc97 share/config: Guard contains against options
Fixes #5662.

[ci skip]
2019-02-14 11:00:47 +01:00
Fabian Homborg
c5a6d0bfde Split $fish_user_paths on ":" explicitly
It's used with $PATH, so it is _always_ split on ":".

We could also force it to be a path variable, but that seems a bit
overkill.

Fixes #5594.
2019-02-13 12:35:15 +01:00
Andrew Childs
56309f1c2e Only invoke path_helper in login shells
Matches upstream path_helper which is invoked in /etc/profile and only
applies to login shells. Enables running interactive, non-login shells
with altered PATH values.

Reverts change in c0f832a7, which reverts change in adbaddf.
2019-02-13 00:02:03 -08:00
Aaron Gyes
1c6efc6378 'kill' is not a builtin.
I guess I was on autopilot.
2019-02-11 09:08:28 -08:00
Aaron Gyes
bcc4240d2b config.fish: Clean up the . function a bit. 2019-02-10 23:19:24 -08:00
Aaron Gyes
4d6a97d35c Retire the bit of config.fish that detected missing builtin string
It's been a few years.
2019-02-10 21:47:10 -08:00
Aaron Gyes
1c9fe71240 config.fish: loop over bg, fg, etc. wrappers
Now that we can do `builtin $x`, this code can be simplified.
2019-02-10 15:03:42 -08:00
Aaron Gyes
6b16975359 Add a colon to command-not-found dealio.
The previous commits to fix #5588 removed quoting.
2019-01-28 19:35:17 -08:00
Fabian Homborg
63c072e225 default_command_not_found_handler: Only use $argv[1]
That's probably the nicer fix, otherwise this would print things like

    Unknown command 'aiohsd 1 2 3'

when it should just say

    Unknown command aiohsd
2019-01-26 21:50:49 +01:00
Fabian Homborg
02628d1b02 default_command_not_found_handler: Join arguments
Without it, this would print the error multiple times, like

    Unknown command: echs
    Unknown command: 1
    Unknown command: 2
    Unknown command: 3

Fixes #5588.
2019-01-26 21:21:20 +01:00
Fabian Homborg
84339d5636 Don't wrap functions with themselves
Our weird %-expanding function wrappers around kill et all defined
"--wraps" for the same name.

As it turns out, fish follows that one, and executes the completion
multiple times.

I didn't notice because these tend to be rather quick on linux, but on
macOS that's apparently a real issue.

Fixes #5541.

[ci skip]
2019-01-17 09:46:55 +01:00
Fabian Homborg
04f1ea0680 share/config: Don't split /etc/paths entries on spaces
This used `read -la`, which _splits_.

Instead, don't do that, each line is its own entry.

Fixes #5481.

[ci skip]
2019-01-04 14:50:12 +01:00