[wiki/MUTN] Add basic building/installation instructions

This commit is contained in:
2024-07-07 22:59:55 -04:00
parent 995e2bd982
commit 565f869da1
8 changed files with 153 additions and 19 deletions
+42
View File
@@ -0,0 +1,42 @@
# mutn(1) completion
_path_gen() {
local mutnPath="$HOME/.local/share/libmutton"
local globStatus=$(shopt -p globstar)
[ -z "${globStatus##*u*}" ] && shopt -s globstar # if recursive globbing is disabled, enable it
local fullPaths=("$mutnPath"/**/*)
$globStatus # set recursive globbing to user default
for scanPath in "${fullPaths[@]}"; do
# exclude directories
[ -f "$scanPath" ] && trimmedPaths+=("${scanPath#$mutnPath}")
done
if [ "${trimmedPaths[0]}" == '' ]; then trimmedPaths[0]=help; fi
} &&
_mutnCompletions() {
local cur=${COMP_WORDS[COMP_CWORD]}
local prev=${COMP_WORDS[COMP_CWORD-1]}
case $prev in
mutn )
while read -r; do ITEM=${REPLY// /\\ }; COMPREPLY+=( "$ITEM" ); done < <( compgen -W "$(printf "'%s' " "${trimmedPaths[@]}")" -- "$cur" )
;;
/* )
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "copy edit gen add shear" -- "$cur" )
;;
add )
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "password note folder" -- "$cur" )
;;
copy )
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "password username totp url note" -- "$cur" )
;;
edit )
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "password username totp url note rename" -- "$cur" )
;;
gen )
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "update" -- "$cur" )
;;
esac
} &&
_path_gen && complete -F _mutnCompletions mutn
+55
View File
@@ -0,0 +1,55 @@
function cliMUTNEntryCompleter {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
#$mutnPath = (Resolve-Path '~/.local/share/libmutton').Path # UNIX testing
$mutnPath = (Resolve-Path '~/AppData/Local/libmutton/entries').Path
try {
$trimmedPaths = If (Test-Path $mutnPath) {
(Get-ChildItem -Path $mutnPath -Recurse -File).FullName.Substring($mutnPath.Length) -replace '\\', '/' -replace ' ', '` '
}
} catch {
$trimmedPaths = $null # if any errors occur (especially, "You cannot call a method on a null-valued expression", set $trimmedPaths to $null
}
if ($null -eq $trimmedPaths) { # if no entries are found, add 'help' to $trimmedPaths
$trimmedPaths = 'help'
}
$trimmedPaths | Where-Object { $_ -like "$wordToComplete*" }
}
function cliMUTNOptionCompleter {
param ($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
$possibleValues = @{
add = @('password', 'note', 'folder')
copy = @('password', 'username', 'totp', 'url', 'note')
edit = @('password', 'username', 'totp', 'url', 'note', 'rename')
gen = @('update')
}
if ($fakeBoundParameters.ContainsKey('argument')) {
$possibleValues[$fakeBoundParameters.argument] | Where-Object {
$_ -like "$wordToComplete*"
}
} else {
$possibleValues.Values | ForEach-Object {$_}
}
}
function mutn {
[CmdletBinding()]
param (
[Parameter(Position = 0)]
[ArgumentCompleter({ cliMUTNEntryCompleter @args })]
[string]$entry,
[Parameter(Position = 1)]
[ArgumentCompletions('copy', 'edit', 'gen', 'add', 'shear')]
[string]$argument,
[Parameter(Position = 2, ValueFromRemainingArguments=$true)]
[ArgumentCompleter({ cliMUTNOptionCompleter @args })]
[string]$option
)
#Invoke-Expression -Command ('/usr/local/bin/mutn ' + ($entry -replace ' ', '` '), $argument, $option).Trim() # UNIX testing
Invoke-Expression -Command ('./mutn.exe ' + ($entry -replace ' ', '` '), $argument, $option).Trim()
}
+31
View File
@@ -0,0 +1,31 @@
#compdef mutn
mutnPath="$HOME/.local/share/libmutton"
fullPaths=("$mutnPath"/**/*)
trimmedPaths=()
for scanPath in "${fullPaths[@]}"; do
# exclude directories
[ -f "$scanPath" ] && trimmedPaths+=("${scanPath#$mutnPath}")
done
[[ -z $trimmedPaths ]] && trimmedPaths=(help)
case ${words[-2]} in
mutn )
compadd $trimmedPaths
;;
/* )
compadd {copy,edit,gen,add,shear}
;;
add )
compadd {password,note,folder}
;;
copy )
compadd {password,username,totp,url,note}
;;
edit )
compadd {password,username,totp,url,note,rename}
;;
gen )
compadd update
;;
esac