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

fix pass-completion as let cannot be used at module level (#544)

* fix pass-completion as `let` cannot be used at module level

`let` cannont be used at module level. #8248 proposes to add `const` for modules, but in the meantime, a function is the best way to make this script useable as a module.

* remove calls to system commands for better portability

`^realpath` and `^find` are replaced with `path expand` and `ls` in an effort not to rely on system commands. Literal "/" are also replaced with native path operations.

---------

Co-authored-by: Benoît Sierro <benoit.sierro@bluewin.ch>
This commit is contained in:
dedebenui 2023-07-03 14:54:14 +02:00 committed by GitHub
parent bc54b622fa
commit 94ae821daa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,20 +1,28 @@
let pass_completions_directory = if ($env | columns | any { |it| $it == "PASSWORD_STORE_DIR" }) {
$env.PASSWORD_STORE_DIR
} else {
(^realpath ~/.password-store/) + "/"
def pass_completions_directory [] {
if ($env | columns | any { |it| $it == "PASSWORD_STORE_DIR" }) {
return $env.PASSWORD_STORE_DIR
} else {
return ("~/.password-store" | path expand)
}
}
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" "") }
let dir = (pass_completions_directory)
ls ($dir | path join "**" | path join "*.gpg")
| get name
| each {|it| ( $it
| path relative-to $dir
| 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 }
let dir = (pass_completions_directory)
ls ($dir | path join **)
| get name
| filter { |it| not (ls $it | is-empty) }
| each {|it| ( $it | path relative-to $dir) }
}
# Show folders in the password store
@ -25,6 +33,8 @@ export extern "pass ls" [
# Show the value of a password
export extern "pass show" [
name: string@"nu-complete pass-files"
--clip(-c) # do not print the password but instead copy the first (or otherwise specified, example: -c2) line to the clipboard.
--qrcode(-q) # do not print the password but instead display a QR code.
]
# Add a new password
@ -70,3 +80,4 @@ export extern "pass cp" [
newname: string@"nu-complete pass-directories"
--force(-f) # Omit prompt when trying to overwrite existing password
]