From 60feefc65b7116ae38a0adbcbd87ca4eab59cef9 Mon Sep 17 00:00:00 2001 From: mrl00 Date: Wed, 18 Nov 2026 20:40:01 -0300 Subject: [PATCH 1/3] pacman completions: native, operation-aware flags from installed help ### Description Add custom-completions/pacman/pacman-completions.nu with a single pacman extern and a native Nushell completer using the token and place records supported by Nushell 0.117.0. How a completion request is resolved: no operation selected -> suggest short and long operation names operation selected -> read pacman - --help current token is --* -> suggest long options with help descriptions current token is -Q -> suggest combined short options such as -Qi non-option token -> return null for default completion Recognize database, files, query, remove, sync, deptest and upgrade operations in both short and long form. Read option names and descriptions from the installed pacman instead of maintaining a separate flag table for each operation. Help and version are also offered at the top level. The extern deliberately declares no flags. Arguments use external_arg so Nushell does not rewrite short options or impose declared-flag parsing on pacman arguments. Completion requires neither Fish nor Carapace. ### Scope and limitations This contribution completes operations and flags, not package names or operation-specific argument values. Help parsing expects the current pacman option-line format; wrapped description continuations are not joined. Combined short flags are formed by appending the suggested flag to the current token, without checking duplicates or incompatible flags. ### Validation - Passed toolkit check pr --and-exit with the new file supplied explicitly. - Verified commandline complete --detailed for pacman -Q, pacman -Q -, and pacman -S -- on Nushell 0.117.0. - Confirmed the local Nushell configuration passes nu-check after import. The toolkit currently performs parsing/lint checks; its logic-test runner is not implemented. --- .../pacman/pacman-completions.nu | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 custom-completions/pacman/pacman-completions.nu diff --git a/custom-completions/pacman/pacman-completions.nu b/custom-completions/pacman/pacman-completions.nu new file mode 100644 index 00000000..c692664e --- /dev/null +++ b/custom-completions/pacman/pacman-completions.nu @@ -0,0 +1,53 @@ +# nu-version: 0.117.0 +# Completions nativas: opções extraídas da ajuda da versão instalada. +def "nu-complete pacman" [token: record, place: record] { + let operations = [ + {short: h, long: help, description: "Mostrar ajuda"} + {short: V, long: version, description: "Mostrar versão"} + {short: D, long: database, description: "Modificar a base de dados"} + {short: F, long: files, description: "Consultar arquivos nos repositórios"} + {short: Q, long: query, description: "Consultar pacotes instalados"} + {short: R, long: remove, description: "Remover pacotes"} + {short: S, long: sync, description: "Sincronizar e instalar pacotes"} + {short: T, long: deptest, description: "Verificar dependências"} + {short: U, long: upgrade, description: "Instalar arquivo de pacote"} + ] + let words = ($place.command | skip 1) + let operation = ($operations | where {|op| + $op.short not-in [h V] and ($words | any {|word| + $word == $"--($op.long)" or ( + ($word starts-with '-') and not ($word starts-with '--') + and ($word | str substring 1.. | str contains $op.short) + ) + }) + } | first 1) + let text = $token.text + if ($operation | is-empty) { + return ($operations | each {|op| + [ + {value: $"-($op.short)", description: $op.description} + {value: $"--($op.long)", description: $op.description} + ] + } | flatten) + } + if ($text | is-not-empty) and not ($text starts-with '-') { return null } + let help = (^pacman $"-($operation.0.short)" --help | complete) + if $help.exit_code != 0 { return null } + let options = ($help.stdout | lines | parse --regex '^\s+(?:-(?P[A-Za-z]),\s+)?--(?P[a-z][a-z-]*)(?:\s+<[^>]+>)?\s+(?P.+)$') + $options | each {|option| + let long = {value: $"--($option.long)", description: $option.description} + if ($text starts-with '--') or ($option.short | is-empty) { + [$long] + } else { + let prefix = if ($text | str length) > 1 { $text } else { "-" } + [ + {value: $"($prefix)($option.short)", description: $option.description} + $long + ] + } + } | flatten +} + +export extern pacman [ + ...args: external_arg@"nu-complete pacman" +] From c62bc35e477f22e4a009fc7fc16b24b81c3287ab Mon Sep 17 00:00:00 2001 From: mrl00 Date: Wed, 18 Nov 2026 20:54:06 -0300 Subject: [PATCH 2/3] pacman completions: document installation, usage and limitations ### Description Add readme.md alongside the pacman completion module. Link to the official pacman website for documentation and source downloads, explain that pacman ships with Arch Linux, and note availability through distribution packages. Document the Nushell version tested, the PATH requirement, and the import to add to config.nu. Include Tab-completion examples for short operations, long operations, combined short flags and long options. Explain how operation-specific help supplies native suggestions without Fish or Carapace. Document the current limits around package names, option values, wrapped help descriptions and duplicate or incompatible flags. ### Validation Documentation-only change. The import path matches the module location and the examples reflect the previously verified completion behavior. --- custom-completions/pacman/readme.md | 52 +++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 custom-completions/pacman/readme.md diff --git a/custom-completions/pacman/readme.md b/custom-completions/pacman/readme.md new file mode 100644 index 00000000..1afab629 --- /dev/null +++ b/custom-completions/pacman/readme.md @@ -0,0 +1,52 @@ +# Pacman completions + +Native Nushell completions for [pacman](https://archlinux.org/pacman/), +the package manager used by Arch Linux and related distributions. + +## Requirements + +- Nushell 0.117.0 or later (tested with 0.117.0). +- `pacman` available on `PATH`. + +Pacman is included with Arch Linux. For documentation and source downloads, +see the [official pacman website](https://archlinux.org/pacman/). +On other distributions, consult your distribution's package repositories +for availability. + +## Usage + +Add this import to your Nushell `config.nu`, adjusting the repository path: + +```nu +use ~/Projects/nu_scripts/custom-completions/pacman/pacman-completions.nu * +``` + +Open a new Nushell session, or run the import in your current session. +Then press Tab after any of these examples: + +```text +pacman - +pacman -Q +pacman -Q - +pacman -S -- +pacman --query -- +``` + +The module suggests operation names and operation-specific flags with +descriptions. For example, `pacman -Q` offers combined short flags +such as `-Qi`, `-Ql`, and `-Qs`. + +## How it works + +A single `extern` passes arguments through without declaring flags. +The native completer identifies the operation and reads its options from +`pacman - --help`, using the installed version's help output. +Neither Fish nor Carapace is required. + +## Limitations + +- Package names and operation-specific argument values are not completed. +- Parsing expects pacman's current option-line format; wrapped description + continuations are not included. +- Combined short-flag suggestions do not check for duplicates or + incompatible flags. From 2434bae02351a5f32ed48e1e46d876c7e04232e4 Mon Sep 17 00:00:00 2001 From: mrl00 Date: Wed, 18 Nov 2026 20:59:25 -0300 Subject: [PATCH 3/3] docs: fix readme --- custom-completions/pacman/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom-completions/pacman/readme.md b/custom-completions/pacman/readme.md index 1afab629..962f6734 100644 --- a/custom-completions/pacman/readme.md +++ b/custom-completions/pacman/readme.md @@ -18,7 +18,7 @@ for availability. Add this import to your Nushell `config.nu`, adjusting the repository path: ```nu -use ~/Projects/nu_scripts/custom-completions/pacman/pacman-completions.nu * +use /nu_scripts/custom-completions/pacman/pacman-completions.nu * ``` Open a new Nushell session, or run the import in your current session.