Because MacOS' apropos is bad and doesn't support the `--` option
separator, this apparently spews errors.
Because the argument _can't_ start with a `-` (because we add a `^`),
we can just remove it.
Fixes#7965.
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.
These were hard to read in the browser, but not in the terminal.
The palette in color.cpp lists #000080 for blue, which is *even darker*. I'm not sure if that's actually a thing - I was under the impression that table was taken from xterm.
Either way, listing it in this color doesn't do anyone any favors. It's just a rough approximation anyway.
Otherwise this has filesystem order, which on my system is quite
chaotic.
An alternative would be to randomize the order so people see different
prompts each time.
Some features:
- A nice `►` prompt char with a fallback for non-utf8 systems
- The $PWD is colored depending on its sha, so different directories
are colored differently, but each directory stays the same
- User@Host is only shown if not on the local machine (ssh or
virtualization)
- A right prompt with a nice git display, date, duration of the last
command (if it took over 100ms), and virtualenv
This gets fish to print the right prompt of any sample if it has any,
and then shows it separately.
If there is a right prompt, it will also save it. If not, it will *not* overwrite an existing right prompt.
This called `uname` just to check if we *should* shorten "cygdrive"
directories.
That's more annoying than just doing it by default - on my system `pwd
| string replace` takes about 100 *micro*seconds, and this is done
once per prompt. Anyway, using $PWD further speeds it up to ~30
microseconds (compared to 10-20 for just `pwd`). This is hard to
measure because it's heavily impacted by system hitter.
The alternative is to ask cygwin to ship this feature as a patch.
Complete RPM files instead of pacakges if there is either
1. a slash in the token, which precludes package names
2. no matching package
To enable 2, pass the commandline token to the dnf query, instead of
an undefined variable. This allows SQL injection; not sure if we care.
We could always complete RPM files but maybe that's too noisy.
Also, isn't that what the "rpm" command is for?
Closes#7928
Fixes#7926.
Also switches the default status order for non-informative to the informative one:
stagedstate invalidstate dirtystate untrackedfiles stashstate
instead of
dirty staged stash untracked
This should be a simple prompt that doesn't place a huge strain on the
system but communicates the most important information simply and
effectively.
It should be a good jumping off point for making your own prompt.
Unless that person directly contributed the prompt.
We name them after a feature - the Scales prompt feature a ">>>" which
kinda looks like fish scales, the "Arrow" prompt starts with a
prominent "➜".
Naming them after people looks like an endorsement of that particular
person, and like they are someone to look up to, especially when they
aren't involved with the project.
The "terlar" and "acidhub" prompts stay for now because they
contributed the prompt themselves, they are also much less prominent.
The "classic" prompts are all just variations on a theme, let's just
keep the default classic+vcs.
"Justadollar" is very unlikely to be what you want and also trivial to
write yourself.
I have no idea what screen_savvy even is for - it reacts to "$WINDOW",
but I don't know anything that even uses that variable.
Lonetwin is just unremarkable, and the debian chroot prompt has one special feature that should be integrated into the other prompts.
Because macOS' `apropos` is just using grep, and we only need
a prefix match for __fish_describe_command, we can shave off
some ok total execution time here.
No longer uses the __fish_apropos hack on every version of macOS.
Juat Catalina+.
The whatis database generated and replaced daily is 2 megabytes on
my computer, and in ~/.cache on a home dir might wind up on a net
mount or something annoying. or, definitely it's backed up by default.
It's wiser to throw that junk in with other cache files on the system
aka DARWIN_USER_CACHE_DIR, and only use the XDG directory if
someone specifically configured that.
Mainly, this just means at least it won't automatically get backed
up by Time Machine and stuff every day, which is no big deal but
y'know...
Rearranged stuff a little to not shell out every time.
The default vi mode prompt is kind of ugly, mostly because we include
this `[I]` with a super bright green background and white text,
which is particularly grating because most prompts don't actually have
a background.
So we get a ton of people asking "How do I remove this [I]" when they
could really benefit from having the mode shown.
There's a few ways to make this look nicer, the simplest is to just
keep the same colors but use them as foreground instead of background
colors, which looks much more understated.
The mode prompt is important, but not more than the actual contents of
the commandline, so it shouldn't have ALARMING colors.
This allows us to stop descending into untracked directories, which
can be faster.
It's still not *good* - git can still be quite slow here, but if
there's an untracked directory you probably don't care about the
number of files in that.
Fixes#7871.
This is all of the sections in interactive, language and for_bash_users.
The faq names are so long that we're not adding them, also not all of
these have descriptions yet.
Given that we no longer have that massive "index" page with
everything, it's become harder to open the correct section
immediately.
So this hardcodes the section titles for each page in help itself.
This was half-automated with
grep -o 'a class="headerlink" href="#[^"]*"' /usr/share/doc/fish/faq.html | sort -u | string replace -r '.*#' '' | string trim -c '"'
The completions still need to be adjusted.
In vim p means paste *after* current character, so go forward a char before pasting.
Also in vim, P means paste *at* current position (like at '|' with cursor = line),
so there's no need to go back a char, just paste it without moving.
Prior to this commit "builtin -h" would silently fail when no
documentation is installed. This happens when running fish without
installing it, or when the docs are not installed.
See #7824
After a fish installation is upgraded to 3.2.0, active shells could
throw an error attempting to load Git completions. It's just a
transient error but also easily avoidable by using the old style.
See #7822
Previously, this message told the user to "set $BROWSER and try again". However,
when I first saw this error, I didn't know how I can set `BROWSER` in fish. Moreover,
I often see this error in situations when no browser will work. For instance, I might be
using fish over ssh, and I might either not know whether that system has a text-mode
browser installed or not want to use it.
A further improvement would be to report this message if a browser fails to start.
This actually *worked* in my tests which confuses me.
It really shouldn't, `apropos -foo` will complain about "-o" not being
a valid option.
It should be `apropos -- -foo`.
Now, of course there are awful apropos implementations, so let's see
if someone complains
When `fish` is running in the Chrome OS Linux VM (Crostini),
both `help` and `fish_config` opened a "file not found"
page. That is because on Crostini, `BROWSER` is usually set to
`garcon-url-handler`, which opens URLs in the host OS Chrome
browser. That browser lacks access to the Linux file system.
This commit fixes these commands. `help` now opens the URL on
www.fishshell.com. `fish_config` now opens the URL for the
server it starts. Previously, it opened a local file that
redirects to the same URL.
In the case of `help`, the situation could be improved further
by starting a web server to serve help. I don't know of another
way to access `/share/fish` from outside the VM without user
intervention, and I think that might be a part of the security
model for the Crostini VM.
It's hard to write a test for this. I checked that `help math`,
`python2 webconfig.py`, and `python3 webconfig.py` work on my
machine running in Crostini.
This was a handler for various prompt variables that called a repaint.
Unfortunately, if you set one of those *inside* the prompt (a logical
place for it), this would lead to something like #7775.
So, because this isn't actually *useful* as far as I can see (how do
you set these variables in a way that you're not already inside a
prompt or about to draw a prompt? in a key binding?), we remove it,
like we removed the repaint from git's variable handlers.
This `set -e` had a cartesian product that caused it to remove the
indexes separately, so the later indexes were off - removing the first
and then the second ends up removing the first and then the
old-*third* which is now the second.
Just quote the expansion so it runs in one go.
Fixes#7776
Because we removed repaint coalescing, currently setting any of the
git prompt variables in fish_prompt leads to a repaint loop (that
presumably aborts once it reaches the recursion limit).
Since repainting on these variables isn't really useful (when you
`set` them interactively you already get a new prompt), just remove
it.
There's two cases this "breaks":
- When you set a variable *after* the call to fish_git_prompt
- When you set a variable via a binding
In both of these it's not too much to expect an explicit "commandline
-f repaint", especially since for bindings that's already needed in
most cases, and setting a variable after using it isn't normal.
Fixes#7775.
Called as
__fish_print_pipestatus "[foo" "oof]" "|" (set_color green) (set_color --bold blue) 0 1 2
it would make the closing `oof]` bold green.
Fixes#7771.
* Ensure web_config works on WSL
web_config could sometimes fail on WSL if the user chose not to append
windows directories to their linux $PATH. This change ensures that the
cmd.exe executable is found in most cases even if windows directories
are not appended to $PATH on linux.
An error message letting the user know that cmd.exe was not found, and
that they should add the cmd.exe dir to their $PATH before running
fish_config is displayed if cmd.exe is still not found.
* Exit with a non 0 status code if cmd.exe is not found
In this context, as it stands, $last_pid will give fish's pid (because
of pgroup shenanigans).
Since that doesn't really work, just `disown` without and let fish
figure out what the last process was.
Theoretically this has an issue if someone started a background
process *before* the python script *and* that exits before we run
disown.
That's a vanishingly small window and this is only run on first start,
so it seems acceptable.
Fixes#7739.
This still showed the background gradient, which is just a waste and
looks weird.
Instead make the actual content fullscreen (except for the border
radius, for now)
When pasting a multiline command with indented blocks, extra indentation
from spaces, or tabs, is generally undesirable, because fish already indents
pipes and blocks. Discard the indentation unless the cursor or the pasted
part is inside quotes.
Users who copied fish_clipboard_paste need to update it because
__fish_commandline_is_singlequoted had an API change and was renamed.
I ran into problems described in https://github.com/fish-shell/fish-shell/issues/718 when using this prompt. This seems to be a bug in the prompt -- this change fixes it, at least on my system.
I tried this in tmux (TERM=screen) and gnome-terminal (TERM=xterm-256) with fish 3.1.2, on Linux.
__fish_print_commands just prints the commands we have man pages for,
and help uses that to figure out whether it should link
a command or a section. If the docs aren't installed it won't find
anything.
At least check the builtins, because we document them and it's easy.
This probably needs to be added at build time - glob
doc_src/cmds/*.rst.
Some third party Git tools provide a man page, which we can at least use
for completing options.
The old logic excluded all generated completions for Git subcommands.
Instead, try to load completions for all available external subcommands.
We can use $PATH/git-* because /bin/git-add and friends were removed in Git
1.6.0 in 2008.
Closes#4358 (the "git-foo" wrapping was added in #7652)
This was only a thing in cygwin, and only a workaround because
cygwin's hostname was broken in 2013 and our sample prompts called it,
which caused errors in fish_config.
Our sample prompts no longer call `hostname` at all (they use
`prompt_hostname`, which uses the variable), and it's possible
cygwin's hostname was fixed in the meantime.
Fixes#7669.
* completions/userdbctl: init
userdbctl:
Show user and group information.
A part of systemd.
* completions/userdbctl: fix complete services
Complete the services at the completion time.
This goes to a separate file because that makes option parsing easier
and allows profiling both at the same time.
The "normal" profile now contains only the profile data of the actual
run, which is much more useful - you can now profile a function by
running
fish -C 'source /path/to/thing' --profile /tmp/thefunction.prof -c 'thefunction'
and won't need to filter out extraneous information.
We were soucing it manually, and implicitly via the `complete -C "git-foo "`
wrapper. Always use the latter, so fish knows that the completion is already
loaded.
This had a classic float:left layout, which led to awkward gaps and
stuff.
Since what we want here is basically 100% exactly a flexbox, just use that.
Note: No flexbox for the prompts, atm, because having multiple of
those next to each other looks a bit weird.
Since #7075, git-foo.fish files are sourced when Git completions are loaded.
However, at least Cobra (CLI framework for Go) provides completions like
complete git-foo ...
This means that completions are only offered when typing "git-foo <TAB>"
and not on "git foo <TAB>". Fix this by forwarding the completion requests.
Take care to only forward if there are actually completions for "git-foo",
to avoid adding filename completions.
Over in https://github.com/wez/wezterm/issues/115#issuecomment-765869705 one of my users noted that fish had automatic OSC 7, but that it wasn't enabled under WezTerm.
You can detect WezTerm through the `$TERM_PROGRAM` environment. In practical terms, all versions of wezterm in the wild support OSC 7 so a version check is not needed.
I'm not a fish user myself, but I did give the equivalent change to this a try on my Fedora 33 machine (it has an older version of fish).
I can see in this file that there's some stuff with `__fish_enable_focus` that you may also want to enable under wezterm; the escape sequence is supported as are panes, tabs and windows.
* Include completion for all pkg alias subcommands
* Formatting and dynamic evaluation of alias subcommands
* only set package_name completion once
* fixed syntax error
Fix 1: The --quiet flag must be at the end of the command. The way it was I would never get any status symbol in my prompt as the command failed.
Fix 2: After adding files to git, but before committing them, git status is unsorted. This gave me the output "M A M A" after `uniq`, which resulted in 4 status symbols instead of 2. Sorting them before filtering them fixed the problem.
As mentioned in 5b706faa73, bare
`disown` has a problem: It disowns the last *existing* job.
Unfortunately, it's easy to see cases where that won't happen:
sleep 5m &
/bin/true & # will exit immediately
disown # will most likely disown *sleep*, not true
So what we do is to pass $last_pid.
In help especially this is likely to occur because many graphical
browsers fork immediately to avoid blocking the terminal (we only
added the backgrounding and disown because some weren't).
Note that it's *possible* this doesn't occur if used in the same
function, but I don't want to rely on those semantics.
It might be worth doing this as the default - see #7210.
This is mildly useful when activating virtualenvs. We had remove
these files earlier, but since there are no more false negatives from
__fish_complete_suffix it seems safe to re-add them.
0507b04 loosened the FreeBSD-only restriction on `pkg` completions to
!SunOS in order to support DragonFlyBSD. This is overly broad and can
still cause the script to be loaded on systems that we can't
realistically expect to have `pkg` be the FreeBSD pkgng package manager
(especially since `pkg` is a much more generic term when compared to the
likes of `dnf`, `yum`, `deb`, and `apt`).
This patch changes `pkg` + BSD to be the minimum requirements for
considering a system to be using pkgng.
This allows for multiple edits to be undone/redone in one go, as if they
were one edit.
Useful when a function is editing the commandline buffer via scripted
changes or via a keybinding so the internal changes to the buffer can be
abstracted away.
(Having extreme difficulty getting pexpect to play nice with the concept
of undo/redo...)
In e8b6705067 this was made to exit if
not on FreeBSD because Solaris has a tool called "pkg" that apparently
"isn't worth supporting".
Since at least DragonflyBSD also uses FreeBSD's pkg thing, let's turn
that check around.
There's a macOS bug with Source Code Pro that makes it unable to be
colored. Since that makes webconfig unusable, stop recommending it.
Instead, we just pick the default monospace font for the system.
This is slated for removal in python 3.10, see
https://www.python.org/dev/peps/pep-0594/#cgi.
We currently only use it for three things:
- escape_html in old python versions that didn't have that in the html
module
- Parsing multipart/form-data
- Figuring out the charset for json
We keep the first one - if loading escape_html from html fails we fall
back to cgi.
We remove the second - I can't find any case where we use
multipart/form-data. Any place we post data we either explicitly pass
application/x-www-form-urlencoded or implicitly use application/json.
The third is the tricky bit. This drops charset detection under the
assumption that we're never going to encounter anything other than
utf-8 (or ascii, which is a utf-8 subset). I'm not sure that holds,
but if it doesn't we can just add a regex to parse the charset.
These used a different object format, so they were passed to
interpret_color wrong.
Because the "common" and "syntax" division doesn't really help all
that much, let's just flatten the thing.
See #7596.
It also reflows.
We might want to think about doing something more extensible here, as
konsole is also about to add reflow, but for now the main problem
children here are VTE and alacritty.
Extends #7491.
Of note: The rpm/yum thing seems to be coupled, so I put it into one
function that tries the yum helper and uses the rpm path otherwise.
Zypper is already its own thing, so this should only be used for yum
and probably dnf (does that still have the helper?)
Zypper can be dropped, as that already used a separate function in the file.
Apk can just be inlined - it's literally one line for installed and another for all packages.
This function doesn't make any sense.
Most things that expect package names expect package names for *one
specific package manager*.
It only happens to work, most of the time, because most people only
have one package manager installed.
Trying to switch to a remote branch like "upstream/ver2" will error with "fatal: a branch is expected, got remote branch 'upstream/ver2'", so these completions should only print the branch name. There doesn't seem to be a function for printing just the branch names for remotes (branch names can have forward-slashes in them), so I have just left them out for now.
This can use files/directories in a variety of ways, and it's
basically impossible to enumerate all of them - basically *any file*
could be mounted, if only there is a filesystem for it.
We still give the blockdevices and predefined mountpoints, so they can
still be used.
And again clang-format does something I don't like:
- if (found != end && std::strncmp(found->name, name, len) == 0 && found->name[len] == 0) return found;
+ if (found != end && std::strncmp(found->name, name, len) == 0 && found->name[len] == 0)
+ return found;
I *know* this is a bit of a long line. I would still quite like having
no brace-less multi-line if *ever*. Either put the body on the same
line, or add braces.
Blergh
At least on Arch Linux, pacmd and pulseaudio aren't necessarily available just because pactl is (pipewire is now a thing, and it installs libpulse but not pulseaudio)
Just copy that "find an executable" code we already have,
the one that was commented with "oh, btw, distutils.spawn.find_executable is bad",
and use it here as well.
Work towards #7514.
The code to override the `(status current-command) was present`, but not
handled in either the default `fish_title` function or the fallback.
Closes#7444.
Use the `-d` parameter to `zfs list` to limit snapshots to the dataset
named in the current token being completed. Thanks to @Debilski for the
tip.
Closes#7472
Only generate the list of snapshots when
a) the argument must be a snapshot and nothing else, or
b) the argument as typed contains a literal @, or
c) a snapshot is a valid completion and there is only one dataset
matching the argument as entered.
Unfortunately, it seems the `zfs` command itself is extremely primitive
and doesn't support listing snapshots by dataset so when we need to
generate completions, we end up needing to enumerate all snapshots
(ever) across all datasets. I'd be very happy to be proven wrong, but I
think the only other way would be manually parse `zdb` output.
See #7472
- clip.exe is used to copy to the Windows clipboard
- There's no binary for pasting from the Windows clipboard so
`Get-Clipboard` from powershell is used as a workaround. The
superflous carriage return is stripped from the output.
This is super cheesy.
One of the most common feature requests we get is "control-r must
search", even tho just using history-search-backward via e.g. up-arrow
is perfectly capable. The only real difference is that ctrl-r search
in other shells allows editing the search term by default, while we
stop the history search and edit the new commandline in those cases.
So, since the major problem is muscle-memory on ctrl-r,
let's just use that!
This makes ctrl-r do nothing on empty commandlines, and do
history-search-backward otherwise, so the basic flow of "press ctrl-r
to start history search, enter your search term, press ctrl-r to cycle
through matches" just works (except the first ctrl-r is useless and it
doesn't show anything).
See #602.
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
These aliases seem to be common, see #7389 and others. This prevents
recursion on that example, so `alias ssh "env TERM=screen ssh"` will just
have the same completions as ssh.
Checking the last token is a heuristic which hopefully works for most
cases. Users are encouraged to use functions instead of aliases.
This prevents a seemingly infinite loop in
fish -c 'alias ssh "env ssh"; complete -C "ssh "'
It still prints "maximum recursion depth exceeded", but a follow-up commit
will work around that.
Fixes#7389
In the new __fish_apropos, makewhatis is run explicitly to generate the
whatis database. However this can be a little slow. Run it in the
background, after the apropos call completes so as to avoid a weird
race.
This means that descriptions may not be available the first time the
user invokes it, but that's better than appearing to hang for a while.
override MANPATH used by apropos with local whatis database and update it once a day
get rid of xargs
Created __fish_apropos and fixed __fish_complete_man to use that as well
moved macos apropos comment
If the padding is not divisible by the char's width without remainder,
we pad the remainder with spaces, so the total width of the output is correct.
Also add completions, changelog entry, adjust documentation, add examples
with emoji and some tests. Apply some minor style nitpicks and avoid extra
allocations of the input strings.
This was a wrapper around status_to_signal, just because that only
handled a single argument.
Instead, just teach status_to_signal to handle multiple arguments and
be done.
This is too important to not be one.
For one if it couldn't be loaded for any reason it would
break a lot of fish scripts.
Also this is faster by ~20x.
Fixes#7342
"function --argument" is not a thing, it's "--argument-names". This only
accidentally works because our getopt is awful and allows abbreviated
long options.
Similarly, one argparse test used "--d" instead of "-d" or "--def".
When pressing \ep on an empty commandline, the cursor would stay at the
beginning of the commandline. Move it to the end of the previous command,
this feels a bit more natural.
The case for symlinked directories being duplicated a lot isn't there,
but there *is* a usecase for adding the symlink rather than the
target, and that's homebrew.
E.g. homebrew installs ruby into /usr/local/Cellar/ruby/2.7.1_2/bin,
and links to it from /usr/local/opt/ruby/bin. If we add the target, we
would miss updates.
Having path entries that point to the same location isn't a big
problem - it's a path lookup, so it takes a teensy bit longer. The
canonicalization is mainly so paths don't end up duplicated via weird
spelling and so relative paths can be used.
Since version 5 (IIRC), pacman has a file database.
This is useful for people who don't have pkgfile, but we still prefer
that because it's much faster - pacman takes a full *second* on my system.
This could lead to an infinite loop (well, stack overflow) because
fish_command_not_found would also be defined to call
__fish_command_not_found_handler.
Since this is for
- missing command errors
- when downgrading
we can just remove it.
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.
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.
Just a skeleton completion file, but the list of available
actions/completions is at least dynamically generated (there's a lot of
them, they are impossible to remember, and they depend on build
options).
[ci skip]
Now command, jobs, type, abbr, builtin, functions and set take `-q` to
query for existence, but the long option is inconsistent.
The first three use `--quiet`, the latter use `--query`. Add `--query`
to the first three, but keep `--quiet` around.
Fixes#7276.
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.