Skip to content

Zsh completions - #1133

Closed
sinbad wants to merge 14 commits into
masterfrom
zsh-completions
Closed

sinbad wants to merge 14 commits into
masterfrom
zsh-completions

Conversation

@sinbad

@sinbad sinbad commented Apr 8, 2016

Copy link
Copy Markdown
Contributor

Replaces #727

Generates the zsh completion script dynamically from a combination of Cobra data and the ManPages dictionary. Tested with ohmyzsh so far.

So far only works with git-lfs command, not git lfs. I've tried to make this work and I can get as far as overriding the git completion in this script, but can't figure out how to only override it for the lfs subcommand and delegate back to the original completions for everything else. My script-fu is not strong enough yet.


"github.com/github/git-lfs/vendor/_nuts/github.com/spf13/pflag"

"github.com/github/git-lfs/vendor/_nuts/github.com/spf13/cobra"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you run goimports? Seems like it should've removed that blank line on line 11.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, my Sublime setup runs goimports every time I save, it obviously doesn't strips blanks.

@technoweenie technoweenie mentioned this pull request Apr 11, 2016
16 of 17 tasks
Comment thread commands/command_init.go
)

func initCommand(cmd *cobra.Command, args []string) {
fmt.Fprintf(os.Stderr, "WARNING: 'git lfs init' is deprecated. Use 'git lfs install' now.\n")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why'd you take these warnings out?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm using the Deprecated string on cobra.Command instead which prints a warning when you use it (also lets me detect deprecated commands and ignore them)

@technoweenie

Copy link
Copy Markdown
Contributor

This works pretty well, but I don't think it's quite ready for v1.2.

First, subcommand arguments don't work:

$ git-lfs fetch _arguments:450: command not found: __git_remotes
_arguments:450: command not found: __git_branch_names
_arguments:450: command not found: __git_remotes
_arguments:450: command not found: __git_branch_names
_arguments:450: command not found: __git_remotes
_arguments:450: command not found: __git_branch_names

$ git-lfs pre-push _arguments:450: command not found: __git_remote_branch_names
_arguments:450: command not found: __git_remote_branch_names
_arguments:450: command not found: __git_remote_branch_names

Second, I'd still really like to figure out how to autocomplete with git lfs, so it'd be useful to a wide variety of users.

A "nice to have" would be some integration with git lfs install or git lfs update. I'd love to set it up (maybe through a --global git config value) to write the zsh (and other potential integrations) to some location I setup. Then they automatically update every time I update Git LFS.

@sinbad

sinbad commented Apr 12, 2016

Copy link
Copy Markdown
Contributor Author

Do you have the git auto completions enabled? As in the original PR this script depends on them, that's where the __git_* functions are defined.

Yeah I'd really like to autocomplete git lfs too and I couldn't figure out how to do it. Would be great if someone with better knowledge of zsh could pitch in now it's automated.

@technoweenie

Copy link
Copy Markdown
Contributor

I have some form of git autocompletions, though I may want to investigate further.

1__technoweenie_ops-bastion4-cp1-prd_____zsh__and_zsh_completions_by_sinbad_ _pull_request__1133_ _github_git-lfs

@technoweenie

technoweenie commented Aug 18, 2016 •

Copy link
Copy Markdown
Contributor

I hate to kill this, you did great work @sinbad. I just don't think it's worth doing if it doesn't work with git lfs ....

EDIT: of course we can always bring it back if someone can figure it out.

@technoweenie
technoweenie deleted the zsh-completions branch August 18, 2016 16:30
@robobenklein

Copy link
Copy Markdown

You should be able to get git lfs completions working the same way that git flow completions are handled:

zstyle ':completion:*:*:git:*' user-commands flow:'provide high-level repository operations'

See the end of https://github.com/bobthecow/git-flow-completion/blob/master/git-flow-completion.zsh

@ttaylorr
ttaylorr restored the zsh-completions branch June 11, 2018 20:08
@ttaylorr

Copy link
Copy Markdown
Contributor

@robobenklein I wasn't able to make this work with the snippet you provided (switching flow for lfs). Can you advise?

@robobenklein

Copy link
Copy Markdown

I have yet to define any of the subcommands yet, but I get first-level completion for git lfs * using what I have currently: https://github.com/robobenklein/configs/blob/e6b0c03566f025641a7d76fd26b662fa96911923/zsh/fpath/_git-lfs.zsh_completion

Note that the subcommand completions need to be sourced to run the zstyle setup for it. For git-lfs it works without the need to source it as long as it's fpath registered.

It gives me completion like this:

robo@robo-unseptium ~> git lfs <tab>
checkout   -- Populate working copy with real content from Git LFS files.
clone      -- Efficiently clone a Git LFS-enabled repository.
env        -- Display the Git LFS environment.
fetch      -- Download Git LFS files from a remote.
fsck       -- Check Git LFS files for consistency.
install    -- Install Git LFS configuration.
lock       -- Set a file as "locked" on the Git LFS server.
locks      -- List currently "locked" files from the Git LFS server.
logs       -- Show errors from the git-lfs command.
ls-files   -- Show information about Git LFS files in the index and working tree.
migrate    -- Migrate history to or from git-lfs
prune      -- Delete old Git LFS files from local storage
pull       -- Fetch LFS changes from the remote & checkout any required working tree files.
push       -- Push queued large files to the Git LFS endpoint.
status     -- Show the status of Git LFS files in the working tree.
track      -- View or add Git LFS paths to Git attributes.
uninstall  -- Uninstall Git LFS by removing hooks and smudge/clean filter configuration.
unlock     -- Remove "locked" setting for a file on the Git LFS server.
untrack    -- Remove Git LFS paths from Git Attributes.
update     -- Update Git hooks for the current Git repository.

@ttaylorr

Copy link
Copy Markdown
Contributor

Hi @robobenklein, I can confirm that your script completes correctly for command invocations of the form git-lfs _, but I agree with technoweenie above and would prefer that we complete git lfs _ (note the missing -) as well.

It looks like git/git@085e2ee allows us to do just that.

If you're interested in working on this topic, can you please prepare something that will work with the above?

@robobenklein

Copy link
Copy Markdown

Got it working with both git lfs and git-lfs as of this version: https://github.com/robobenklein/configs/blob/433eca4021efd31f7bc989a2f7e25f0ba88e898c/zsh/fpath/_git-lfs

You should just be able to drop it in the fpath now. Also implemented fetch/ls-files/push subcommands.

https://asciinema.org/a/MXbve4MbOHo7dpnc4r2lhdpPC (alias g=git)

I don't know what that _git completion error is though, can somebody check if that's just me?

@robobenklein

robobenklein commented Jul 30, 2018 •

Copy link
Copy Markdown

I have working ZSH completion for git-lfs and git lfs now.

https://github.com/robobenklein/configs/blob/007dcd1f4eb9a4cb42ba7558d161d9b2d6bd89c9/zsh/fpath/_git-lfs

With the last updates to git, the only step required to install is to add that _git-lfs file to ZSH's fpath.

I can continue to expand/finish this handwritten version, or I could start on the automatic generation of the script like this PR had - but I'm not familiar with Go so it might take be a bit longer.

@sinbad are you still interested in working on this issue? If so, I'd be willing to help out with whatever ZSH-specific issues you have.

@ttaylorr

ttaylorr commented Aug 8, 2018

Copy link
Copy Markdown
Contributor

I have working ZSH completion for git-lfs and git lfs now.

https://github.com/robobenklein/configs/blob/007dcd1f4eb9a4cb42ba7558d161d9b2d6bd89c9/zsh/fpath/_git-lfs

Hi, when I attempt to install this, I get:

$ echo $0
-zsh
$ pbpaste > _git-lfs.zsh
$ source _git-lfs.zsh
_arguments:comparguments:325: can only be called from completion function

But I am still hesitant to ship a ZSH-only solution, when built-in Git support is coming in a future release (as noted above.)

@robobenklein

Copy link
Copy Markdown

Ah, there's not really the install step like there was with the previous solution.

The _git-lfs completion file needs to placed in the fpath which can be done when packaging a deb for example.

On Ubuntu, it would look like this: /usr/share/zsh/functions/Completion/Unix/_git-lfs, next to the git completion _git in the same folder.

@chrisd8088
chrisd8088 deleted the zsh-completions branch December 24, 2022 03:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants