Fixes#6798
This re-adds some false positives: functions, builtins and abbreviations
are suggested after commands like sudo but I don't think anyone had
complained about that.
Many people have mentioned wanting support for changing / yanking /
deleting between "" and '', meaning the commands `ci' ci" yi' yi" di' di"`,
so this adds that support in a generic, and thus potentially confusing way.
The concept is that we check for the character backwards and forwards
before making the selection. Unfortunately, this will also work for *any*
character that isn't `w` or `W`, so `cia` could change everything between
two `a` characters.
Looking through the [bind documentation](https://fishshell.com/docs/current/cmds/bind.html)
and input handler at `src/input.cpp`,
this is the best possible solution I could come up with until
`forward-jump` and `backward-jump` can accept input in the call to `bind`,
and not just from stdin, meaning we can write a binding as:
```
bind di\" backward-jump-till \" and repeat-jump-reverse ...`
```
If that were done, then other commands such as `di)` to go between `()` would
be possible.
There are also some added `y` bindings not part of #6648.
Let me know if you need anything else.
This reverts commit 7f402cdae7.
There are fundamental issues with `funced` and `funcsave` that prevent
this from working. A file and a function are not interchangeable.
Add completions for `downgrade` tool
Add new `--installed` option for printing Arch packages
Change Arch Linux package related completions to use `--installed`
add newline
The output of
systemctl list-units
seems to include a marker of '●' or '*' for some units, even if the
output is not going to a terminal and "--no-legend" and "--no-pager"
are given. This appears
to be a recent development, and there does not appear to be a flag to
disable it.
So we simply filter it out in the completions to once again hopefully
offer the actual units.
Fixes#6740
Even if $DISPLAY is unset, xdg-open can be useful, and on systems that
have xdg-open, "open" is most likely some god awful outdated thing
called "openvt" elsewhere.
Fixes#6739
[ci skip]
Fixes#6138
Naturally this does not work for many other editors/aliases,
but it's still nice that we can make it work for some common
editors without requiring any configuration.
Of course this approach is not terribly flexible; but it's
alwyas possible to just wrap edit_command_buffer and set an
EDITOR that knows about the cursor position. It doesn't
feel important enough to add a configuration option.
The default hg prompt is slow on large repositories (hg status takes
2-3 seconds on mozilla-central) which is unacceptable as a default.
Mimick our git prompt: by default, only show the current branch.
If the new variable $fish_prompt_hg_show_informative_status is set,
then use the old behavior.
[ci skip]
This is apparently quite slow on large svn repos (like 40 seconds
slow), and we don't have a good thing to display other than the full
file information.
So we'll have to disable it for now.
Fixes#6681.
[ci skip]
Mimic the behavior of Linux's `apropos -e` and ~BSD's `apropos -f` with
the awk script by disallowing trailing characters in the name of the
manpage as compared to the original input string. Apart from being
faster (by aborting earlier and stopping `apropos` by breaking the pipe
after the first match), it's also more correct.
Mostly line breaks, one instance of tabs!
For some reason clang-format insists on two spaces before a same-line comment?
(I continue to be unimpressed with super-strict line length limits,
but I continue to believe in automatic styling, so it is what it is)
[ci skip]
Add the input function undo which is bound to `\c_` (control + / on
some terminals). Redoing the most recent chain of undos is supported,
redo is bound to `\e/` for now.
Closes#1367.
This approach should not have the issues discussed in #5897.
Every single modification to the commandline can be undone individually,
except for adjacent single-character inserts, which are coalesced,
so they can be reverted with a single undo. Coalescing is not done for
space characters, so each word can be undone separately.
When moving between history search entries, only the current history
search entry is reachable via the undo history. This allows to go back
to the original search string with a single undo, or by pressing the
escape key.
Similarly, when moving between pager entries, only the most recent
selection in the pager can be undone.
Same issue occurs here, as in #6270 (and fixed in 611a658 for `__fish_describe_command.fish`). Same reason. I've just copied the same workaround and changed the function name to match.
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.
At the moment the "prepend sudo" functionality always sets the cursor to
the end of the line. This changes it to restore the relative position of
the cursor.
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.
We just do a cheesy version check and hope it works out.
If this is fixed in 10.15.4, we have to reenable it. If it still isn't
fixed in 10.16, we need to adjust it.
Fixes#6270
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 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]
This use of eval is unsafe, not really all that useful and can spew
errors that can't be suppressed. So let's remove it, and in future add
a thing that can do expansions in a safe manner
Fixes#6456.
"-C" is short for "--case-sensitive", which is entirely okay with "--delete".
The one that isn't okay is "-X", which is short for "--Clear".
Seen on gitter.im
This prefixes files beginning with `-` with a `./` when generating
completions *in fish code*. Standard completions for directory listings
generated by the C++ directory traversal code are not afected by this
patch.
Most fish completions defer to `__fish_complete_suffix` to generate the
file/directory completions, these *will* be corrected.
* Make `type -p` and `type -P` behave as documented
* Recognize `-` as an additional sign of no path
Functions created via `source` (like by `alias`) cause `functions --details` to return `-`
rather than `stdin` when invoked upon them.
* Add the `--succinct` flag to `type`
* Use `echo` rather than `printf`
* Change `succinct` to `short`; print path if known
* Clean up the printing logic ever so slightly
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]
(command pwd) uses the system's implementation of pwd. At least the GNU
coreutils implementation defaults to -P, which resulted in symlinks being
expanded when switching between directories with nextd/prevd.
This did some weird unescaping to try to extract the first word.
So we're now more likely to be *correct*, and the alias benchmark is
about 20% *faster*.
Call it a win-win.
Fix 'string length: Unknown option': add `--` before $subcommand
Fix count $subcommand always = 1 with `sudo` and `doas`:
give argv as array to __fish_complete_subcommand
[ci skip]
This mostly fixes some wrong indents or replaces some stray tab indents.
I excluded alignment on purpose, because we have a whole bunch of code
that goes like
```fish
complete -c foo -n 'some-condition' -l someoption
complete -c foo -n 'some-longer-condition' -l someotheroption
```
and changing it seems like a larger thing and would include more
thrashing.
See #3622.
This would have prevented #6323.
While we don't want to pepper `command` everywhere, `psub` is kind of
a core thing, so we should try to proof it against common problems.
This reverts commit f620ddf03b.
Setting the paste handler isn't performance-sensitive.
On the other hand setting it this way makes things less transparent,
less flexible (if e.g. a paste handler is installed while the shell is running),
and causes #6286.
Fixes#6286.
[ci skip]
Presently the completion engine ignores builtins that are part of the
fish syntax. This can be a problem when completing a string that was
based on the output of `commandline -p`. This changes completions to
treat these builtins like any other command.
This also disables generic (filename) completion inside comments and
after strings that do not tokenize.
Additionally, comments are stripped off the output of `commandline -p`.
Fixes#5415Fixes#2705
This just makes more sense, as people don't want to enter exact
matches if they delete interactively.
It also brings it in line with "search".
Fixes#6142
Rejects #6070
MacOS Catalina apparently ships a stripped down svn that doesn't have
`svnversion`, which we use to print the revision.
For now skip the entire step to remove error spam.
Fixes#6267.
[ci skip]
Every builtin or function shipped with fish supports flag -h or --help to
print a slightly condensed version of its manpage.
Some of those help messages are longer than a typical screen;
this commit pipes the help to a pager to make it easier to read.
As in other places in fish we assume that either $PAGER or "less" is a
valid pager and use that.
In three places (error messages for bg, break and continue) the help is
printed to stderr instead of stdout. To make sure the error message is
visible in the pager, we pass it to builtin_print_help, every call of which
needs to be updated.
Fixes#6227
* functions/__fish_print_hostnames: Fix ssh_configs no values return
`string replace` not working with mutlilines variable.
So split per line first.
* functions/__fish_print_hostnames: remove quotes at `split '\n'`
"\n with quotes" will cause `string split` weird issues.
* functions/__fish_print_hostnames: using `read -alz -d \n`
Fix `$contents` issues together
Corrects #6110
BSD `seq` produces a down-counting sequence when the second argument is
smaller than the first, e.g.:
$ seq 2 1
2
1
$
While GNU `seq` produces no output at all:
$ seq 2 1
$
To accommodate for this behavior, only run `seq` when we are sure that
the second argument is greater than or equal to the first (in this case,
the second argument `line_count` should be greater than 1).
Revert "gut gpg.fish/gpg1.fish/gpg2.fish; migrate functionality to __fish_complete_gpg.fish"
This reverts commit d558218d03.
Revert "break version-specific completions out into independent function;"
This reverts commit 9160e77b01.
Revert "split gpg2- and gpg1-specific completions to conditional block"
This reverts commit a069b95f63.
* Fix default Alt+W keybinding
The old keybinding would chop off the last line of the `whatis` output
when using a multi-line prompt. This fix corrects that.
* Make variable local and remove unneeded if statement
* Test that token is non-empty
Reproducer: type `: \<RET><M-p>`. This used to print an error due to builtin test receiving
too many arguments.
It looks like (commandline -j) can return multiple items, because a job can be broken up in multiple
lines terminated by backslashes.
With the new support for self-insert inserting a bound sequence,
the default binding for space as expanding abbreviations can be simplified
to just `self-insert expand-abbr`. This also fixes the bug where space
would cancel pager search.
By not manipulating each line or even each file at a time, we can go
back to `string` and piece together a pipeline that will execute
significantly faster than shelling out to `awk` will. This also removes
one of the few dependencies on `awk` in the codebase.
With this change, `__fish_print_hostnames` now finishes ~80% faster than
it used to a few commits back.
Reordering the `getent hosts` and read from `/etc/hosts` combined with
minimizing shelling and job invocations for parsing the output results
in a profiled and benchmarked ~42% decrease in the time it takes to run,
and that's on a machine with a very small hosts list in the first place.
This update also fixes the hadling of IPv6 addresses in the hosts
output, which were previously ignored, and ignores 127.* loopback
addresses in addition to the 0.0.0.0 address (plus adds support for
shorter IPv4 notations).
$__fish_git_prompt_use_informative_chars will use the informative
chars without requiring informative mode (which is really frickin'
slow!).
See #5726.
[ci skip]
This previously effectively checked `string split ' '`s return status,
which was false if it didn't split anything. And while that should be
true if getent fails (because it should produce no output), it's also
true if it doesn't print a line with multiple aliases. Which should be
fairly typical.
Instead we use our new-found $pipestatus to check what getent returns,
in the assumption that it'll fail if it doesn't support hosts.
Follow up to 8f7a47547e.
[ci skip]
`getent hosts` is expensive-ish - ~50ms, so we don't want to run it
twice just to figure out it works.
Apparently this works everywhere but CYGWIN and possibly older
OpenBSD, but we don't want to explicitly blacklist those.
[ci skip]
If you changed $__fish_git_prompt_show_informative_status, it
triggered a variable handler, which erased the chars, but neglected to
unset $___fish_git_prompt_init, so we just kept chugging along with
empty characters.
What's the hardest thing in CS again? Cache something something?
[ci skip]
This way we use our core file completion code, which is much more
flexible than we can easily achieve directly in script (which would
require e.g. an `expand` builtin, and case-insensitive globs).
Fixes#5896.
This was quite famously rather complicated.
We drop a bunch of cases - we can't handle tmux-starting-terminals
100% accurately, so we just don't try. It should be quite rare that
somebody starts a different terminal from tmux.
We drop the `tput` since it is useless (like terminfo in general for
feature-detection, because everyone claims to be xterm).
So we just check if we are in konsole, iTerm, vte or genuine-xterm.
Fixes#3696.
See #3481.
This runs build_tools/style.fish, which runs clang-format on C++, fish_indent on fish and (new) black on python.
If anything is wrong with the formatting, we should fix the tools, but automated formatting is worth it.
Dealing with macOS output in a fast manner using `string` is surprisingly hard, given that it features lines like
gls(1), ls(1) - list directory contents
Printing the "gls" with the description and the "ls" with the description requires a `while read` loop, and that's too slow.
This reverts commit 7784a5f23c.
[ci skip]
I did not realize builtins could safely call into the parser and inject
jobs during execution. This is much cleaner than hacking around the
required shape of a plain_statement.
* Honour `dirprev` scope
Honour the scope of the `dirprev` variable if it is universal
and avoid to shadow it with a global. This enables to share
the `cd` history between sessions.
* Honor dirnext and __fish_cd_direction scope
If these variables exist in the universal scope, do not shadow them
`eval` has always been implemented as a function, which was always a bit
of a hack that caused some issues such as triggering the creation of a
new scope. This turns `eval` into a decorator.
The scoping issues with eval prevented it from being usable to actually
implement other shell components in fish script, such as the problems
described in #4442, which should now no longer be the case.
Closes#4443.
If we switch the bind mode, we add a "force-repaint" there just to
redraw the mode indicator.
That's quite wasteful and annoying, considering that sometimes the prompt can take
half a second.
So we add a "repaint-mode" function that just reexecutes the
mode-prompt and uses the cached values for the others.
Fixes#5783.
* Add "expand-abbr" bind function
This can be used to explictly allow expanding abbreviations.
* Make expanding abbr explicit
NOTE: This accepts them for space only, we currently also do it for \n
and \r.
* Remove now dead code
We no longer trigger an abbr implicitly, so we can remove the code
that does it.
* Fix comment
[ci skip]
This searched for package.json in any parent, so just like finding
.git and .hg directories it _needs_ to use the physical pwd because
that's what git/hg/yarn use.
In general, if you do _any_ logic on $PWD, it should be the physical
path. Logical $PWD is basically only good for display and cd-ing
around with symlinks.
[ci skip]
This called `eval $fish_browser --version` to figure out if it is
lynx.
That's really not worth it just to support edge-cases using a rather
unusual browser, to work around a bug in it.
Instead we just see if the browser name starts with "lynx", which
should work in 99.9% of cases.
This created another local version of the variable just for the if-block.
Can't say I love the space prefix, but then I think we have too many
of these modes anyway.
If you use these to figure out if there _are_ staged files, or dirty
or whatever, you currently need to check the output, which relies on
the configured character.
Instead, we let them also return a useful status.
Notably, this is *not* simply the status of the git call.
__fish_git_prompt_X returns 0 if the repo is X.
This works for untracked, but the "diff" things return 1 if there is a
diff, so we invert the status for them.
See #5748.
[ci skip]
A function file for a function used only by one completion (and
unlikely to be used anywhere else).
If another user shows up, we can move it out again.
Part of #5279
[ci skip]
Similar to the last commit, only for the in-terminal-paste stuff.
Also cleans up the comments on bracketed paste a bit - nobody has
stepped forward to report problems with old emacsen or windows, so
there's no need for a TODO comment.
See #4327.
If we're at the beginning of the commandline, we trim leading whitespace so we don't trigger histignore.
Since that's the main issue of problems with histignore:
Closes#4327.
Apparently if you install gnu coreutils on OpenBSD, the tools are
g-prefixed. So we definitely want to just alias that rather than
provide our lousy shell script implementation.
25d83ed0d7 (included in 3.0.0) added a `string` check that
did not use `--`, so negative numbers were interpreted as options.
Apparently nobody is using this.
(Again, this is for the `seq` fallback used on OpenBSD)
That seems suspect.
It removes files starting with "# Autogenerated", but those files
usually do not show up in ~/.config - they're in ~/.local/share.
So let's be careful and not mess with the user's config.
(I'm pretty sure that the previous commit re-enabled cleanup as the
`~` was quoted before then)
[ci skip]
This did `argparse`, but only handled "--help". Any other options
would be ignored.
Instead, we just pass all the options through to python, and that'll
display help if needed.
This allows passing e.g. `--verbose 1` to help with debugging.
[ci skip]
NetBSD's man is unusual in that it doesn't understand an empty
$MANPATH component as "the system man path", and doesn't have a
`manpath` or `man --path`.
It has a `-m` option that would be useful, but other mans also have a
`-m` option that isn't, so detecting it is tough.
It does have a `-p` option that almost does what one would want here,
so we hack around it to make things work.
Fixes#5657.
[ci skip]
It turns out the default gettext on the sunny operating system with
the many names interprets at least `\n` itself, so we'd end up
swallowing it.
This allows us to move past the interactive tests and onto the expect
ones.
See #5472.
This exposes it more, since it's quite an important function.
We should do the same with the other vcs functions.
We leave a compatibility shim in place for now.
300ms was waaay too long, and even 100ms wasn't necessary.
Emacs' evil mode uses 10ms (0.01s), so let's stay a tad higher in case
some terminals are slow.
If anyone really wants to be able to type alt+h with escape, let them
raise the timeout.
Fixes#3904.
Prior to this fix, we would write to a fifo via cat >$filename & .
However in some cases (and soon in all cases) we open the file before
the fork, not after. This results in a deadlock because the file open
cannot succeed until a write begins.
Switch to using tee to write to the file. Because tee opens the file itself,
fish is no longer responsible and the deadlock is resolved.
Prior to this fix, we would write to a fifo via cat >$filename & .
However in some cases (and soon in all cases) we open the file before
the fork, not after. This results in a deadlock because the file open
cannot succeed until a write begins.
Switch to using tee to write to the file. Because tee opens the file itself,
fish is no longer responsible and the deadlock is resolved.
We were checking for the $TMUX variable to determine if we were
running under tmux. However when running the tests, the terminal becomes
expect, even though the TMUX variable is still set, so we spew tmux-isms
at expect. Check the value of $TERM for 'screen'.
This allows disabling _just_ the informative status.
We still also use the dirty and untracked variables, but only if
informative status hasn't explicitly been enabled.
If either of the two git config variables:
- bash.showDirtyState
- bash.showUntrackedFiles
is explicitly set to false, we will disable informative status, and
fall back on the non-informative version (most likely still with
either dirty or untracked files, since we already use the variables
for that).
These vars are read by the official git prompt, so we use them instead
of inventing our own "fish.showInformativeStatus".
(Note: This also uses $__fish_git_prompt_showdirtystate and friends,
but only when there's nothing set in the repo, and there's really no
reason to set those to false if using the informative status)
Fixes#5551.
[ci skip]
Expands the utility of `type -p foo` by allowing it to print the path to
the script that defines `foo` when `foo` is a valid function that was
sourced from a path on disk (rather than interactively defined).
This does not change the behavior of `type -P`/`type --force-path`,
which should have already been used if the desire was to resolve the
path to an executable file (otherwise the output would have been blank
if a function was shadowing an executable file of the same namea), so no
backwards compatibility issues are expected.
Previously, using special regex characters or slashes would result in an
error message, when pressing tab in a command-line such as
"man /usr/bin/time ".
Make it so that the generated completion has the form \t\n
when the optional description has been ommitted - otherwise
the original option's description gets inherited and is seen hundreds
of times repeating in the pager.
GNU ls's --indicator-style=classify is the same as POSIX -F.
Refactor and change command testing logic so that we define the
function in the same place for all platforms, and use -F on all
the platforms when stdout is a TTY.
A person stuck installing it just for fish on their server
doesn't want to waste time installing the wrong one, so assuage that.
Also tweak to look nicer with 80 columns
As discussed in #5492, it would be good if running fish_config without
Python actually told the user to install Python.
Further, let's give the person some hints on how to configure these
things by hand, since they may have to.
Which is 4, apparently.. (builtin_set.cpp returns ENV_NOT_FOUND)
here. This was previously hardcoded to our 121, which used to be
what builtins used for invalid arguments.
4 is pretty arbitrary but at least this is more consistent.
I had previously introduced a lot of updates and fixes to npm registry
based completions for `yarn` but hadn't ported them to `npm` as well
(although they can be dropped in as-is). This patch shares the code
between the two, which resides in an explicitly sourced multi-function
fish script.