This prints a description of the "host". Currently that's
`(chroot:debianchroot) $USER@$hostname`
with the chroot part when needed.
This also switches the default and terlar prompts to use it, the other
prompts have slightly different coloring or logic here.
Commit 5d135d555 (prompts: fix pipestatus for jobs prefixed with "not")
introduced a backwards compatibility hack about adding an optional argument
to __fish_print_pipestatus. This hack would break downgrading to fish 3.1.2
if the user copied the new prompt to their config - they would get a backtrace
on every prompt which is arguably worse than the patch's minor improvement.
This does away with the error trace - old fish just won't show the fancy
new pipestatus on `not true`.
Implemented by passing the last $status as the poor man's kwarg, which works
since 3.1.0 (9b86d5dd1 Export all local exported variables in a new scope).
The prompts don't work with fish 3.0.0 or older; downgrading does not seem
too important in general but I think this patch is an okay simplification.
These passed " [" to __fish_print_pipestatus as the left brace.
If the color contained a background, that would also color the space
in, leading to a weird unbalanced space before and none after.
Instead, prepend the whitespace when printing later.
[ci skip]
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
6902459566 was an attempt to not print
$status twice in the prompt. As a result we print $pipestatus but
not $status, which /usually/ is the same as $pipestatus[-1] --- unless
the builtin "not" is used, which inverts the $status of a job (it does
not alter $pipestatus).
As a result, the default prompt prints unexpected status codes:
~ > not false
~ [1]> not true
~ > not true | true
~ > not false | false
~ [1|1]>
This commit reintroduces printing of $status after $pipestatus, but only
if it is different from $pipestatus[-1].
Additionally, we only print anything at all if the $status is nonzero,
to avoid confusing output on `not false | false`
~ > not false
~ > not true
~ [0] 1> not true | true
~ [0|0] 1> not false | false
~ >
I think this is closer to users' expectations for those cases; they should
not have to think about this implementation detail of the not-statement.
It's now good enough to do so.
We don't allow grid-alignment:
```fish
complete -c foo -s b -l barnanana -a '(something)'
complete -c foo -s z -a '(something)'
```
becomes
```fish
complete -c foo -s b -l barnanana -a '(something)'
complete -c foo -s z -a '(something)'
```
It's just more trouble than it is worth.
The one part I'd change:
We align and/or'd parts of an if-condition with the in-block code:
```fish
if true
and false
dosomething
end
```
becomes
```fish
if true
and false
dosomething
end
```
but it's not used terribly much and if we ever fix it we can just
reindent.
This is part of our (well, my) quest to spice up the default prompt.
In this case we color the host if $SSH_TTY is set, which is easy to
detect and helps draw attention to the host.
See #6398.
See #6375.
This was mostly dead, since $fish_color_host is set to normal in
__fish_config_interactive. The assignment was only used if the user
explicitly unsets fish_color_host (which they shouldn't, really).
Anyway it's weird to use cyan, use normal instead.
[ci skip]
The colors are set in __fish_config_interactive before the prompt is
painted for the first time.
Also initialize the $fish_color_status for the (pipe) status, bump the
version for that.
[ci skip]
If a command fails, print the pipestatus in red instead of yellow and
don't print the status of the last process again. See #6375.
Also use $fish_color_status for coloring status consistently.
Also use __fish_pipestatus_with_signal to print SIGPIPE instead
of a numeric code on e.g.: yes | less +q
[ci skip]
I hate doing this but I am tired of touching a fish script as part of
some change and having `make style` radically change it. Which makes
editing fish scripts more painful than it needs to be. It is time to do
a wholesale reformatting of these scripts to conform to the documented
style as implemented by the `fish_indent` program.
# The first commit's message is:
Simplify default fish_prompt
No need for the set_color caching now that it's a builtin.
Also simplify the 3 classic prompts in fish_config's sample_prompts set.
Currently fish doesn't recognize toor as special. However, it's likely
that on BSD systems, fish shell will be used on toor, not on root (toor
is an intentionally existing account to use more advanced shell on, like
shell).