mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-08-28 04:46:41 -04:00
Do not require a pre-existing entry name for PowerShell completions
This commit is contained in:
+14
-18
@@ -1,18 +1,13 @@
|
||||
Class libmuttonEntries : System.Management.Automation.IValidateSetValuesGenerator {
|
||||
[string[]] GetValidValues() {
|
||||
#$entryPath = (Resolve-Path '~/.local/share/libmutton').Path # UNIX testing
|
||||
$entryPath = (Resolve-Path '~/AppData/Local/libmutton/entries').Path
|
||||
$entryNames = If (Test-Path $entryPath) {(Get-ChildItem -Path $entryPath -Recurse).FullName.Substring($entryPath.Length) -replace '\\', '/'}
|
||||
return [string[]] $entryNames
|
||||
}
|
||||
function MUTNEntryCompleter {
|
||||
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
|
||||
$entryPath = (Resolve-Path '~/.local/share/libmutton').Path # UNIX testing
|
||||
#$entryPath = (Resolve-Path '~/AppData/Local/libmutton/entries').Path
|
||||
$entryNames = If (Test-Path $entryPath) {(Get-ChildItem -Path $entryPath -Recurse).FullName.Substring($entryPath.Length) -replace '\\', '/' -replace ' ', '` '}
|
||||
$entryNames | Where-Object { $_ -like "$wordToComplete*" }
|
||||
}
|
||||
|
||||
function MUTNArgumentCompleter {
|
||||
param ( $commandName,
|
||||
$parameterName,
|
||||
$wordToComplete,
|
||||
$commandAst,
|
||||
$fakeBoundParameters )
|
||||
function MUTNOptionCompleter {
|
||||
param ($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
|
||||
|
||||
$possibleValues = @{
|
||||
add = @('password', 'note', 'folder')
|
||||
@@ -33,8 +28,8 @@ if ($fakeBoundParameters.ContainsKey('argument')) {
|
||||
function mutn {
|
||||
[CmdletBinding()]
|
||||
param (
|
||||
[Parameter(Mandatory=$false, Position = 0)]
|
||||
[ValidateSet([libmuttonEntries])]
|
||||
[Parameter(Position = 0)]
|
||||
[ArgumentCompleter({ MUTNEntryCompleter @args })]
|
||||
[string]$entry,
|
||||
|
||||
[Parameter(Position = 1)]
|
||||
@@ -42,9 +37,10 @@ function mutn {
|
||||
[string]$argument,
|
||||
|
||||
[Parameter(Position = 2)]
|
||||
[ArgumentCompleter({ MUTNArgumentCompleter @args })]
|
||||
[ArgumentCompleter({ MUTNOptionCompleter @args })]
|
||||
[string]$option
|
||||
)
|
||||
#Invoke-Expression -Command ('/usr/local/bin/mutn ' + ($entry -replace ' ', '` '), $argument, ($option -replace ':', '-')).Trim() # UNIX testing
|
||||
Invoke-Expression -Command ('mutn.exe ' + ($entry -replace ' ', '` '), $argument, $option).Trim()
|
||||
|
||||
Invoke-Expression -Command ('/usr/local/bin/mutn ' + ($entry -replace ' ', '` '), $argument, ($option -replace ':', '-')).Trim() # UNIX testing
|
||||
#Invoke-Expression -Command ('mutn.exe ' + ($entry -replace ' ', '` '), $argument, $option).Trim()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user