Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Argument completion in bash doesn't work for aliases with arguments #5377

Open
DemvSteinbrink opened this issue Jan 16, 2025 · 1 comment
Open
Labels
🐛bug Something isn't working

Comments

@DemvSteinbrink
Copy link

DemvSteinbrink commented Jan 16, 2025

Description

For aliases, the bash completion is broken. It only completes one element and it's always completed to the first argument in the alias.

Steps to Reproduce the Problem

  1. Create an alias gp = ["git", "push"]
  2. source <(COMPLETE=bash jj)
  3. Type jj gp and then hit <Tab>

Expected Behavior

Completion behaves the same as if I had typed jj git push, i.e. it would add -- to my prompt.

Actual Behavior

The completion adds push to my prompt. It even replaces partial input with push, i.e. jj gp --he + <Tab> becomes jj gp push.

Specifications

  • Platform: Linux Debian Sid
  • Version: jj 0.25.0-041c4fecb77434dd6720e7d7f1ce48d9575ac5f7
@yuja
Copy link
Contributor

yuja commented Jan 16, 2025

Perhaps, it is the problem of _CLAP_COMPLETE_INDEX. Alias completion works only on fish right now.

jj/cli/src/cli_util.rs

Lines 3390 to 3402 in 646bdab

let arg_index: Option<usize> = env::var("_CLAP_COMPLETE_INDEX")
.ok()
.and_then(|s| s.parse().ok());
let resolved_aliases = if let Some(index) = arg_index {
// As of clap_complete 4.5.38, zsh completion script doesn't pad an
// empty arg at the complete position. If the args doesn't include a
// command name, the default command would be expanded at that
// position. Therefore, no other command names would be suggested.
// TODO: Maybe we should instead expand args[..index] + [""], adjust
// the index accordingly, strip the last "", and append remainder?
let pad_len = usize::saturating_sub(index + 1, orig_args.len());
let padded_args = orig_args.chain(iter::repeat(OsString::new()).take(pad_len));
expand_args(ui, app, padded_args, config)?

@yuja yuja added the 🐛bug Something isn't working label Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants