Commit Graph

5384 Commits

Author SHA1 Message Date
Johannes Altmanninger
5b94af6367 Restore cursor shape when deactivating Vi mode
Running

	fish_vi_key_bindings
	fish_default_key_bindings

ought to maintain cursor shape, at least in the default configuration,
so let's do that.

Fixes 9ef76860e6 (Default Vi cursor shapes for insert/replace mode, 2024-10-26).
2025-03-11 20:22:27 +01:00
Johannes Altmanninger
ea6e819a33 completions/set: add fish_cursor_* variables 2025-03-10 22:28:40 +01:00
Niklas Liechti
90218821f9 Split content of *KnownHostsFile as this is a supported config option by ssh. 2025-03-06 21:53:30 -08:00
phanium
6e8d6328ee completions/flatpak: don't ignore packages with uppercase in name (#11230)
* completions/flatpak: don't ignore packages with uppercase in name

`[^A-Z]+` here seems to trim header section in old version flatpak (avoid one
more `tail -n -2`?) but this can ignore packages have uppercase name like
`org.gtk.Gtk3theme.Adwaita-dark`.

* completions/flatpak: use cached `__fish_print_flatpak_packages` for `flatpak install`
2025-03-06 21:39:10 -08:00
Johannes Altmanninger
4ff94b657f __fish_apropos: fixup broken macOS version check
Due to the parens, this prints the version twice.  Fixes 49023adec7
(Consolidate some calls to uname(1) around shell startup, 2025-03-05).
2025-03-05 14:30:06 +01:00
Johannes Altmanninger
49023adec7 Consolidate some calls to uname(1) around shell startup
Most versions of fish don't run any external processes at startup, except
maybe fish_vcs_prompt.  This changed recently with a couple additions of uname.
This is probably fine but I guess we can reduce it down to one.

This change feels somewhat wrong. Not sure.  I guess we can remove it once
we provide $OSTYPE.

Note that this is also the reason why bindings don't use

	bind alt-backspace 'if test "$(uname)" = Darwin ...'

