Commit Graph

4974 Commits

Author SHA1 Message Date
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
Fabian Boehm
7e087d8eda __fish_make_cache_dir: Create fish subdir and optionally deeper
This will move all current cache uses to e.g. ~/.cache/fish/

That's better anyway because it makes it easier to remove.

Also it allows supplying a subdir so you can do `__fish_make_cache_dir
completions`
to get ~/.cache/fish/completions.
2024-01-21 14:18:50 +01:00
Johannes Altmanninger
5dfcfa336b edit_command_buffer: if aliasee is a recognized editor, pass cursor position too
If I alias "e" to "emacsclient" it will probably accept the same options.
Let's dereference the alias so we can detect support for passing the cursor
position in more cases.

This does not solve the problem for recursive cases (e.g. alias of another
alias). If we want to handle that we would need cycle detection.
2024-01-21 09:39:59 +01:00
Paul Ouellette
2cb60bed10 Remove share/completions/highlight.fish
Highlight ships its own completion script:
https://gitlab.com/saalen/highlight/-/blob/master/sh-completion/highlight.fish
2024-01-20 11:39:48 +01:00
Ikko Eltociear Ashimine
1e925857f0 Update iwctl.fish
colum -> column
2024-01-18 19:34:30 +01:00
Himadri Bhattacharjee
5389d84285 shorten long descriptions for the cargo command 2024-01-16 22:16:36 +01:00
Peter Collingbourne
0b3e9609f1 completions/fastboot: declare -s as taking an argument, add argument completions 2024-01-12 20:45:56 +01:00
Fabian Boehm
23a8967ecb fish_config: Fix on python < 3.12 if not on Windows 2024-01-12 18:42:55 +01:00
ahaoboy
8009469f8f Add support for the Windows MSYS environment. 2024-01-12 17:55:49 +01:00
yinm
b583145a00 Shorten long descriptions 2024-01-12 17:53:49 +01:00
Johannes Altmanninger
57d7c46d22 completions: fix some completions to not look at other commands on the command line 2024-01-07 19:04:54 +01:00
Johannes Altmanninger
d71aae7d3b completions/ip: remove obsolete workaround
This workaround already exists in core completion machinery.
2024-01-07 19:04:54 +01:00
Fabian Boehm
16c2c14fb4 Restyle 2024-01-07 15:13:34 +01:00
Johannes Altmanninger
f42b7d30b3 completions/ant: don't look at tokens from adjacent commands 2024-01-06 08:44:23 +01:00
Josef Litoš
ee837f254b feat: adb completion cleared of awk 2024-01-04 16:13:03 +01:00
Damien Picard
4f3e7ddef0 Completions: fix Blender completions when it prints to stderr
Some of the completions recently introduced called Blender itself to query some
arguments, and Blender sometimes prints messages to stderr. This output was not
filtered, resulting in the shell printing irrelevant messages during completion.
2024-01-04 16:11:51 +01:00
Nethum Lamahewage
a36ff7d143 history: fix deleting last entry 2024-01-04 16:10:08 +01:00
David Adam
c10d00599b completions/ninja: add --verbose option 2024-01-03 23:17:55 +08:00
Fabian Boehm
b895cf49ca umask: Correctly handle empty symbolic value
Simple return/echo confusion.

Fixes #10177
2023-12-31 19:39:23 +01:00
David Adam
850c57bbb3 completions/funced: clarify -i description
Work on #10053.
2023-12-31 23:04:19 +08:00
jydeng
b9b850f286 add more subcommands for apt (#10100) 2023-12-31 23:00:15 +08:00
David Adam
31eb429add themes/Nord: include license tag 2023-12-31 12:54:31 +08:00
Fabian Boehm
4c1e25b141 fish_git_prompt: Add separator even if state is empty
This would leave off the separator if the repo was just bare or had
upstream difference, but no status (e.g. dirty) applied.

Fixes #10175
2023-12-30 19:38:22 +01:00
Damien Picard
9132684617 completions: improve Blender completions
- Replace short options with old-style options: even though they are
  single-letter, Blender's options cannot be combined.
- Add comments to separate blocks of options, mirroring Blender's help message.
- Add missing options: render-frame, python-use-system-env, register-allusers,
  unregister, unregister-allusers.
- Remove options: debug-gpu-disable-ssbo, debug-gpu-renderdoc, -R.
- Fix typos:
  - debug-depsgraph-eval (was -evel)
  - debug-depsgraph-pretty (was -time)
  - app-template (was open-last)
- Update output formats:
  - Add descriptions.
  - Add HDR, TIFF, OpenEXR, OpenEXR Multilayer, FFmpeg, Cineon, DPX, JPEG 2000,
    and WebP, which are optional but generally available.
  - Remove IRIZ, which is no longer available.
- Fix arguments for --use-extension: they should be 0 or 1, not true or false.
- Make env-system-* options require a parameter.
- Improve --add-ons by querying the list of add-ons inside Blender rather than a
  hardcoded path. This is because Blender's add-on modules may come from many
  different paths which depend on platform.
- Fix __blender_echo_input_file_name, by relying on extension.
- Fix listing of scene datablocks inside Blend file.
- Add listing of Python text datablocks to execute inside Blend file.

Closes #10150
2023-12-30 16:20:39 +01:00
Amy Grace
6fe4e3d8a9 completions: add xxd
Closes #10137

(cherry picked from commit 36ed2b79c2)
2023-12-30 10:18:59 +01:00
Grzegorz Milka
c369080963 Add git stash push completions
Closes #10147

(cherry picked from commit 03198b7fd3)
2023-12-30 10:09:48 +01:00
tangowithfoxtrot
cf98b27544 add completions for bws
Closes #10165

(cherry picked from commit 7370e38069)
2023-12-30 09:33:05 +01:00
Eric N. Vander Weele
48ef682cad themes: Synchronize Nord theme in adherence to color palette guidelines
Adhere as best as possible to the style guidelines at
https://www.nordtheme.com/docs/colors-and-palettes. Some adaptations were made
so that `functions <function>` is also syntax highlighted per the upstream
recommendations.

Additionally, the theme file has been reordered to follow the order of variables
defined in interactive syntax-highlighting-variables documentation.
2023-12-28 13:36:41 -08:00
Johannes Altmanninger
81c8cd1b61 completions: use POSIX character classes with sed
\s and \S are not supported BSD sed.

Fixes #10163
2023-12-27 17:11:01 +01:00
Fabian Boehm
b1a1a3b0a7 prompt_pwd: Fix missing --
Fixes #10169
2023-12-25 18:46:23 +01:00