Skip to content

feat: add bash, zsh, and fish completions for termux-tools - #390

Open
SjnExe wants to merge 1 commit into
termux:masterfrom
SjnExe:add-shell-completions
Open

SjnExe wants to merge 1 commit into
termux:masterfrom
SjnExe:add-shell-completions

Conversation

@SjnExe

@SjnExe SjnExe commented Sep 7, 2026

Copy link
Copy Markdown

Adds tab completions for pkg, termux-open, termux-backup, termux-restore, termux-info, and chsh across Bash, Zsh, and Fish. Integrated into Autotools via completions/Makefile.am.

@SjnExe
SjnExe marked this pull request as ready for review September 7, 2026 16:51
@SjnExe

SjnExe commented Sep 7, 2026

Copy link
Copy Markdown
Author

If someone knows how to build binary and test this, please do and give me results

@SjnExe
SjnExe force-pushed the add-shell-completions branch 3 times, most recently from b6b3308 to 1ecb24a Compare September 7, 2026 22:03

@TomJo2000 TomJo2000 left a comment

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.

It would be nice for the pkg completions to use the existing apt or pacman completers.
Although I'm not 100% sure how to properly call another completer in a completer or if that's even possible.

I think complete -F should handle it for Bash, but I'm unsure about Zsh and Fish.

Comment thread completions/bash/pkg Outdated
Comment thread completions/bash/pkg Outdated
Comment thread completions/zsh/_pkg.in
Comment thread completions/fish/pkg.fish Outdated
@SjnExe

SjnExe commented Sep 12, 2026

Copy link
Copy Markdown
Author

Updated completions according to the review comments:

  • Subcommand aliasing: Matched case / switch patterns across Bash, Zsh, and Fish with the wildcard logic in pkg.in (add|i*, f*|rei*|un*|rem*|rm|del*, sh*|inf*), enabling completion for shorthand invocations such as pkg in, pkg rm, and pkg sh.
  • Package manager detection: Sourced termux-setup-package-manager in an isolated subshell with session caching and clean fallbacks for apt/pacman across Bash, Zsh, and Fish.
  • Fish completion syntax: Replaced hardcoded checks with dynamic commandline token evaluation and native Fish switch/case patterns.
  • Verification: Built from source and verified end-to-end completion resolution directly in Termux across Bash, Fish, and Zsh.

@SjnExe
SjnExe force-pushed the add-shell-completions branch from 1ecb24a to fd1965b Compare September 12, 2026 04:45
@SjnExe

SjnExe commented Sep 12, 2026

Copy link
Copy Markdown
Author

@TomJo2000 Now everything addressed?

@TomJo2000

TomJo2000 commented Sep 13, 2026

Copy link
Copy Markdown
Member

@TomJo2000 Now everything addressed?

I've left you a comment above regarding the LLM's "response" for why it doesn't wanna do this in a sane way (#390 (comment)).

Other than that I'm okay with the changes in the latest push (1ecb24a..fd1965b).

One more thing we should probably add as part of this PR is proper highlighting for the completions files in GitHub's code view.
That can be done via the .gitattributes file.
e.g.

