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

Tab-complete branch names for jj branch subcommands #1217

Open
chooglen opened this issue Feb 8, 2023 · 3 comments
Open

Tab-complete branch names for jj branch subcommands #1217

chooglen opened this issue Feb 8, 2023 · 3 comments
Labels
polish🪒🐃 Make existing features more convenient and more consistent

Comments

@chooglen
Copy link
Collaborator

chooglen commented Feb 8, 2023

Tab-completing branch names would be useful for all branch subcommands today execpt list.

e.g. I run into this on a regular basis:

$ jj branch delete # wait what that branch again?
$ jj branch list
$ jj branch delete <furiously typed branch name and/or copied>

or

$ jj branch set <typo-ed branch name>
# Ugh
$ jj undo
$ jj branch set <correct branch name>

It seems that Clap completion doesn't have support for this yet clap-rs/clap#1232.

@chooglen chooglen added the polish🪒🐃 Make existing features more convenient and more consistent label Feb 8, 2023
@senekor
Copy link
Contributor

senekor commented May 19, 2024

Here are my custom additions to the auto-generated completions (fish shell):

complete -c jj -n "__fish_seen_subcommand_from branch; and __fish_seen_subcommand_from delete" -f -a "(jj branch list | cut --delimiter ':' --fields 1)"
complete -c jj -n "__fish_seen_subcommand_from branch; and __fish_seen_subcommand_from forget" -f -a "(jj branch list | cut --delimiter ':' --fields 1)"
complete -c jj -n "__fish_seen_subcommand_from branch; and __fish_seen_subcommand_from rename" -f -a "(jj branch list | cut --delimiter ':' --fields 1)"
complete -c jj -n "__fish_seen_subcommand_from branch; and __fish_seen_subcommand_from set" -f -a "(jj branch list | cut --delimiter ':' --fields 1)"
complete -c jj -n "__fish_seen_subcommand_from branch; and __fish_seen_subcommand_from track" -f -a "(jj branch list --all-remotes | cut --delimiter ':' --fields 1 | grep '\w@\w')"
complete -c jj -n "__fish_seen_subcommand_from branch; and __fish_seen_subcommand_from untrack" -f -a '(
for line in (jj branch list -a | cut --delimiter ":" --fields 1)
    if echo $line | grep --quiet "^\S"
        set --function __local_branch $line
        continue
    end
    if [ $line = "  @git" ]
        continue
    end
    echo "$__local_branch$(string trim $line)"
end
set --erase __local_branch
)'

As mentioned in this comment, adding that to the output of jj util completion should be simple.

I would be happy to make that contribution, unless maintainers consider this an undue maintenance burden. In my opinion, if it does turn out to be a burden, it can just be deleted again. I don't think shell completions come with any expection of stability.

@martinvonz
Copy link
Owner

That seems fine to me.

Since #3651, jj branch list | cut --delimiter ':' --fields 1 can be replaced by jj branch list -T 'name ++ "\n"'. Maybe the untrack script can also be simplified somehow.

@senekor
Copy link
Contributor

senekor commented May 19, 2024

Great! I didn't think of using templates, great idea. I'll see how simple I can make it and open a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
polish🪒🐃 Make existing features more convenient and more consistent
Projects
None yet
Development

No branches or pull requests

3 participants