Skip to content

Commit

Permalink
completion: add branch name completions for fish
Browse files Browse the repository at this point in the history
  • Loading branch information
senekor committed May 19, 2024
1 parent 6d211c5 commit 20572e3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* `jj branch track` now show conflicts if there are some.

* Added custom completion of branch names to `jj branch` subcommands for fish.

### Fixed bugs

* When the working copy commit becomes immutable, a new one is automatically created on top of it
Expand Down
23 changes: 23 additions & 0 deletions cli/src/commands/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,29 @@ impl ShellCompletion {
Self::Zsh => generate(Shell::Zsh, cmd, bin_name, &mut buf),
}

// Append custom completions. The main purpose of these is to support
// dynamic completions, like branch names. This may be removed in the
// future when clap has builtin support for dynamic completions, see:
// https://github.com/clap-rs/clap/issues/1232
match self {
Self::Bash => {}
Self::Elvish => {}
Self::Fish => buf.write_all(CUSTOM_FISH_COMPLETIONS).unwrap(),
Self::Nushell => {}
Self::PowerShell => {}
Self::Zsh => {}
}

buf
}
}

static CUSTOM_FISH_COMPLETIONS: &[u8] = r#"
# dynamic branch name completions
complete -c jj -n "__fish_seen_subcommand_from branch; and __fish_seen_subcommand_from delete" -f -a "(jj branch list -T 'name ++ \"\n\"')"
complete -c jj -n "__fish_seen_subcommand_from branch; and __fish_seen_subcommand_from forget" -f -a "(jj branch list -T 'name ++ \"\n\"')"
complete -c jj -n "__fish_seen_subcommand_from branch; and __fish_seen_subcommand_from rename" -f -a "(jj branch list -T 'name ++ \"\n\"')"
complete -c jj -n "__fish_seen_subcommand_from branch; and __fish_seen_subcommand_from set" -f -a "(jj branch list -T 'name ++ \"\n\"')"
complete -c jj -n "__fish_seen_subcommand_from branch; and __fish_seen_subcommand_from track" -f -a "(jj branch list -a -T 'if(remote && !tracked, name ++ \"@\" ++ remote ++ \"\n\")')"
complete -c jj -n "__fish_seen_subcommand_from branch; and __fish_seen_subcommand_from untrack" -f -a "(jj branch list -a -T 'if(tracked && !\"git\".contains(remote), name ++ \"@\" ++ remote ++ \"\n\")')"
"#.as_bytes();

0 comments on commit 20572e3

Please sign in to comment.