Commit Graph

5203 Commits

Author SHA1 Message Date
Mahmoud Al-Qudsi
c2ecfe60ac completions/flatpak: Fix compatibility with older versions
Filter out ansi control characters and pretty formatting from older versions
that don't detect the absence of a tty.

Closes #10514.
2024-05-22 13:53:25 -05:00
Michal Koutný
fa0c585662
completions/git: Add git branch --edit-description (#10512)
* completions/git: Add `git branch --edit-description`
2024-05-21 18:56:52 -05:00
Jannik Vieten
bd4e5fe69a
completions ip: silence stderr in case -d does not exist (busybox) (#10509) 2024-05-20 07:28:40 -05:00
Peter Yates
56a168d37f Prevent loading of psqlrc when listing databases
Users have the ability to override the way records are displayed in psql by
changing the format[1] and linestyle[2] settings. These settings also affect the
output of psql commands used for autocompletion, like listing databases and
users - so they inadvertantly break Fish's completion.

If we suppress the loading of psqlrc[3] the default settings are used instead.

[1] https://www.postgresql.org/docs/current/app-psql.html#APP-PSQL-META-COMMAND-PSET-FORMAT
[2] https://www.postgresql.org/docs/current/app-psql.html#APP-PSQL-META-COMMAND-PSET-LINESTYLE
[3] https://www.postgresql.org/docs/current/app-psql.html#APP-PSQL-OPTION-NO-PSQLRC
2024-05-20 14:04:38 +02:00
ridiculousfish
efefeda392 Restore some iTerm2 default key bindings
c0bcd817ba removed some key bindings, including the bindings of
ESC ESC [ C for Alt-Right. the commit claimed that
"Sequences like \e\eOC are Escape followed by an SS3 arrow key which we
can already decode separately." but for whatever reason this doesn't work:
Alt-Right is broken in iTerm2 by default.

Restore the default ESC ESC [ X bindings for iTerm2 compatibility.
2024-05-19 11:01:14 -07:00
Klaus Hipp
4659fdf704
Add git-lfs completions (#10490) 2024-05-19 09:09:33 -05:00
tesuji
255c8da22d
add completions for ibus (#10500) 2024-05-19 09:05:40 -05:00
Jannik Vieten
66d28f5fda
completions: improved ip completions (#10505)
- complete routing table names/IDs
- rudimentary completions for ip rule subcommand
2024-05-19 09:00:29 -05:00
Mahmoud Al-Qudsi
ef614ba2d9 Speed up rustc completions, filter out deprecated options
Don't unconditionally execute the plumbing to get `rustc -C` completions (use it
only when trying to complete `rustc -C`), filter out deprecated options, and use
fewer calls to the `string` builtin to optimize further.

Need to do the same thing for the `-Z` completions next, those hang the shell
for a good 1.5+ seconds.
2024-05-18 12:37:18 -05:00
Mahmoud Al-Qudsi
0a7725e469 Add comment re accuracy of cargo --target completions
[ci skip]
2024-05-18 12:00:45 -05:00
Mahmoud Al-Qudsi
cbb399f2ed completions/cargo.fish: Add python fallback for jq 2024-05-17 18:45:19 -05:00
Mahmoud Al-Qudsi
79f7b9f92a completions/cargo.fish: Dynamically generate --features completion 2024-05-17 18:17:53 -05:00
Mahmoud Al-Qudsi
f342ae6a1c Add a completion helper function to generate permutation completions
I've been needing this for some time to generate completions for functions that
we can dynamically generate completions for that take one or more
comma-separated values in any order.
2024-05-17 18:15:41 -05:00
Mahmoud Al-Qudsi
6dbae76b24 Update cargo-asm completions
Try not to let `cargo asm` build a large project and hang the terminal (and make
the fans go crazy) if we try to generate a list of functions/paths and the
project is in a dirty state. Also support dynamic completion of --target.
2024-05-17 17:10:10 -05:00
Mahmoud Al-Qudsi
1d36c6ad8c completions/cargo.fish: Generate dynamic --target options
If rustup is installed, use the existing `__rustup_installed_targets` to get a
list of installed targets to compile for. If it's not, print a list of all
targets known to rustc.

It sucks that the completions file is currently architected in a way where we
have to manually specify the arguments for each subcommand. 🤷
2024-05-17 16:57:40 -05:00
Mahmoud Al-Qudsi
9ab1ec2a9e Tweak newly added rustc completion descriptions
Addendum to https://github.com/fish-shell/fish-shell/pull/10491
2024-05-17 12:33:59 -05:00
tesuji
d3758d3751
completion: add more arguments for rustc --print (#10491)
Based off of rustc 1.80.0-nightly
2024-05-17 12:32:41 -05:00
Ian Chamberlain
1462da3ae2
Complete cargo check bin targets like build (#10499)
Since `check` operates on basically the same things as `build`, it makes
sense to complete binary targets the same way (i.e. tests, bins, examples)
2024-05-17 12:31:30 -05:00
Mahmoud Al-Qudsi
0271d91d3a Add completions for cargo-asm 2024-05-17 12:31:02 -05:00
Fabian Boehm
5dc07c9e7e completions: More shortening
Also removes a few deprecated options - there's really no need to
offer these.
2024-05-16 18:29:42 +02:00
Fabian Boehm
8bac13360b completions/gcc: More cleanup
These options, I tell you
2024-05-15 20:07:28 +02:00
Fabian Boehm
173bcf29ab completions/gcc: Cleanup options
- Remove duplicated options - we had `-type` 9 times!
- Remove deprecated options and synonyms
- Make descriptions shorter, even removing some - when they're inscrutable they might as well not be there.

Really, 99.8% of these options are of interest to nobody except possibly (a subset of) gcc developers, so it pays to have *less* on your screen that you don't use anyway.
2024-05-15 17:05:02 +02:00
Fabian Boehm
4cadaa4041 completions/gcc: Fix some options
Especially the "-l" one was *always* offered.
2024-05-15 17:05:02 +02:00
Johannes Altmanninger
35b689335a Strip control characters from pasted text
We ignore typed control characters 33a7172ee (Revert to not inserting control
characters from keyboard input, 2024-03-02).

We used to do the same for bracketed paste but that changed in 8bf8b10f6
(Extended & human-friendly keys, 2024-03-30) which made bracketed paste
behave like fish_clipboard_paste; it inserts the exact input (minus leading
whitespace etc). At that time it wasn't clear to me which behavior was the
right one (because of the inconsistency between terminal and bracketed paste).

As reported in
https://matrix.to/#/!YLTeaulxSDauOOxBoR:matrix.org/$PEEOAoyJY-644amIio0CWmq1TkpEDdSy2QnfJdK-dco
trailing tabs in pasted text can be confusing.

There seems to be not real need to insert raw control characters into the
command line, so let's strip them when pasting.

Now the only way to insert a raw control character into the command line is
to recall it from command history.  Not sure what the behavior should be for
that case, we can revisit that later. If we get rid of raw control characters
entirely, then we can also delete the new "control pictures" rendering :)
2024-05-14 23:14:49 +02:00
Fabian Boehm
24836f9652 Use set --no-event in the key binding functions
This is how we can use it in a backwards-compatible way. Eventually we
would remove the compatibility guff.
2024-05-14 17:31:47 +02:00
tesuji
f71623ec1b
Partially update zig completions for zig 0.13 (#10479)
Try for completeness with `zig -h` and `zig build -h`
2024-05-09 15:31:07 -05:00
Klaus Hipp
ae486bafc8
Add completions for VS Code preview builds (#10485) 2024-05-09 15:28:14 -05:00
Klaus Hipp
1c0887eba2
Add duf completions (#10486) 2024-05-09 15:27:13 -05:00
Klaus Hipp
5524b46181
Add zed completions (#10487) 2024-05-09 15:25:41 -05:00
Mahmoud Al-Qudsi
2ca92cd52d completions/rustup: Filter out installed components from rustup component add 2024-05-08 18:47:15 -05:00
Mahmoud Al-Qudsi
671d128a3e completions/rustup: Fix incorrect component names
The components with the form abc-x86_64-unknown-linux-gnux32 were ending
up generating invalid components of the form abcx32, which is incorrect.
2024-05-08 18:43:28 -05:00
Fabian Boehm
9320fb52bb git prompt: Check for "U"nmerged files
Fixes #10481
2024-05-06 19:17:26 +02:00
Fabian Boehm
33c5cd5808 git prompt: Remove a useless use of math 2024-05-06 19:15:42 +02:00
Mahmoud Al-Qudsi
bcc1fc0167 rustup: add rustup target xxx completions 2024-05-04 18:42:11 -05:00
Johannes Altmanninger
d4ecea56df Fix regression spuriously expanding abbr with cursor outside token
Given "abbr foo something", the input sequence

    foo<space><ctrl-z><space>

would re-expand the abbreviation on the second space which is surprising
because the cursor is not at or inside the command token.  This looks to be
a regression from 00432df42 (Trigger abbreviations after inserting process
separators, 2024-04-13)

Happily, 69583f303 (Allow restricting abbreviations to specific commands
(#10452), 2024-04-24) made some changes that mean the bad commit seems no
longer necessary. Not sure why it works but I'll take it.
2024-05-03 08:39:05 +02:00
ClaXXX
0116dc5984
Fix the acidhub prompt for a commitless repository (#10462)
Deletes the error message generated by git when comparing indexes for a
commitless repository and print '-' as the branch name
2024-05-02 19:37:12 +02:00
Johannes Altmanninger
0c413d0093 Use canonical key name in bind command 2024-05-01 12:53:00 +02:00
Fabian Boehm
4be4592870 fish_add_path: Add separate message about files 2024-04-30 16:47:45 +02:00
Johannes Altmanninger
e7347b9581 Bind ctrl-Z to redo (since ctrl-z is undo)
In addition to the native Emacs undo binding, we also support ctrl-z.
On Linux, ctrl-shift-z alias ctrl-Z is the redo binding according to
https://en.wikipedia.org/wiki/Table_of_keyboard_shortcuts Let's bind allow
that.

Unfortunately ctrl-shift and ctrl-alt modified shortcuts on Linux may be
intercepted by the windowing system or the terminal. Only alt-shift seems to be
available reliably (but the shift bit should mean "extend selection" in Emacs).
2024-04-30 14:00:06 +02:00
Johannes Altmanninger
1185e5279e Don't print multiple summaries for multiline jobs
For example

    $ echo 'line
    line2' | sleep 1 &

    fish: Job 1, 'echo 'line' has ended
    fish: Job     line2' | sleep 1 &, '' has ended
2024-04-30 14:00:06 +02:00
Johannes Altmanninger
c0bcd817ba Remove obsolete bindings
iTerm2 supports CSI u so the custom bindings are no longer needed. Sequences
like \e\eOC are Escape followed by an SS3 arrow key which we can already
decode separately.
2024-04-28 10:38:26 +02:00
Mahmoud Al-Qudsi
40591ba629 Unify convert and magick completions 2024-04-27 11:45:54 -05:00
Jadi
6840ef46f7 Completion for magick (#10307)
In ImageMagick 7 or later, legacy commands have been replaced with
magick. Here a new functions, defines these completions and it is
called for `magick` and `magick convert`.

fixes #7172. Closes #10307.

Co-authored-by: Mahmoud Al-Qudsi <mqudsi@neosmart.net>
2024-04-27 11:45:12 -05:00
Fabian Boehm
2da5ce7a48 completions/conda: Enable file completions for --file options
Fixes #10463
2024-04-27 17:11:52 +02:00
Johannes Altmanninger
67197b4b07 Fix cleanup of autogenerated completions
We were inconsistent about this for no apparent reason.

Also cleaning up in ~/.config/fish/completions is
irrelevant by now since we moved to ~/.local/share/fish 8 years ago.

Now that the parent commit moved it again, cleaning up that one seems
reasonable.
2024-04-27 10:54:31 +02:00
Anurag Singh
62a8b48fd1 Move generated completions to cache directory 2024-04-27 10:39:30 +02:00
Johannes Altmanninger
ec33550cff Fix detection of empty commandline in alt-d binding 2024-04-26 11:16:30 +02:00
Nguyen Huu Kim
891b0a74fd Update helm completions ignore stderr 2024-04-21 14:39:49 +02:00
Nguyen Huu Kim
2e61ce5540 Replace minikube completions with autogenerated script 2024-04-21 14:39:49 +02:00
Nguyen Huu Kim
00f661d8e8 add devspace completions 2024-04-21 14:39:49 +02:00
Johannes Altmanninger
b3444ea128 Work around ctrl-c in VSCode killing wl-copy and clearing clipboard
wl-copy is a daemon process that serves its stdin to any wl-paste processes.
On Wayland, we launch it from fish_clipboard_copy.  It then lives in the
same process group as fish (see `ps -o pid,pgid,comm`).

For some reason pressing ctrl-c inside the VSCode integrated terminal with
fish as the default shell kills the wl-copy process, thus clearing the
clipboard. On other terminals it works fine.

This is also reproducible by running "echo foo | wl-copy" ctrl-v ctrl-c ctrl-v
(the second ctrl-v does not paste because wl-copy was killed).

Work around this for now by running wl-copy asynchronously, and disowning it.
This seems to fix it though I really don't know why. Alternatively we could
"setsid" but that's technically not available on BSD.

For some reason this works in Bash. We should strace it to figure out why.
2024-04-21 14:34:41 +02:00
Johannes Altmanninger
c9793711dc Remove stale mention of plus key name 2024-04-20 15:36:29 +02:00
Johannes Altmanninger
334946af61 completions/complete: add --escape 2024-04-20 13:34:08 +02:00
Johannes Altmanninger
e571774c97 Make alt-d on empty commandline call dirh again
alt-d used to do that until evil merge[*] 213e90704 (Merge remote-tracking branch
'upstream/master' into bind_mode, 2014-01-15) which changed the order of
the \ed bindings such that the smart dirh version would be shadowed by the
simpler ones.

[*] git blame alone failed to find it because it skips merge commits.
2024-04-20 12:11:30 +02:00
Johannes Altmanninger
2e42d80dc9 completions/scp: silence error on unexpected version
There seem to be versions of ssh (possibly not from OpenSSH) that don't
print the version number in -V, so make sure not to pass an empty string as
numeric arg to test.

Fixes #10445
2024-04-17 09:52:12 +02:00
Johannes Altmanninger
9af6a64fd2 Fix bad contrast in search match highlighting
This is another problem that has been bothering me for years: as mentioned
in 1dd901e52 (Maintain cursor in history prefix search, 2024-04-12), up-arrow
search highlights search matches but the contrast is really bad, especially in
command position, because the search matches --background=brblack is combined
with whatever foreground syntax highlighting the command has.  The history
pager had a similar problem (for the selected history item) but circumented
it by disabling syntax highlighting altogether for the selected item.

fish_color_search_match's foreground component is ignored.
Let's use it instead of syntax highlighting.

This fixes the contrast on some default colorschemes but the bryellow
foreground looks weirdly like an error/warning on some terminals.  Change it
to white. This needs a hack because we don't have a canonical way to tell
if a uvar has been set by the user. Fortunately the foreground component
hasn't been used at all so far, so we're not so much changing it as much as
initializing it.
2024-04-15 09:40:21 +02:00
Johannes Altmanninger
a37629f869 fish_clipboard_copy: indent multiline commands
See also the earlier commits.

Closes #10437
2024-04-15 09:20:44 +02:00
Johannes Altmanninger
611a0572b1 builtins type/functions: indent interactively-defined functions
This means that in case no editor is defined, "fish_indent" is now required
to fix the indentation.

Fixes #8603
2024-04-15 08:32:31 +02:00
Johannes Altmanninger
222673f339 edit_command_buffer: send indented commandline to editor
Indented multiline commandlines look ugly in an external editor.  Also,
fish doesn't properly handle the case when the editor runs fish_indent.
Fix is by indenting when exporting the commandline and un-indenting when
importing the commandline again.

Unindent only if the file is properly indented (meaning at least by the
amount fish would use).  Another complication is that we need to offset
cursor positions by the indentation.

This approach exposes "fish_indent --only-indent" and "--only-unindent"
though I don't imagine they are useful for others so I'm not sure if this
is the right place and whether we should even document it.

One alternative is to add "commandline --indented" to handle indentation
transparently.
So  "commandline --indented" would print a indented lines,
and "commandline --indented 'if true' '    echo'" would remove the unecessary
indentation before replacing the commandline.
That would probably simplify the logic for the cursor position offset.
2024-04-15 08:32:31 +02:00
Johannes Altmanninger
47a446ae18 Teach fish_indent to only indent and unindent
To be used in the following commits.
2024-04-15 08:32:31 +02:00
Anurag Singh
c044d5e3f0 add history append subcommand 2024-04-15 08:31:16 +02:00
Adam J. Stewart
6f408211a1
Add ruff completions (#10440)
* Add ruff completions

* Automatically generate and cache
2024-04-14 13:29:10 +02:00
Johannes Altmanninger
00432df420 Trigger abbreviations after inserting process separators
On

    a;

we don't expand the abbreviation because the cursor is right of semicolon,
not on the command token. Fix this by making sure that we call expand-abbr
with the cursor on the semicolon which is the end of the command token.
(Now that our bind command execution order is less surprising, this is doable.)

This means that we need to fix the cursor after successfully expanding
an abbreviation. Do this by setting the position explicitly even when no
--set-position is in effect.

An earlier version of this patch used

    bind space self-insert backward-char expand-abbr or forward-char

The problem with that (as a failing test shows) was that given "abbr m
myabbr", after typing "m space ctrl-z", the cursor would be after the "m",
not after the space.  The second space removes the space, not changing the
cursor position, which is weird.  I initially tried to fix this by adding
a hack to the undo group logic, to always restore the cursor position from
when begin-undo-group was used.

    bind space self-insert begin-undo-group backward-char expand-abbr end-undo-group or forward-char

However this made test_torn_escapes.py fail for mysterious reasons.
I believe this is because that test registers and triggers a SIGUSR1 handler;
since the signal handler will rearrange char events, that probably messes
with the undo group guards.

I resorted to adding a tailor-made readline cmd. We could probably remove
it and give the new behavior to expand-abbr, not sure.

Fixes #9730
2024-04-13 20:11:11 +02:00
Johannes Altmanninger
6858f1100a Remove redundant raw CSI u bindings 2024-04-13 14:36:11 +02:00
Johannes Altmanninger
1d98846e03 Remove some redundant raw bindings
We already decode these, see parse_csi() and parse_ss3().
2024-04-13 14:36:11 +02:00
Lia Lenckowski
90cffb18a1 complete brightnessctl flags 2024-04-12 12:53:55 +02:00
Johannes Altmanninger
9158395d10 Fix __fish_list_current_token and friends for multiline commandlines
Some of these handled multiline prompts but not multiline command lines. We
first need to move the cursor to the end of the commandline, then we can
print a message.  Finally, we need to move the cursor back to where it was.
2024-04-12 12:00:24 +02:00
Johannes Altmanninger
5c3a0251b7 funced: don't try to source interactive-only function
Regressed in 2c2ab0c1f (Always `source` file after `funced` (#10318),
2024-02-22) which was only intended for functions that are backed by a file.
2024-04-12 11:27:55 +02:00
Johannes Altmanninger
e934e1b009 Test that bind output can recreate the same bindings 2024-04-09 00:22:41 +02:00
Johannes Altmanninger
8949c44574 Fix __fish_complete_command with multiline tokens 2024-04-09 00:07:27 +02:00
Johannes Altmanninger
3b9e3e251b Emit OSC 133 sequences to mark prompt/command output regions
This allows terminals like foot and kitty to
* scroll to the previous/next prompt with ctrl-shift-{z,x}
* pipe the last command's output to a pager with ctrl-shift-g

Kitty has existing fish shell integration
shell-integration/fish/vendor_conf.d/kitty-shell-integration.fish which we
can simplify now. They keep a state variable to decide which of prompt start,
command start or command end to output.  I think with our implementation
this is no longer necessary, at least I couldn't reproduce any difference.
We also don't need to hook into fish_cancel or fish_posterror like they do;
only in the one place where we actually draw the prompt.

As mentioned in the above shell integration script, kitty disables reflow
when it sees an OSC 133 marker, so we need to do it ourselves,
otherwise the prompt will go blank after a terminal resize.

Closes #10352
2024-04-06 22:22:56 +02:00
Johannes Altmanninger
33701faa8c completions/set: offer private variables if token starts with _ 2024-04-06 21:20:53 +02:00
Johannes Altmanninger
18f6492564 completions/set: strip cursed descriptions from history/fish_killring
If I type

    $ echo $SOME_VARIABLE_WIHT_A_TYPO
    $ set -S SOME_VARIABLE_WIHT

and press tab, I'm always extremely surprised that this completes to

    $ set -S fish_history

which is because $history[1] contains the typo'd variable name.  I don't
think anyone intends to filter by that last 3-4 history items, so let's
remove this pitfall.

Note that I usually hit this scenario with undefined variables, not necessarily
typos.. "set -S" is usually redundant but it's still quite nice in this case,
to rule out any weird empty strings/empty lists.
2024-04-06 19:12:25 +02:00
Johannes Altmanninger
444cda20bc Document focus events 2024-04-06 18:14:17 +02:00
phanium
0a6e8468cc Avoid invoking extra subshell in __fish_md5 2024-04-05 15:26:48 +02:00
phanium
aa1a390504 Replace __funced_md5 with __fish_md5 2024-04-05 15:26:48 +02:00
phanium
b121b9649b Fix completions for pactree, pkgfile 2024-04-05 15:26:06 +02:00
Klaus Hipp
3c9b5713c9 Update code completions 2024-04-05 15:25:32 +02:00
Armin Brauns
3c0d7d0feb Add typst completions 2024-04-05 15:24:36 +02:00
Felix Luciano Salomon
8bbf760860
Added bruno completions (#10388)
* Added bruno completions

* Modified format completion to include formats as closed list arguments
2024-04-05 15:23:29 +02:00
Johannes Altmanninger
cb58a30bf2 Report $PWD changes unconditionally
Similar to 20bbdb68f (Set terminal title unconditionally, 2024-03-30).

While at it, get rid of a few unnecessary guards (we are never called from
a command substitution, so the check only adds confusion).
2024-04-03 13:14:02 +02:00
Johannes Altmanninger
9870faa8be Remove workarounds for Emacs ansi-term
I'm not sure if it's worth supporting a terminal that mishandles unknown OSC
and CSI sequences. Better to fix the terminal.  Note that there are Emacs
terminals available that don't have this problems; for example "vterm".
2024-04-03 13:09:27 +02:00
Fabian Boehm
ec603790d1 nim prompt: Don't use test
A single-argument use, even!

Fixes #10404
2024-04-02 17:33:30 +02:00
Johannes Altmanninger
8bf8b10f68 Extended & human-friendly keys
See the changelog additions for user-visible changes.

Since we enable/disable terminal protocols whenever we pass terminal ownership,
tests can no longer run in parallel on the same terminal.

For the same reason, readline shortcuts in the gdb REPL will not work anymore.
As a remedy, use gdbserver, or lobby for CSI u support in libreadline.

Add sleep to some tests, otherwise they fall (both in CI and locally).

There are two weird failures on FreeBSD remaining, disable them for now
https://github.com/fish-shell/fish-shell/pull/10359/checks?check_run_id=23330096362

Design and implementation borrows heavily from Kakoune.

In future, we should try to implement more of the kitty progressive
enhancements.

Closes #10359
2024-04-02 14:35:16 +02:00
Johannes Altmanninger
22717339b4 fish_clipboard_paste: don't bypass pager search field.
To do so add an ad-hoc "commandline --search-field" to operate on pager
search field.

This is primarily motivated because a following commit reuses the
fish_clipboard_paste logic for bracketed paste. This avoids a regression.
2024-04-02 14:35:16 +02:00
Felix Luciano Salomon
1f68d66692
Added pbpaste command completions (#10389)
* Added pbpaste command completions
2024-03-30 22:35:53 -05:00
Johannes Altmanninger
62a49acda3 completions/iwctl: fix spurious error on "iwctl device foo" 2024-03-25 20:56:08 +01:00
Johannes Altmanninger
f5d6ea6cf6 Basic completions for gdbserver 2024-03-25 05:42:16 +01:00
Fabian Boehm
ec7c0e19d0 help: Always print what is used
Makes it easier to debug
2024-03-24 08:51:52 +01:00
Fabian Boehm
bdfa7341e7 help: Only use open on macOS
Unfortunately on Debian "open" is a symlink to "openvt", and there's
no way from outside to tell.

This prevents fish from failing because no browser could be found.
2024-03-24 08:48:58 +01:00
Johannes Altmanninger
39ea1d710d Vi mode: add "+yy for fish_clipboard_copy and friends
Obviously not fully correct, and the implementation is not greate but it's
a start.
2024-03-23 14:24:51 +01:00
Johannes Altmanninger
25db4e803c Vi mode: don't cross newline on escape 2024-03-23 14:12:21 +01:00
Johannes Altmanninger
54b8817937 Vi mode: add + as clipboard alias, like * 2024-03-23 14:12:21 +01:00
Johannes Altmanninger
d51f669647 Vi mode: avoid placing cursor beyond last character
Today fish_cursor_selection_mode controls whether selection mode includes
the cursor. Since it's by default only used for Vi mode, perhaps use it to
also decide whether it should be allowed to select one-past the last character.

Not allowing to select to select one-past the last character is much nicer
in Vi mode.  Unfortunately Vi mode sometimes needs to temporarily select
past end (using forward-single-char and such), so reset fish_cursor_selection_mode
for the duration of the binding.

Also fix other things like cursor placement after yank/yank-pop.

Closes #10286
Closes #3299
2024-03-23 14:12:21 +01:00
Johannes Altmanninger
bffc9515a8 Fix bracketed paste regression from input event queue changes
We have

    bind --preset -M $mode --sets-mode paste \e\[200~ __fish_start_bracketed_paste

Commit c3cd68dda (Process shell commands from bindings like regular char
events, 2024-03-02) made it so __fish_start_bracketed_paste is no longer
executed before the bind mode is  updated.
This is a long-awaited fix but it broke __fish_start_bracketed_paste's
assumption that $fish_bind_mode is the mode before we entered paste mode.
This means we never exit paste mode.

Work around that. I forgot about this issue because I already replaced our
bracketed paste handling on my fork.
2024-03-23 14:08:55 +01:00
Johannes Altmanninger
8baf7de4c0 Vi mode: remove stale comment 2024-03-23 10:38:28 +01:00
Johannes Altmanninger
789a280ee8 Fix {Alt,Shift}-Return bindings not expanding abbreviations
Today,

    bind foo "commandline -f expand-abbr; commandline -i \n"

does not work because this
1. enqueues an expand-abbr readline event
2. "commandline -i" inserts \n
3. processes the expand-abbr readline event

Since there is no abbreviation on the new line, this doesn't do anything.

PR https://github.com/fish-shell/fish-shell/pull/9398 would fix this
particular instance however it does not fix the issue that "commandline -i"
is run before the expand-abbr is processed by the reader. This is harmless
here but there would be a problem if "commandline" tried to read commandline
state that was created by a preceding command.

It's not super clear to me whether the above binding should work as one
would naively expect. That would imply that "commandline" would need to
drain all input events (at least all synthetic ones) from the input queue,
to ensure it sees the current state.

Fortunately the parent commit makes it so if we separate them

    bind foo "commandline -f expand-abbr" "commandline -i \n"

both will be separate events and the commandline state will be synced after
each of them. This fixes abbreviation expansion here.

Also, we can now mix readline cmds and shell commands, which makes it shorter.
2024-03-23 10:06:11 +01:00
Johannes Altmanninger
c1f601f31e Don't bind Alt-Return in Vi normal mode
It seems wrong because it's for text insertion; if someone actually wants
to use it we can add it back.
2024-03-23 09:54:18 +01:00
Johannes Altmanninger
865118e3b4 On Shift+Return, insert a newline instead of executing the commandline
Most chat programs I found use Shift+Return to insert a newline while plain
Return sends the message. One user reported having only tried Shift+Return
and not knowing about Alt+Return.

No release notes yet because this only works on a very small number of
terminals. Once we enable CSI u, this should work on most modern terminals.
2024-03-23 09:54:18 +01:00
Fabian Boehm
0ff1e50a33 rustc: Protect against lines starting with -
Fixes #10379
2024-03-19 16:49:46 +01:00
Johannes Altmanninger
cd71359c42 completions/git: complete files iff last token is not a fixupish
Closes #10371
2024-03-16 10:45:57 +01:00
Johannes Altmanninger
62d1720605 completions/htop: fix --sort-key completions 2024-03-16 10:31:01 +01:00
fortifiedhill
8678ad8ca0 Update htop completions
Added and updated completions and updated htop link.
2024-03-16 09:00:42 +01:00
Xiretza
8271021fb6 Add completions for dmidecode 2024-03-16 08:57:43 +01:00
Fabian Boehm
0aa2426552 completions/wg-quick: Complete files after the subcommand
Fixes #10366
2024-03-12 17:32:51 +01:00
Johannes Altmanninger
d8d491741b edit_command_buffer: preserve external editor's cursor position
Unless the editor changed to a different file for some reason.

Note that the Kakoune integration uses -always to export the cursor even if
the user temporarily suppressed hooks - possibly a "fish_indent" hook.
2024-03-10 11:08:12 +01:00
Johannes Altmanninger
5fa743337c edit_command_buffer: also detect aliases with arguments
For example

    complete my-vim --wraps 'vim -x'
2024-03-10 11:06:38 +01:00
amiyzku
bb6b3101ff
Shortened some which.fish completions. (#10347)
* Shortened some which.fish completions.

* improve descriptions for which command options
2024-03-09 20:52:55 -06:00
RomainGiraud
f8757d154c
Fix scp completion for WSL (with ssh.exe) (#10290)
* Fix scp completion for WSL (with ssh.exe)

* Be more explicit
2024-03-09 15:39:57 -06:00
Johannes Altmanninger
836ee93617 Vi bindings: Control-N to accept autosuggestion
One of the things that keep me from using Vi mode is that it doesn't define an
insert-mode shortcut to accept autosuggestions. Let's use Control-N because
that Vim key is the closest equivalent.

Closes #10339
2024-03-09 11:03:57 +01:00
QianChenglong
b3c610feff add completion for mycli
Closes #10309
2024-03-09 10:28:03 +01:00
Felix Luciano Salomon
90b9bce174 Added completion for ollama
Closes #10327
2024-03-09 10:28:03 +01:00
Next Alone
a1d44a92be
fix: #10184 causes adb file completion failures (#10349)
Signed-off-by: NextAlone <12210746+NextAlone@users.noreply.github.com>
2024-03-08 21:56:37 -06:00
Johannes Altmanninger
6eddaa37af Revert "feat: adb completion cleared of awk"
It's broken,  see https://github.com/fish-shell/fish-shell/pull/10184
and doesn't really help I don't think.

This reverts commit ee837f254b.
2024-03-08 07:33:18 +01:00
John
b75e5ee823
remove repetitive words (#10348)
Signed-off-by: hishope <csqiye@126.com>
2024-03-07 18:35:41 -06:00
zuisong
a1e46a94f6
Add --url-query completion for curl (#10332)
Add missing completion for curl's `--url-query` option
2024-02-29 12:09:51 -06:00
Fabian Boehm
78c9482822 Reformat share/**.fish with newlines collapsed 2024-02-27 16:25:01 +01:00
Mathis Chenuet
73d760560b
Add completion for pstree (#10317)
* Add completion for pstree.fish

* use fish functions, much better
2024-02-26 17:39:11 +01:00
Fabian Boehm
d0cf07c4b3 Format __fish_cache_sourced_completions 2024-02-26 16:17:47 +01:00
may
66aab66670
add recent commits to completion for git diff (#10321) 2024-02-25 14:36:05 -06:00
Mahmoud Al-Qudsi
2c2ab0c1fa
Always source file after funced (#10318)
... even if the file hasn't changed. This addresses an oddity in the following
case:

* Shell is started,
* function `foo` is sourced from foo.fish
* foo.fish is *externally* edited and saved
* <Loaded definition of `foo` is now stale, but fish is unaware>
* `funced foo` loads `type -p foo` showing changed definition, user exits
  $EDITOR saving no changes (or with $status 0, more generally).
* Stale definition of `foo` remains
2024-02-22 12:45:20 -06:00
Jadi
e207f8464e Make descriptions shorter: iex, jhipster, lpadmin, mocp, rmmod 2024-02-22 18:59:08 +01:00
Jason Nader
fc58b9c68f completions: add ssh -D option 2024-02-22 18:58:04 +01:00
Paul Gier
6c9c033126 functions: handle hostname starting with dash
If a hostname starts with a dash `-` character, the prompt_hostname function
fails because the `string` function interprets it as an option instead
of an argument.
2024-02-22 21:21:31 +08:00
Jason Nader
2f332f0019 completions: update 'echo' 2024-02-20 17:40:35 +01:00
Fabian Boehm
8667ed5c17 fish_git_prompt: Count type changes as dirty too
Fixes #10305
2024-02-17 08:37:22 +01:00
Johannes Altmanninger
26ea024e74 completions/xdg-mime: fix off-by-one error and allow multiple filetypes 2024-02-16 07:45:22 +01:00
Johannes Altmanninger
0627c9d9af Render control characters as Unicode Control Pictures
Inserting Tab or Backspace characters causes weird glitches. Sometimes it's
useful to paste tabs as part of a code block.

Render tabs as "␉" and so on for other ASCII control characters, see
https://unicode-table.com/en/blocks/control-pictures/. This fixes the
width-related glitches.

You can see it in action by inserting some control characters into the
command line:

	set chars
	for x in (seq 1 0x1F)
		set -a chars (printf "%02x\\\\x%02x" $x $x)
	end
	eval set chars $chars
	commandline -i "echo '" $chars

Fixes #6923
Fixes #5274
Closes #7295

We could extend this approach to display a fallback symbol for every unknown
nonprintable character, not just ASCII control characters.

In future we might want to support tab properly.
2024-02-15 01:39:45 +01:00
Emily Grace Seville
623f3463a5
feat: cobra-cli support (#10293)
* feat: cobra-cli support

* fix: cobra-cli completion
2024-02-10 16:52:31 +01:00
Johannes Altmanninger
47aa79813d Open command script in external editor on Alt+o
Fish functions are great for configuring fish but they don't integrate
seamlessly with the rest of the system. For tasks that can run outside fish,
writing scripts is the natural approach.

To edit my scripts I frequently run

    $EDITOR (which my-script)

Would be great to reduce the amount typing for this common case (the names
of editor and scripts are usually short, so that's a lot of typing spent on
the boring part).

Our Alt+o binding opens the file at the cursor in a pager.  When the cursor
is in command position, it doesn't do anything (unless the command is actually
a valid file path). Let's make it open the resolved file path in an editor.

In future, we should teach this binding to delegate to "funced" upon seeing
a function instead of a script. I didn't do it yet because funced prints
messages, so it will mess with the commandline rendering if used from
a binding.  (The fact that funced encourages overwriting functions that
ship with fish is worrysome. Also I'm not sure why funced doesn't open the
function's source file directly (if not sourced from stdin). Persisting the
function should probably be the default.)

Alternative approach: I think other shells expand "=my-script" to
"/path/to/my-script".  That is certainly an option -- if we do that we'd want
to teach fish to complete command names after "=".  Since I don't remember
scenarios where I care about the full path of a script beyond opening it in
my editor, I didn't look further into this.

Closes #10266
2024-02-07 00:07:47 +01:00
Daniel Kahn Gillmor
b265152fba tab completions: avoid completing gpg --use-embedded-filename
gpg's --use-embedded-filename is a dangerous option that can cause gpg
to write arbitrary content to arbitrary files.

According to the GnuPG maintainer, this is not an option recommended
for use (https://dev.gnupg.org/T4500).  Fish shouldn't encourage users
to supply it.

I've offered https://dev.gnupg.org/T6972 to upstream to make it even
more clear that this option is a bad idea.

While removing it, we might as well also remove
--no-use-embedded-filename, since it is effectively a no-op.
2024-02-02 21:57:55 +01:00
Theodore Ehrenborg
263197dcb7 Typo 2024-01-31 08:06:34 +01:00
bitraid
86afc7832d Call fish_vi_cursor_handle also for interactive read
Not doing this results in the cursor not being initially set for `read`.
2024-01-27 20:13:47 +01:00
bitraid
a5dfa84f73 fish_vi_cursor: skip if stdin is not a tty
Instead of skipping for non-interactive shells, skip when stdin is not a tty.
This allows the cursor to be set for scripts that use the `read` command.
2024-01-27 20:13:47 +01:00
Johannes Altmanninger
33a9659cd1 Fix stale name of --tokens-expand option
Missed in 368017905 (builtin commandline: -x for expanded tokens, supplanting
-o, 2024-01-06).
2024-01-27 20:09:33 +01:00
Daniel Bretoi
6f797ac958
Update just.fish to handle descriptions for completions (#10260)
* Update just.fish to handle descriptions for completions

This change updates fish completions to also include descriptions for justfile recipes. It has been tested with descriptions for recipes with arguments as well

* rely on fish only (avoid sed)
2024-01-27 18:58:24 +01:00
Fabian Boehm
677e4ff698 anypython: Add more versions 2024-01-27 18:47:38 +01:00
Johannes Altmanninger
37c380d885 completions/git: add send-email 2024-01-27 17:57:48 +01:00
Jason Nader
28d9f1878d completions: fix wg-quick interface completions
wg outputs space separated list
2024-01-27 11:40:57 +01:00
Johannes Altmanninger
5f459446a8 functions/funced: harmonize interpretation of VISUAL/EDITOR
Like other tools, we split $EDITOR by spaces and remove backslashes in Alt+e
and Alt+o but not in funced. Let's' fix this inconsistency.
2024-01-27 09:38:51 +01:00
Johannes Altmanninger
29f35d6cdf completion: adopt commandline -x replacing deprecated -o
This gives us more accurate completions because completion scripts get
expanded paths
2024-01-27 09:28:06 +01:00
Johannes Altmanninger
798527d79a completions: fix double evaluation of tokenized commandline
Fix cases like

    eval my-cmd (commandline -o)
    complete -C "my-cmd $(commandline -o)"

In both cases, we spuriously evaluate tokens like "(inside-quoted-string)"
as command substitutions. Fix this by escaping the strings.  The momentarily
regresses the intended purpose of "eval" -- to expand variables -- but the
next commit will fix that.
2024-01-27 09:28:06 +01:00
Johannes Altmanninger
368017905e builtin commandline: -x for expanded tokens, supplanting -o
Issue #10194 reports Cobra completions do

    set -l args (commandline -opc)
    eval $args[1] __complete $args[2..] (commandline -ct | string escape)

The intent behind "eval" is to expand variables and tildes in "$args".
Fair enough. Several of our own completions do the same, see the next commit.

The problem with "commandline -o" + "eval" is that the former already
removes quotes that are  relevant for "eval". This becomes a problem if $args
contains quoted () or {}, for example this command will wrongly execute a
command substituion:

    git --work-tree='(launch-missiles)' <TAB>

It is possible to escape the string the tokens before running eval, but
then there will be no expansion of variables etc.  The problem is that
"commandline -o" only unescapes tokens so they end up in a weird state
somewhere in-between what the user typed and the expanded version.

Remove the need for "eval" by introducing "commandline -x" which expands
things like variables and braces. This enables custom completion scripts to
be aware of shell variables without eval, see the added test for completions
to "make -C $var/some/dir ".

This means that essentially all third party scripts should migrate from
"commandline -o" to "commandline -x". For example

    set -l tokens
    if commandline -x >/dev/null 2>&1
        set tokens (commandline -xpc)
    else
        set tokens (commandline -opc)
    end

Since this is mainly used for completions, the expansion skips command
substitutions.  They are passed through as-is (instead of cancelling or
expanding to nothing) to make custom completion scripts work reasonably well
in the common case. Of course there are cases where we would want to expand
command substitutions here, so I'm not sure.
2024-01-27 09:28:06 +01:00
Daniel Bretoi
c78750499d
Dynamic Completion for Justfile Recipes (#10244)
* Create just.fish

justfile completions for tasks similar to make completions for targets

* no need for the match at all
2024-01-22 20:13:10 +01:00
Asuka Minato
0f97111290
add more strace completion (#10227)
* Update strace.fish

* Update strace.fish

* upper case
2024-01-22 20:12:43 +01:00
Mark Huang
65cf6ada56 completions for apt and apt-get 2024-01-21 14:21:44 +01:00
Fabian Boehm
423829a634 Rename existing cache files
We're already moving them, we can remove the awkward dot that hides
them, and while we're doing that remove the useless $USER as well.

Most systems will have only one of these files - it's rare to run a
second package manager (especially for anything more than
bootstrapping a container).
2024-01-21 14:18:50 +01:00
Fabian Boehm
a66fa5262e Cache ykman completions
Also 140ms
2024-01-21 14:18:50 +01:00
Fabian Boehm
b4d9189fd3 Cache pip{,2,3,env} completions
These take a *lot* of time - `pip3` takes 180ms, `pipenv` takes 320ms
on my system.

Note that this removes a number of obsolete workarounds - pip's was
fixed in 2017 (and pip2 is less and less of a thing), pipenv's change
was in 2019.

Since these are packaging tools with access to the internet they
should really be kept up-to-date, so it is unlikely someone still uses
these old versions.
2024-01-21 14:18:50 +01:00
Fabian Boehm
e5b2c3e4be Add helper to cache | source completions
We have a lot of completions that look like

```fish
pip completion --fish 2>/dev/null | source
```

That's *fine*, upstream gives us some support.

However, the scripts they provide change very rarely, usually not even
every release, and so running them again for every shell is extremely
wasteful.

In particular the python tools are very slow, `pip completion --fish`
takes about 180ms on my system with a hot cache, which is quite
noticeable.

So what we do is we run them once, store them in a file in our cache
directory, and then serve from that.

We store the mtime of the command we ran, and compare against that for
future runs. If the mtime differs - so if the command was up or
downgraded, we run it again.
2024-01-21 14:18:50 +01:00