# File syntax
‎completions/bash/* linguist-language=bash
‎completions/fish/* linguist-language=fish
‎completions/zsh/* linguist-language=zsh

(The fish line isn't strictly necessary but I think for consistency having it in there would be a good idea.)

@SjnExe
SjnExe force-pushed the add-shell-completions branch from fd1965b to b8b8445 Compare September 13, 2026 18:58
@SjnExe

SjnExe commented Sep 13, 2026

Copy link
Copy Markdown
Author

Added .gitattributes

@SjnExe
SjnExe requested a review from TomJo2000 September 13, 2026 19:09
@TomJo2000

Copy link
Copy Markdown
Member

Highlighting appears to work though not within this PR.

image

@SjnExe

SjnExe commented Sep 15, 2026

Copy link
Copy Markdown
Author

Yeah, GitHub only applies .gitattributes to PR diffs once it's in the base branch. Good to see it picked up on the tree view.

@SjnExe

SjnExe commented Sep 15, 2026

Copy link
Copy Markdown
Author

@TomJo2000 PR is ready for merge, right?

@TomJo2000 TomJo2000 left a comment

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.

Most of what I've written for the Bash completion also applies for Zsh.

Comment thread completions/bash/pkg Outdated
Comment thread completions/bash/pkg Outdated
Comment thread completions/bash/pkg Outdated
Comment thread completions/bash/pkg Outdated
Comment thread completions/zsh/_pkg.in
Comment thread completions/bash/pkg Outdated
@SjnExe
SjnExe force-pushed the add-shell-completions branch from b8b8445 to 2a13960 Compare September 15, 2026 20:45
@SjnExe

SjnExe commented Sep 15, 2026

Copy link
Copy Markdown
Author

Addressed the review feedback in the latest push:

  • Prefix substitution: Renamed chsh and pkg across Bash, Fish, and Zsh to .in templates using @TERMUX_PREFIX@, with substitution handled via $(do_subst) in completions/Makefile.am.
  • Bash refactoring: Extracted _pkg_available_packages and _pkg_installed_packages helper functions to eliminate repeated if/else checks inside the subcommand case block.
  • Syntax & quoting: Quoted assignments, passed $setup_pm directly as $0 to the subshell, and switched silent status checks to &>/dev/null across Bash and Zsh.
  • Zsh matching: Added se*) and *) fallthrough cases to keep parity with Bash.
  • Empty completions: Non-package subcommands (update, upgrade, clean, autoclean, etc.) return empty COMPREPLY=() to prevent shells from falling back to arbitrary local directory path completions.

@SjnExe
SjnExe force-pushed the add-shell-completions branch from 2a13960 to be080f7 Compare September 15, 2026 20:46
@SjnExe

SjnExe commented Sep 15, 2026

Copy link
Copy Markdown
Author

@TomJo2000 Now everything good?

Comment thread completions/bash/chsh.in Outdated
Comment thread completions/bash/chsh.in Outdated
Comment thread completions/bash/chsh.in Outdated
@SjnExe
SjnExe force-pushed the add-shell-completions branch from be080f7 to b6a2c1a Compare September 16, 2026 09:43
@SjnExe

SjnExe commented Sep 16, 2026

Copy link
Copy Markdown
Author

Updated chsh across Bash, Fish, and Zsh to check a list of known shells against PATH and only return installed ones.

Reverted chsh back to a regular completion file since it no longer needs @TERMUX_PREFIX@, leaving only pkg in the .in substitution list in completions/Makefile.am.

@SjnExe
SjnExe force-pushed the add-shell-completions branch from b6a2c1a to 00c0ad4 Compare September 16, 2026 09:57
@SjnExe

SjnExe commented Sep 16, 2026

Copy link
Copy Markdown
Author

@TomJo2000 Now everything addressed? No issues?

Comment thread completions/bash/chsh Outdated
Comment thread completions/bash/chsh
Comment thread completions/bash/chsh Outdated
Comment thread completions/bash/chsh
Comment thread completions/bash/chsh Outdated
Comment thread completions/bash/chsh Outdated
@SjnExe
SjnExe force-pushed the add-shell-completions branch from 00c0ad4 to f6f08bf Compare September 17, 2026 03:26
@SjnExe

SjnExe commented Sep 17, 2026

Copy link
Copy Markdown
Author

Updated the known shells list across all three shells:

  • Added ash, bsh, cicada, eltclsh, etsh, tsh, and preemptively added pwsh.
  • Replaced oksh with loksh.
  • Removed ion and yash, kept xonsh.

Also ran a full compilation and sandbox installation/uninstallation test via DESTDIR—all completions and xdg-open symlinks installed and uninstalled cleanly with 0 leftover files.

@SjnExe

SjnExe commented Sep 17, 2026

Copy link
Copy Markdown
Author

@TomJo2000 Now good?

@TomJo2000

Copy link
Copy Markdown
Member

I'll need to look at it after work.
But this is an iterative process.

Might take a while to find and address everything.
I'd also like to get some other people to take a look at these.

Comment thread completions/bash/chsh
@SjnExe
SjnExe force-pushed the add-shell-completions branch from f6f08bf to d72f3ad Compare September 18, 2026 11:14
@SjnExe

SjnExe commented Sep 18, 2026

Copy link
Copy Markdown
Author

Added beanshell alongside bsh across the completion scripts for all three shells.

Comment thread completions/bash/chsh
@SjnExe
SjnExe force-pushed the add-shell-completions branch from d72f3ad to f9a04df Compare September 21, 2026 03:16
@SjnExe

SjnExe commented Sep 21, 2026

Copy link
Copy Markdown
Author

Added osh and ysh (from oils-for-unix) to known_shells across Bash, Fish, and Zsh.

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.

2 participants