1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-01 14:47:47 +00:00

Added completions for pass (#454)

This commit is contained in:
nils-degroot 2023-04-20 15:12:48 +02:00 committed by GitHub
parent 4157914f71
commit 1d16a376b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 85 additions and 0 deletions

View file

@ -0,0 +1,13 @@
# Pass Custom Completions
This script provides custom completions for most pass commands. It can be
imported with the following command:
```nu
source path/to/pass/pass-completions.nu
```
Where `path/to` is the relative of absolute pass to the pass completions file.
More information about the pass password manager can be found at
https://www.passwordstore.org/.

View file

@ -0,0 +1,72 @@
let pass_completions_directory = if ($env | columns | any { |it| $it == "PASSWORD_STORE_DIR" }) {
$env.PASSWORD_STORE_DIR
} else {
(^realpath ~/.password-store/) + "/"
}
def "nu-complete pass-files" [] {
^find $pass_completions_directory -name "*.gpg" -type f
| lines
| each {|it| ($it | str replace $pass_completions_directory "" | str replace ".gpg" "") }
}
def "nu-complete pass-directories" [] {
^find $pass_completions_directory -name ".git" -prune -o -type d -print
| lines
| each {|it| ($it | str replace $pass_completions_directory "") }
| filter { |it| ($it | is-empty) == false }
}
# Show folders in the password store
export extern "pass ls" [
subfolder?: string@"nu-complete pass-directories"
]
# Show the value of a password
export extern "pass show" [
name: string@"nu-complete pass-files"
]
# Add a new password
export extern "pass add" [
name: string@"nu-complete pass-directories"
--echo(-e) # Enable keyboard echo
--multiline(-m) # Lines will be read until EOF or Ctrl+D is reached
--force(-f) # Omit prompt when trying to overwrite existing password
]
# Edit an existing password
export extern "pass edit" [
name: string@"nu-complete pass-files"
]
# Generate a new password
export extern "pass generate" [
name: string@"nu-complete pass-directories"
length?: number
--no-symbols(-n) # Do not use any non-alphanumeric characters in the generated password
--clip(-c) # Do not print the password but instead copy it to the clipboard using xclip or wl-clipboard
--in-place(-i) # Do not interactively prompt, and only replace the first line of the password file with the new generated password, keeping the remainder of the file intact
--force(-f) # Omit prompt when trying to overwrite existing password
]
# Remove a password
export extern "pass rm" [
name: string@"nu-complete pass-files"
--recursive(-r) # delete pass-name recursively if it is a directory
--force(-f) # Do not interactively prompt before removal
]
# Rename a password
export extern "pass mv" [
oldname: string@"nu-complete pass-files"
newname: string@"nu-complete pass-directories"
--force(-f) # Omit prompt when trying to overwrite existing password
]
# Copy a password
export extern "pass cp" [
oldname: string@"nu-complete pass-files"
newname: string@"nu-complete pass-directories"
--force(-f) # Omit prompt when trying to overwrite existing password
]