diff --git a/custom-completions/winget/winget-completions.nu b/custom-completions/winget/winget-completions.nu index fa2d8b80..91d7c3db 100644 --- a/custom-completions/winget/winget-completions.nu +++ b/custom-completions/winget/winget-completions.nu @@ -80,63 +80,6 @@ def "nu-complete winget install id" [] { } } -def "nu-complete winget parse table" [lines: any] { - let header = ( - $lines - | first - | parse -r '(?PName\s+)(?PId\s+)(?PVersion\s+)?(?PMatch\s+)?(?PAvailable\s+)?(?PSource\s*)?' - | first - ) - let lengths = { - name: ($header.name | str length), - id: ($header.id | str length), - version: ($header.version | default "" | str length), - match: ($header.match | default "" | str length), - available: ($header.available | default "" | str length), - source: ($header.source | default "" | str length) - } - $lines | skip 2 | each { |it| - let it = ($it | split chars) - - let version = if $lengths.version > 0 { - ( - $it | skip ($lengths.name + $lengths.id) - | first $lengths.version | str join | str trim - ) - } else { "" } - - let match = if $lengths.match > 0 { - ( - $it | skip ($lengths.name + $lengths.id + $lengths.version) - | first $lengths.match | str join | str trim - ) - } else { "" } - - let available = if $lengths.available > 0 { - ( - $it | skip ($lengths.name + $lengths.id + $lengths.version + $lengths.match) - | first $lengths.available | str join | str trim - ) - } else { "" } - - let source = if $lengths.source > 0 { - ( - $it | skip ($lengths.name + $lengths.id + $lengths.version + $lengths.match + $lengths.available) - | str join | str trim - ) - } else { "" } - - { - name: ($it | first $lengths.name | str join | str trim), - id: ($it | skip $lengths.name | first $lengths.id | str join | str trim), - version: $version, - match: $match, - available: $available, - source: $source - } - } -} - export extern winget [ --version(-v), # Display the version of the tool --info, # Display general info of the tool @@ -251,7 +194,7 @@ export extern "winget source update" [ --name(-n): string, # Name of the source --help(-?) # Display the help for this command ] -export alias "winget source refresh" = winet source update +export alias "winget source refresh" = winget source update # Remove current sources export extern "winget source remove" [ @@ -315,15 +258,18 @@ export def "winget search" [ | where { not ($in | is-empty) } ) - let output = (^winget ...$params) + let output = ^winget ...$params + # remove loading symbols at start of output + | str replace -r r#'^[^\w]*'# "" if $raw or $help { $output } else { - let lines = ($output | lines) + let lines = ($output | detect columns --guess) | rename name id version match source if ($lines | length) == 1 { - $"(ansi light_red)($lines | first)(ansi reset)" + print -e $"(ansi light_red)($output)(ansi reset)" + null } else { - nu-complete winget parse table $lines | select name id version source + $lines } } } @@ -373,19 +319,20 @@ export def "winget list" [ ) let output = ^winget ...$params + # remove loading symbols at start of output + | str replace -r r#'^[^\w]*'# "" if $help or $raw { $output } else { - let lines = ($output | lines) + let lines = ($output | detect columns --guess) | rename name id version available source if ($lines | length) == 1 { - $"(ansi light_red)($lines | first)(ansi reset)" + print -e $"(ansi light_red)($output)(ansi reset)" + null } else { - let truncated = $lines | last | $in == "" - nu-complete winget parse table (if $truncated { $lines | drop } else { $lines }) - | reject match - # Because of a bug: https://github.com/microsoft/winget-cli/issues/4236 - # we need to filter it with the "where" command - | if ($source | is-not-empty) { $in | where source == $source } else { $in } + $lines + # Because of a bug: https://github.com/microsoft/winget-cli/issues/4236 + # we need to filter it with the "where" command + | if ($source | is-not-empty) { $in | where source == $source } else { $in } } } }