[feature] fzf search for edit-pass

This commit is contained in:
Klesh Wong 2021-06-02 16:36:51 +08:00
parent 4da081c761
commit 7ae9bdd90c

View File

@ -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 { function Edit-Pass {
[Cmdletbinding()] [Cmdletbinding()]
param( param(
[Parameter(Mandatory=$true)] [String] $Path [String] $Path
) )
$Path = EnsurePath($Path) if (!$Path) {
echo $Path $Path = FzfPass
}
$Path = EnsurePath $Path
$tmpfile = (New-TemporaryFile).FullName $tmpfile = (New-TemporaryFile).FullName
gpg --decrypt $Path > $tmpfile gpg --decrypt $Path > $tmpfile
@ -84,10 +96,10 @@ function New-Pass {
if (Test-Path -PathType Leaf $Path) { if (Test-Path -PathType Leaf $Path) {
$text = gpg --decrypt $Path $text = gpg --decrypt $Path
$text[0] = $pass $text[0] = $pass
Remove-Item $Path -Force
} else { } else {
$text = @($pass) $text = @($pass)
} }
Remove-Item $Path -Force
$text | gpg -r (GetUid) -o $Path --encrypt - $text | gpg -r (GetUid) -o $Path --encrypt -
Set-Clipboard $pass Set-Clipboard $pass
Write-Host $pass Write-Host $pass
@ -117,12 +129,7 @@ function Get-Pass {
} }
function Find-Pass { function Find-Pass {
$selected = Get-ChildItem $PASSWORD_STORE_DIR -Recurse -Filter *.gpg | %{ $selected = FzfPass
$_.FullName.SubString(
$PASSWORD_STORE_DIR.FullName.Length+1,
$_.FullName.Length-$PASSWORD_STORE_DIR.FullName.Length-5
)
} | Invoke-Fzf
if ($selected) { if ($selected) {
Get-Pass $selected Get-Pass $selected