Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions custom-completions/pacman/pacman-completions.nu
Original file line number Diff line number Diff line change
@@ -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<short>[A-Za-z]),\s+)?--(?P<long>[a-z][a-z-]*)(?:\s+<[^>]+>)?\s+(?P<description>.+)$')
$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"
]
52 changes: 52 additions & 0 deletions custom-completions/pacman/readme.md
Original file line number Diff line number Diff line change
@@ -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 <yourpath>/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<Tab>` 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 -<operation> --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.
Loading