This was always awkward as fish script, and had problems with
interrupting the autoloading.
Note that we still leave the old function intact to facilitate easier
upgrading for now.
Fixes#7145.
Add a helper function to check if the user is root. This function can be
useful for the prompts for example. Modify the prompts made root checked
to use the function instead. Add also the support of Administrator like
a root user.
Fixes: #7031
* docs/faq: Mention prepend_sudo
[ci skip]
* __fish_prepend_sudo: Use $history[1] if commandline is empty
Currently, if you press alt+s with an empty commandline, it inserts
"sudo", which seems fairly useless.
Now, it inserts "sudo " followed by the last history entry, which
makes it a replacement for `sudo !!`.
* docs
There's a terrible number of fishscripts that start with
set path (dirname (status filename))
And that's really just a bit boring.
So let's let it be
set path (status dirname)
* Add an "_" builtin to call into gettext
We already have gettext in C++ (if available), so it seems weird to
fork off a command to start it from script.
This is only for fish's own translations. There's no way to call into
other catalogs, it just translates all arguments separately.
This is faster by a factor of ~1000, which allows us to call
translations much more, especially from scripts.
E.g. making fish_greeting global by default would hurt cost-wise,
given that my fish starts up in 8ms and just calling the current `_`
function takes 2ms, and that would have two calls.
Incidentally, this also makes us rely on a weirdly defined function
less, so it:
Fixes#6804.
* docs: Add `_` docs
Let's see if that filename works out.
* Reword _ docs
This is a function you can either execute once, interactively, or
stick in config.fish, and it will do the right thing.
Some options are included to choose some slightly different behavior,
like setting $PATH directly instead of $fish_user_paths, or moving
already existing components to the front/back instead of ignoring
them, or appending new components instead of prepending them.
The defaults were chosen because they are the most safe, and
especially because they allow it to be idempotent - running it again
and again and again won't change anything, it won't even run the
actual `set` because it skips that if all components are already in.
Fixes#6960.