-
-
Notifications
You must be signed in to change notification settings - Fork 57
Add Fish Shell Completions #601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gr1da
wants to merge
6
commits into
creativeprojects:master
Choose a base branch
from
gr1da:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d6e21c8
Add fish completion script
gr1da 99d3270
Add support for fish completions
gr1da 1e237d3
Add documentation for use of fish shell completions
gr1da c6b2aac
Fix fish completion empty value check
gr1da a4f781e
Fix isOwnCommand when command descriptions are present
gr1da 3588c30
Fix restic command forwarding with profile prefix
gr1da File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| #!/usr/bin/env fish | ||
| # | ||
| # resticprofile fish completion script | ||
| # Usage: see https://fishshell.com/docs/current/completions.html#where-to-put-completions | ||
|
|
||
| function __resticprofile_completion | ||
| set --local full_cmdline (commandline -x) | ||
| set --local cmdline_to_cursor \ | ||
| (string split -- " " (string escape -- (commandline -cx; commandline -ct))) | ||
| set --local current_token_pos (math (count $cmdline_to_cursor) - 1) | ||
|
|
||
| #send commandline to 'resticprofile complete' in the format it expects | ||
| set --local completions ("$full_cmdline[1]" complete "fish:v1" "__POS:$current_token_pos" "$full_cmdline[2..]") | ||
|
|
||
| if test (count $completions) = 0 | ||
| return | ||
| end | ||
|
|
||
| #handle the directive returned from resticprofile | ||
| switch $completions[-1] | ||
| case "__complete_file" | ||
| set --erase completions[-1] | ||
|
|
||
| set --local file $full_cmdline[-1] | ||
| #if file starts with '-', remove it | ||
| test (string sub --length 1 -- "$file") = "-"; and set file "" | ||
|
|
||
| #do path completion | ||
| set --append completions (__fish_complete_path "$file") | ||
|
|
||
| case "__complete_restic" | ||
| #string match --regex returns list where first element is the whole string | ||
| #and the rest are capture group matches. | ||
| set --local prefix (string match --regex '^(.*)\.' -- "$completions[-1]")[2] | ||
| set --local suffix (string match --regex '\.([^.]+)$' -- "$completions[-1]")[2] | ||
| set --erase completions[-1] | ||
|
|
||
| #This removes profile prefixes before forwarding the completion to restic | ||
| set --local restic_words | ||
| for word in $cmdline_to_cursor[2..] | ||
| if test (string match --regex ".*\/.*" -- "$word") | ||
| set --append restic_words (string unescape -- "$word") | ||
| else | ||
| #take everything after last dot, if there is one | ||
| set --append restic_words (string match --regex '([^.]+)$' -- $word)[2] | ||
| end | ||
| end | ||
|
|
||
| #Add a space if the cursor is past the last token so that 'complete' doesn't | ||
| #return a command that's already fully typed out | ||
| if test "$restic_words[-1]" = "''" | ||
| set restic_words[-1] " " | ||
| end | ||
|
|
||
| #get restic completions | ||
| set --local restic_values (complete --do-complete "restic $restic_words") | ||
|
|
||
| if test (count $restic_values) = 0 | ||
| for x in $completions | ||
| echo $x | ||
| end | ||
| return | ||
| end | ||
|
|
||
| for value in $restic_values | ||
| #remove empty values | ||
| string match --regex '^[\r\n\t ]+$' -- "$value"; and return | ||
|
|
||
| #add prefix back to completion if applicable | ||
| if test -n $prefix && test "$prefix" != "$suffix" | ||
| set --append completions "$prefix.$value" | ||
| else | ||
| set --append completions "$value" | ||
| end | ||
| end | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| end | ||
|
|
||
| for x in $completions | ||
| echo $x | ||
| end | ||
|
|
||
| end | ||
|
|
||
| complete --command resticprofile --no-files --arguments "(__resticprofile_completion)" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.