We don't want to expose a private interface in "bind" output.
2025-03-05 12:34:17 +01:00
Johannes Altmanninger
ce40229da6 Fix broken macOS major version detection regex
Not that it matters in practice but this is broken for version 100.
Reduce the surprise.
2025-03-05 12:28:48 +01:00
Johannes Altmanninger
8d8d25ff45 completions/bind: add super modifier 2025-03-05 12:28:48 +01:00
nicole
b3ff27b089 completions/emacs: add completion for argumnet: "--init-directory" (#11165) 2025-03-04 11:56:09 +01:00
Johannes Altmanninger
2bb5cbc959 Default bindings for token movements v2
Commit 6af96a81a8 (Default bindings for token movement commands, 2024-10-05)
has been reverted but not all docs have been.

Key bindings to move by command line argument are quite intuitive, and useful
when moving across URLs or other long arguments.

We have redundant bindings like {alt,ctrl}-left, so let's use one of them
for token movement.  We don't want to break the OS-native shortcut for word
movement, so use the other one on the current platform.

Note that Sublime Text does something similar: it uses the native key
binding for word movement, and the vacant one (e.g. `alt-left` on Linux)
for sub-word movement in camel case words.

While there have been 2.5 votes against making this platform dependent,
the majority of feedback was in favor.

This uses uname which seems wrong; we should rather use the OS that the
terminal is running on. I plan to implement this in future, but there's no
consensus yet on whether terminal applications should be allowed to do this.

See #10926
See #11107
2025-03-04 11:44:47 +01:00
Johannes Altmanninger
e015956de7 Orphan background tasks to work around terminals being sensitive to unreaped processes
When a command like "long-running-command &" exits, the resulting SIGCHLD
is queued in the topic monitor. We do not process this signal immediately
but only after e.g. the next command has finished. Only then do we reap the
child process.

Some terminals, such as Terminal.app, refuse to close when there are unreaped
processes associated with the terminal -- as in, having the same session ID,
see setsid(3).

In future, we might want to reap proactively.

For now, apply an isolated workaround: instead of taking care of a child
process, double-fork to create an orphaned process. Since the orphan will
be reaped by PID 1, we can eventually close Terminal.app without it asking
for confirmation.

	/bin/sh -c '( "$@" ) >/dev/null 2>&1 &' -- cmd arg1 arg2

This fix confines the problem to the period during which a background process
is running. To complete the fix, we would need to call setsid to detach the
background process from a controlling terminal. That seems to be desirable
however macOS does provide a setsid utility.

	setsid cmd arg1 arg2 >/dev/null 2>&1

Fixes #11181
2025-03-04 09:16:40 +01:00
Johannes Altmanninger
44d5abdc05 Add back legacy bindings to address modifyOtherKeys regressions in iTerm2<3.5.12
As of 303af07, iTerm2 3.5.11 on two different machines has two different
behaviors. For unknown reasons, when pressing alt-right fish_key_reader
shows "\e\[1\;9C" on one machine and "\e\[1\;3C" on another.

Feels like iTerm2 interprets modifyOtherKeys differently, depending on
configuration.

We don't want to risk asking for the kitty
keyboard protocol until iTerm2 3.5.12 (see
https://github.com/fish-shell/fish-shell/issues/11004#issuecomment-2571494782).

So let's work around around this weirdness by adding back the legacy
bindings removed in c0bcd817ba (Remove obsolete bindings, 2024-04-28) and
plan to remove them in a few years.

Note that fish_key_reader still reports this as "left", which already has
a different binding, but it looks like literal matches of legacy sequences
have precedence.

Fixes the problem described in
https://github.com/fish-shell/fish-shell/issues/11192#issuecomment-2692247060

Closes #11192
2025-03-03 14:44:00 +01:00
Johannes Altmanninger
50e595503e completions/git: fix completions for third-party git commands
Before 798527d79a (completions: fix double evaluation of tokenized commandline, 2024-01-06)
git-foo completions did something like

	set -l subcommand_args (commandline -opc)
	complete -C "git-foo $subcommand_args "

As mentioned in 368017905e (builtin commandline: -x for expanded tokens,
supplanting -o, 2024-01-06), the "-o" option is bad
because it produces a weird intermediate, half-expanded state.

The immediate goal of 798527d79a was to make sure we do not do any
more expansion on top of this.  To that end, it changed the above to
"\$subcommand_args".  The meaning is more or less the same[^*] but crucially,
the recursive completion invocation does not see through the variable,
which breaks some completions.

Fix this with the same approach as in 6b5ad163d3 (Fix double expansion of
tokenized command line, 2025-01-19).

[^*]: It wasn't semantically correct before or after -- this was later
corrected by 29f35d6cdf (completion: adopt commandline -x replacing deprecated
-o, 2024-01-22)).

Closes #11205
2025-03-03 14:30:48 +01:00
Fabian Boehm
86e531b848 completions/wine: Complete files
wine can be used, and is usually used for things like `wine
setup.exe`,
so it should allow for regular file completion.

Fixes #11202
2025-03-02 13:07:57 +01:00
Fabian Boehm
e0dd983c49 sample_prompts/acidhub: Use the same branch logic as fish_git_prompt
This was broken for 4.0 because it used `{}` command grouping.

Instead just do one of the things the fish_git_prompt does.

(the default isn't usable here because it gets the sha from elsewhere)

(cherry picked from commit e925eccad2)
2025-03-02 12:32:34 +01:00
Johannes Altmanninger
7b7e744353 sample_prompts/acidhub: fix regression showing all branches
Fix the accidental "git branch" output leaking while making sure we support:
1. unborn branch, where HEAD does not exist (`git init`)
2. detached head (`git checkout --detach`)

Notably computing the branch name should be independent of computing
a diff against HEAD.
In scenario 1 there is a branch but no HEAD,
while in scenario 2 it's the other way round.

Hence we need a separate check to see if we're in a git repo.
"git rev-parse" seems to work. Not sure what's best pracitce.

Also remove the ahead/behind logic, it was broken because it misspelled
@{upstream}.

Fixes #11179
2025-03-02 11:46:58 +01:00
Jay
c790b1051d fix unknown command __fish_diskutil_volumes
Signed-off-by: Jay <BusyJay@users.noreply.github.com>
2025-03-02 11:03:43 +01:00
Johannes Altmanninger
495083249b Fix regression causing cursor shape commands to leak into noninteractive shell
As reported in
https://matrix.to/#/!YLTeaulxSDauOOxBoR:matrix.org/$CLuoHTdvcRj_8-HBBq0p-lmGWeix5khEtKEDxN2Ulfo

Running

	fish -C '
		fzf_key_bindings
		echo fish_vi_key_bindings >>~/.config/fish/config.fish
		fzf-history-widget
	'

and pressing "enter" will add escape sequences like "[2 q" (cursor shape)
to fish's command line.

This is because fzf-history-widget binds "enter" to a filter
that happens to be a fish script:

	set -lx FZF_DEFAULT_OPTS \
		... \
		"--bind='enter:become:string replace -a -- \n\t \n {2..} | string collect'" \
		'--with-shell='(status fish-path)\\ -c)

The above ~/.config/fish/config.fish (redundantly) runs "fish_vi_key_bindings"
even in *noninteractive* shells, then "fish_vi_cursor" will print cursor
sequences in its "fish_exit" handler.  The sequence is not printed to the
terminal but to fzf which doesn't parse CSI commands.

This is a regression introduced by a5dfa84f73 (fish_vi_cursor: skip if stdin
is not a tty, 2023-11-14). That commit wanted "fish -c read" to be able to
use Vi cursor.  This is a noninteractive shell, but inside "read" we are
"effectively interactive".  However "status is-interactive" does not tell
us that.

Let's use a more contained fix to make sure that we print escape sequences only
if either fish is interactive, or if we are evaluating an interactive read.

In general, "fish -c read" is prone to configuration errors, since we
recommend gating configuration (for bind etc) on "status is-interactive"
which will not run here.
2025-03-02 09:34:06 +01:00
Johannes Altmanninger
5278686f55 completions/status: break up long line, add buildinfo 2025-03-02 09:34:06 +01:00
Peter Rice
d1bb4503d6 edit_command_buffer: pass cursor position to helix 2025-03-02 07:27:06 +01:00
Johannes Altmanninger
c926a87bdb Work around Konsole not recognizing file:://$hostname/path as local
Konsole has a bug: it does not recognize file:://$hostname/path as directory.
When we send that via OSC 7, that breaks Konsole's "Open Folder With"
context menu entry.

OSC 7 producers are strongly encouraged to set a non-empty hostname, but
it's not clear if consumers are supposed to accept an empty hostname (see
https://gitlab.freedesktop.org/terminal-wg/specifications/-/issues/20).
I think it should be fine; implementations should treat it as local path.

Let's work around the Konsole bug by omitting the hostname for now. This
may not be fully correct when using a remote desktop tool to access a
system running Konsole but I guess that's unlikely and understandable.
We're using KONSOLE_VERSION, so it the workaround should not leak into SSH
sessions where a hostname component is important.

Closes #11198

Proposed upstream fix https://invent.kde.org/frameworks/kio/-/merge_requests/1820
2025-03-02 05:44:36 +01:00
Johannes Altmanninger
f415413bfb Strip "$ " prefixes on paste
Code blocks are often written like

	$ echo hello world
	hello world

The "$ " is widely understood to introduce a shell command.  It's often
easier to copy the whole line than copying everything after "$ ".

This gets more pronounced when there are multiple commands without interleaved
output (either due to omission or the rule of silence). Copying the whole
code block is the most natural first step.

You could argue that this is a presentation issue - the dollar prefix
should be rendered but not copied to clipboard. But in my experience there
are many cases where there is no HTML or Javascript that would allow the
copy-to-clipboard functionality to strip the prefixes.

The "$ " prefix is almost never useful when pasting; strip it automatically.

Privileged commands use "# " as prefix which overlaps with comments, so do
not strip that until we can disambiguate (another potential reason not to
do that would be safety but it's unclear if that really matters).

Add the new logic to the commandline builtin, because we don't know about the
AST in fish script. (Technically, the tokenizer already knows whether a "$
" is in command position and at the beginning of a line, but we don't
have that either (yet).)

Maybe we should move the rest of __fish_paste over as well. I'm not sure what
difference that would make; for one, pasting could no longer be cancelled
by ctrl-c (in theory), which seems like a good direction?
2025-03-01 07:55:53 +01:00
Fabian Boehm
20e9fe9c95 Revert token movement bindings
Comments by macOS users have shown that, apparently, on that platform
this isn't wanted.

The functions are there for people to use,
but we need more time to figure out if and how we're going to bind
these by default.
For example, we could change these bindings depending on the OS in future.

This reverts most of commit 6af96a81a8.

Fixes #10926
See #11107

(cherry picked from commit 378f452eaa)
2025-02-27 21:10:07 +01:00
Fabian Boehm
6c9e6b3baf functions/help: Fix version number for betas 2025-02-19 21:47:00 +01:00
Łukasz Wieczorek
82750bbaec Reformat with black. 2025-02-12 22:59:27 +08:00
idealseal
7accf4ffa1 feat(comp): update to systemd 257 2025-02-11 22:52:42 +08:00
David Adam
2849cd11ae completions/elm: remove = in long options
elm's argument parser copes just fine without them

Review comment from
https://github.com/fish-shell/fish-shell/pull/10759#discussion_r1786918645
2025-02-11 22:27:53 +08:00
Kemel Zaidan
df6bd36e82 adds completion for the default Elm cli tool 2025-02-11 22:21:18 +08:00
Roland Fredenhagen
d862e7bf26 Complete entries for bootctl
Uses `jq` to parse and doesn't add these extra completions if not available.
2025-02-10 22:15:57 -08:00
Johannes Altmanninger
f4503af037 Make alt-{b,f} move in directory history if commandline is empty
alt-{left,right} move in the directory history (like in browsers).
Arrow keys can be inconvenient to reach on some keyboards, so
let's alias this to alt-{b,f}, which already have similar behavior.
(historically the behavior was the same; we're considering changing
that back on some platforms).

This happens to fix alt-{left,right} in Terminal.app (where we had
a workaround for some cases), Ghostty, though that alone should not
be the reason for this change.

Closes #11105
2025-02-06 19:12:00 +01:00
phanium
1d827d1d2d Fix twice tokenize editor_cmd
```fish
export VISUAL='nvim --cmd let\ g:flatten_wait=1'
funced -s fish_prompt
```

`editor_cmd[3]` would be `let` rather than `let g:flatten_wait=1`
2025-02-02 16:20:12 -08:00
Peter Ammon
7c32cb1b44 Put back noun form of "licence" in mksquashfs comment 2025-02-02 11:48:37 -08:00
ccoVeille
0df6fa7915 Fix typos in completions scripts 2025-02-02 17:15:11 +08:00
Ilya Grigoriev
5dd6759d01 completions/tmux: replace embedded tabs with \t 2025-02-01 17:37:38 -08:00
Ilya Grigoriev
2b6f6b8cbc completions/tmux: basic window argument completions 2025-02-01 17:37:38 -08:00
Ilya Grigoriev
5d0e2244bb completions/tmux: add ability to complete buffer names and commands
This adds the ability to complete (and therefore preview) buffer names,
and adds incomplete (aiming to maximize utility/effort, similarly to
b1064ac) bindings to the `tmux` buffer commands.

The main benefit is, IMO, is the tab completion for `tmux paste-buffer
-b` and `tmux show-buffer -b`.
2025-02-01 17:37:38 -08:00
Fabian Boehm
5eee4fc2c7 completions/git: Don't set the read limit
This isn't propagated correctly:

If $fish_read_limit is set globally, it won't apply to the completion
command substitution, *unless* you set fish_read_limit inside of that
function.

I'm not entirely sure how that happens, but let's work around it for
now by removing that limit.

I'm going to increase the default limit in a future commit, because
it's not something supposed to be reachable in ordinary code.

See #11106
2025-01-31 16:37:26 +01:00
Fabian Boehm
ba193665e2 completions: Add missing options for our builtins 2025-01-29 20:38:41 +01:00
Fabian Boehm
66f1aba0f2 completions/commandline: Add missing options 2025-01-29 20:17:46 +01:00
David Adam
2184aaf9b4 completions/acpi: correct the -c option as cooling
Closes #11068.
2025-01-28 21:47:05 +08:00
Ilya Grigoriev
f241187c4a completions/tmux: some windows and panes boolean flag completions
This documents some non-argument options for the window and panes
commands. The choice of what to document is somewhat arbitrary,
this commit is biased towards options that I find confusing or
misleading without documentation (is `-a` "all" or "after"?)
and the command that seem more useful to me.

I also didn't cover the options that would be covered by
#10855 (though this PR can be used independently). I'm not
sure how much difference this made, it might not matter at
all.
2025-01-28 21:38:34 +08:00
Ilya Grigoriev
77406ddd11 completions/tmux: complete commands inside tmux lscm
Make `tmux lscm <tab>` work.
2025-01-28 21:37:16 +08:00
Ilya Grigoriev
183e20cc3a completions/tmux: complete all flags when tmux lscm is available
These dynamic completions are exhaustive, but not as well-documented or
as ergonomic as the manual completions. So, any manual completions
should override them.
2025-01-28 21:37:16 +08:00
Ilya Grigoriev
27e5ed7456 completions/tmux: complete all subcommands when tmux lscm works
For example, `tmux shell<tab>` now completes to `if-shell` and
`run-shell`, though no additional information is provided.
2025-01-28 21:37:16 +08:00
Fabian Boehm
9116c61736 completions/nmcli: Complete at runtime
This used to get all the interfaces and ssids when the completions
were loaded. That's obviously wrong, given that ssids especially can, you know, change
2025-01-27 20:46:38 +01:00
Fabian Boehm
4370fb755d completions/git: Handle untracked files separately
This uses `git ls-files`, which has a simpler format (just the
filenames on separate lines), in order to print the untracked files.

This allows us to skip them in the `git status` call, which reduces
the output a lot and removes two `string match`.

In a repository with over half a million files (my home directory, if
I made it one), this improves time by a third (12s to 8s).

In a smaller repo (fish-shell) it's barely measurable.
2025-01-27 18:24:08 +01:00
Fabian Boehm
5c81e18b2e completions/git: Handle gigantic repos better
Determine if untracked files are off via `__fish_git`, so we get the
repo used on the commandline etc,

and if it isn't, at least don't error out. Yes, this *can* print a
hundred megabytes of filenames.
2025-01-27 17:52:32 +01:00
Fabian Boehm
bba15c6d14 completions/csvlens: Fix missing option 2025-01-27 17:51:35 +01:00
ccoVeille
b6a1bedab9 Fix typos in comments 2025-01-26 20:30:48 -08:00
Fabian Boehm
2b2f824b94 completions/git: Handle huge repositories for "add" better
`git add` may have to go through literal megabytes of file information
because of tons of untracked files.

So, if the repository is set to not show untracked files (because it's
too slow for the prompt), let's fall back on regular file completions.

(the alternative is to go back to `while read`, but that takes much
longer in repositories of a sensible size)

Fixes #11095
2025-01-26 21:41:36 +01:00