Skip to content

Add fish completions - #1153

Open
Vincent-Carrier wants to merge 1 commit into
medialab:masterfrom
Vincent-Carrier:fish-completions
Open

Vincent-Carrier wants to merge 1 commit into
medialab:masterfrom
Vincent-Carrier:fish-completions

Conversation

@Vincent-Carrier

Copy link
Copy Markdown

Closes #1152.

Adds a fish arm to xan completions, alongside bash and zsh.

Like the two existing scripts, the fish function delegates everything to xan compgen <cmd> <current> <previous> and implements no completion logic of its own, so all three shells track compgen.rs together.

Two details are fish-specific, both covered in the issue:

  • <previous> is passed verbatim where that works — notably the flags whose value is a column selector (-s, --select, -g, --groupby), which compgen matches by name. It falls back to the subcommand for xan select file.csv <TAB>, where the literal preceding word is the file name and so matches nothing. The fallback is conditional so it doesn't shadow the flags.
  • No -f on the complete, so fish keeps completing file names when compgen returns nothing — mirroring -o default in bash and _default in zsh. With -f, xan count <TAB> offered nothing at all.

Also updates the completions usage text, the README install section, and the changelog.

Testing

cargo build, cargo fmt and cargo clippy are clean, and ./scripts/docs.sh produces no changes (completions has no generated page).

The generated script was installed and driven with complete -C against real CSVs, exercising: subcommand listing, prefix filtering (xan sesearch/select), columns with and without an explicit file, per-file column resolution across two CSVs, comma-separated selectors (name,agname,age), -s/--select values, subcommand groups (xan help), and file-name fallback.

Delegates to `xan compgen` like the bash and zsh scripts.

The word before the cursor selects the completion mode, so it is passed
verbatim where that works, notably for the flags whose value is a column
selector (-s/--select, -g/--groupby). It does not work on
`xan select file.csv <TAB>`, where that word is the file name rather than
the subcommand, so the subcommand is used as a fallback when the literal
word matches nothing.

No -f on the complete, so that fish keeps completing file names when
compgen returns nothing, mirroring `-o default` in bash and `_default`
in zsh.
Comment thread src/cmd/completions.rs
# subcommand, so fall back to the subcommand when it matches nothing.
set -l previous $tokens[-1]

if not contains -- $previous -s --select -g --groupby

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this required? This looks like a repetition of xan compgen inner logic, no?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add fish completions

2 participants