-
Notifications
You must be signed in to change notification settings - Fork 87
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
[WIP] Add fish completions (Fixing #118) #151
Open
harmtemolder
wants to merge
2
commits into
tadfisher:develop
Choose a base branch
from
harmtemolder:develop
base: develop
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 all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 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,56 @@ | ||
#!/usr/bin/env fish | ||
|
||
#TODO Do not suggest a second subcommand after a first one is used | ||
#TODO Do not hard-code the path to the main pass completions | ||
#TODO Make sure the Makefile does not overwrite the main pass completions | ||
#TODO Make sure the default FISHCOMPDIR is in $fish_complete_path, and before the main pass completions' location | ||
|
||
source "/usr/share/fish/vendor_completions.d/pass.fish" | ||
|
||
# Allow for the checking of two commands | ||
function __fish_pass_uses_command | ||
set -l cmd (commandline -opc) | ||
if test (count $argv) -gt 1 | ||
if test (count $cmd) -gt 2 | ||
if test \( $argv[1] = $cmd[2] \) -a \( $argv[2] = $cmd[3] \) | ||
return 0 | ||
end | ||
end | ||
else if test (count $cmd) -gt 1 | ||
if test $argv[1] = $cmd[2] | ||
return 0 | ||
end | ||
end | ||
return 1 | ||
end | ||
|
||
set -l PROG 'pass' | ||
|
||
# Add `otp` after `pass`. Defaults to `pass otp code` | ||
complete -c $PROG -f -n '__fish_pass_needs_command' -a otp -d 'Command: generate OTP code' | ||
complete -c $PROG -f -n '__fish_pass_uses_command otp; and not __fish_pass_uses_command otp insert; and not __fish_pass_uses_command otp append; and not __fish_pass_uses_command otp validate' -s c -l clip -d 'Put OTP code in clipboard' | ||
complete -c $PROG -f -n '__fish_pass_uses_command otp' -a "(__fish_pass_print_entries_and_dirs)" | ||
|
||
# Add `code` after `pass otp` | ||
complete -c $PROG -f -n '__fish_pass_uses_command otp' -a code -d 'Command: generate an OTP code' | ||
complete -c $PROG -f -n '__fish_pass_uses_command otp code' -s c -l clip -d 'Put OTP code in clipboard' | ||
|
||
# Add `insert` after `pass otp` | ||
complete -c $PROG -f -n '__fish_pass_uses_command otp' -a insert -d 'Command: insert a new OTP key URI in a new password file' | ||
complete -c $PROG -f -n '__fish_pass_uses_command otp insert' -s e -l echo -d 'Echo the input' | ||
complete -c $PROG -f -n '__fish_pass_uses_command otp insert' -s f -l force -d 'Do not prompt before overwriting an existing URI' | ||
|
||
# Add `append` after `pass otp` | ||
complete -c $PROG -f -n '__fish_pass_uses_command otp' -a append -d 'Command: append an OTP key URI to an existing password file' | ||
complete -c $PROG -f -n '__fish_pass_uses_command otp append' -s e -l echo -d 'Echo the input' | ||
complete -c $PROG -f -n '__fish_pass_uses_command otp append' -s f -l force -d 'Do not prompt before overwriting an existing URI' | ||
complete -c $PROG -f -n '__fish_pass_uses_command otp append' -a "(__fish_pass_print_entries_and_dirs)" | ||
|
||
# Add `uri` after `pass otp` | ||
complete -c $PROG -f -n '__fish_pass_uses_command otp' -a uri -d 'Command: display the stored key URI' | ||
complete -c $PROG -f -n '__fish_pass_uses_command otp uri' -s c -l clip -d 'Put key URI in clipboard' | ||
complete -c $PROG -f -n '__fish_pass_uses_command otp uri' -s q -l qrcode -d 'Display a QR code' | ||
complete -c $PROG -f -n '__fish_pass_uses_command otp uri' -a "(__fish_pass_print_entries_and_dirs)" | ||
|
||
# Add `validate` after `pass otp` | ||
complete -c $PROG -f -n '__fish_pass_uses_command otp' -a validate -d 'Command: test if the given URI is a valid OTP key URI' |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be called
pass-otp
since it might interfere withpass
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually tried that first, but it seemed like fish uses the filename to apply its completions to a specific command (in this case
pass
). If you know of a way to name this filepass-otp.fish
I'm all for itThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But won't that overwrite the default
pass.fish
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's why by default this
pass.fish
installs into/etc/fish/completions
and reads the defaultpass.fish
from/usr/share/fish/vendor_completions.d/pass.fish
. That is where the default ones are on my system, but I can't guarantee that on other systems. That's why checkboxes 3 and 4 are still openThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the setup for completions is kind of messy and I haven't looked at this for a while. Lemme check upstream and get back to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, the ideal solution would be for pass to delegate to extension completion scripts itself, similar to what it does for
pass git
andpass grep
here: https://git.zx2c4.com/password-store/commit/?id=06f499994071bb6131244218b25d637103afe1d5. This should be a reasonable change to submit upstream.