mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-01 14:47:47 +00:00
Fix winget completions (#171)
Fix regex strings so they work with the new escaping syntax Use completion options to offer better suggestions Fix issue with `nu-complete winget uninstall package name`
This commit is contained in:
parent
1edddaf160
commit
490e6c9d9b
1 changed files with 14 additions and 7 deletions
|
@ -91,7 +91,7 @@ def "winget show" [
|
|||
} else if ($output | first) =~ "No package found matching input criteria." {
|
||||
$"(ansi yellow)($output | first | str trim)(ansi reset)"
|
||||
} else {
|
||||
let header = ($output | first | parse -r "Found (?P<Name>.+) \[(?P<Id>.+)\]")
|
||||
let header = ($output | first | parse -r 'Found (?P<Name>.+) \[(?P<Id>.+)\]')
|
||||
let manifest = ($output | skip 1 | str collect (char newline) | from yaml)
|
||||
$header | first | merge { $manifest }
|
||||
}
|
||||
|
@ -209,7 +209,7 @@ def "winget search" [
|
|||
if ($output | length) == 1 {
|
||||
$"(ansi light_red)($output | first)(ansi reset)"
|
||||
} else {
|
||||
nu-complete winget parse table $output | select name id version
|
||||
nu-complete winget parse table $output | select name id version source
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -361,11 +361,11 @@ def "nu-complete winget install locale" [] {
|
|||
}
|
||||
|
||||
def "nu-complete winget install source" [] {
|
||||
^winget source list | lines | skip 2 | split column ' ' | get column1
|
||||
^winget source list | lines | skip 2 | split column ' ' | get column1
|
||||
}
|
||||
|
||||
def "nu-complete winget install scope" [] {
|
||||
["user", "machine"]
|
||||
["user", "machine"]
|
||||
}
|
||||
|
||||
def "nu-complete winget source type" [] {
|
||||
|
@ -391,13 +391,13 @@ def "nu-complete winget uninstall package id" [] {
|
|||
}
|
||||
|
||||
def "nu-complete winget uninstall package name" [] {
|
||||
winget list structured | get Name | str trim | str find-replace "…" "..."
|
||||
winget list | get name | str trim | str find-replace "…" "..."
|
||||
}
|
||||
|
||||
def "nu-complete winget install name" [] {
|
||||
let path = ($env.TMP | path join winget-packages.csv)
|
||||
|
||||
if ($path | path exists) && (ls $path | first | get modified | ((date now) - $in) < 1day) {
|
||||
let completions = if ($path | path exists) && (ls $path | first | get modified | ((date now) - $in) < 1day) {
|
||||
open $path | get name | each { |it| $"(char dq)($it)(char dq)" } | str find-replace "…" ""
|
||||
} else {
|
||||
# Chinese characters break parsing, filter broken entries with `where source == winget`
|
||||
|
@ -405,6 +405,13 @@ def "nu-complete winget install name" [] {
|
|||
$data | save $path | ignore
|
||||
$data | get name | each { |it| $"(char dq)($it)(char dq)" } | str find-replace "…" ""
|
||||
}
|
||||
{
|
||||
completions: $completions
|
||||
options: {
|
||||
case_sensitive: $false
|
||||
positional: $false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def "nu-complete winget install id" [] {
|
||||
|
@ -423,7 +430,7 @@ def "nu-complete winget install id" [] {
|
|||
def "nu-complete winget parse table" [lines: any] {
|
||||
let header = (
|
||||
$lines | first
|
||||
| parse -r "(?P<name>Name\s+)(?P<id>Id\s+)(?P<version>Version\s+)?(?P<available>Available\s+)?(?P<source>Source\s*)?"
|
||||
| parse -r '(?P<name>Name\s+)(?P<id>Id\s+)(?P<version>Version\s+)?(?P<available>Available\s+)?(?P<source>Source\s*)?'
|
||||
| first
|
||||
)
|
||||
let lengths = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue