From 7ae9bdd90c9b0262cb4e7cda9a4e512f01ca35db Mon Sep 17 00:00:00 2001 From: Klesh Wong Date: Wed, 2 Jun 2021 16:36:51 +0800 Subject: [PATCH] [feature] fzf search for edit-pass --- win/Modules/Pass/Pass.psm1 | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/win/Modules/Pass/Pass.psm1 b/win/Modules/Pass/Pass.psm1 index e9cde2e..01741af 100644 --- a/win/Modules/Pass/Pass.psm1 +++ b/win/Modules/Pass/Pass.psm1 @@ -53,14 +53,26 @@ function GetUid { } } +function FzfPass { + Get-ChildItem $PASSWORD_STORE_DIR -Recurse -Filter *.gpg | %{ + $_.FullName.SubString( + $PASSWORD_STORE_DIR.FullName.Length+1, + $_.FullName.Length-$PASSWORD_STORE_DIR.FullName.Length-5 + ) + } | Invoke-Fzf +} + function Edit-Pass { [Cmdletbinding()] param( - [Parameter(Mandatory=$true)] [String] $Path + [String] $Path ) - $Path = EnsurePath($Path) - echo $Path + if (!$Path) { + $Path = FzfPass + } + + $Path = EnsurePath $Path $tmpfile = (New-TemporaryFile).FullName gpg --decrypt $Path > $tmpfile @@ -84,10 +96,10 @@ function New-Pass { if (Test-Path -PathType Leaf $Path) { $text = gpg --decrypt $Path $text[0] = $pass + Remove-Item $Path -Force } else { $text = @($pass) } - Remove-Item $Path -Force $text | gpg -r (GetUid) -o $Path --encrypt - Set-Clipboard $pass Write-Host $pass @@ -117,12 +129,7 @@ function Get-Pass { } function Find-Pass { - $selected = Get-ChildItem $PASSWORD_STORE_DIR -Recurse -Filter *.gpg | %{ - $_.FullName.SubString( - $PASSWORD_STORE_DIR.FullName.Length+1, - $_.FullName.Length-$PASSWORD_STORE_DIR.FullName.Length-5 - ) - } | Invoke-Fzf + $selected = FzfPass if ($selected) { Get-Pass $selected