Add completions for git blame command #3094

Merged
merged 1 commit into from Jun 2, 2016

Projects

None yet

4 participants

@Hunsu
Contributor
Hunsu commented May 31, 2016

I would like to know how to test it.

@faho
Member
faho commented May 31, 2016

Thanks for doing this!

I would like to know how to test it.

You copy the file into a directory in $fish_complete_path, e.g. ~/.config/fish/completions, and then just use it.

I'm gonna add some more comments inline.

@faho faho commented on an outdated diff May 31, 2016
share/completions/git.fish
@@ -645,5 +645,32 @@ complete -f -c git -n '__fish_git_using_command clean' -s x -d 'Remove ignored f
complete -f -c git -n '__fish_git_using_command clean' -s X -d 'Remove only ignored files'
# TODO -e option
+### git blame
+complete -f -c git -n '__fish_git_needs_command' -a blame -d 'Show what revision and author last modified each line of a file'
+complete -f -c git -n '__fish_git_using_command blame' -s b -d 'Show blank SHA-1 for boundary commits'
+complete -f -c git -n '__fish_git_using_command blame' -l root -d 'Do not treat root commits as boundaries'
+complete -f -c git -n '__fish_git_using_command blame' -l show-stats -d 'Include additional statistics at the end of blame output'
@faho
faho May 31, 2016 Member

The "of blame output" is a bit redundant.

@faho faho commented on an outdated diff May 31, 2016
share/completions/git.fish
@@ -645,5 +645,32 @@ complete -f -c git -n '__fish_git_using_command clean' -s x -d 'Remove ignored f
complete -f -c git -n '__fish_git_using_command clean' -s X -d 'Remove only ignored files'
# TODO -e option
+### git blame
+complete -f -c git -n '__fish_git_needs_command' -a blame -d 'Show what revision and author last modified each line of a file'
+complete -f -c git -n '__fish_git_using_command blame' -s b -d 'Show blank SHA-1 for boundary commits'
+complete -f -c git -n '__fish_git_using_command blame' -l root -d 'Do not treat root commits as boundaries'
+complete -f -c git -n '__fish_git_using_command blame' -l show-stats -d 'Include additional statistics at the end of blame output'
+complete -f -c git -n '__fish_git_using_command blame' -s L -d 'Annotate only the given line range'
+complete -f -c git -n '__fish_git_using_command blame' -s l -d 'Show long rev'
+complete -f -c git -n '__fish_git_using_command blame' -s t -d 'Show raw timestamp'
+complete -f -c git -n '__fish_git_using_command blame' -s S -d 'Use revisions from revs-file instead of calling git-rev-list'
@faho
faho May 31, 2016 Member

This needs a file as argument, that's the "revs-file". How about "Use revisions from named file instead of calling rev-list"?

@faho faho commented on an outdated diff May 31, 2016
share/completions/git.fish
@@ -645,5 +645,32 @@ complete -f -c git -n '__fish_git_using_command clean' -s x -d 'Remove ignored f
complete -f -c git -n '__fish_git_using_command clean' -s X -d 'Remove only ignored files'
# TODO -e option
+### git blame
+complete -f -c git -n '__fish_git_needs_command' -a blame -d 'Show what revision and author last modified each line of a file'
+complete -f -c git -n '__fish_git_using_command blame' -s b -d 'Show blank SHA-1 for boundary commits'
+complete -f -c git -n '__fish_git_using_command blame' -l root -d 'Do not treat root commits as boundaries'
+complete -f -c git -n '__fish_git_using_command blame' -l show-stats -d 'Include additional statistics at the end of blame output'
+complete -f -c git -n '__fish_git_using_command blame' -s L -d 'Annotate only the given line range'
+complete -f -c git -n '__fish_git_using_command blame' -s l -d 'Show long rev'
+complete -f -c git -n '__fish_git_using_command blame' -s t -d 'Show raw timestamp'
+complete -f -c git -n '__fish_git_using_command blame' -s S -d 'Use revisions from revs-file instead of calling git-rev-list'
+complete -f -c git -n '__fish_git_using_command blame' -l reverse -d 'Walk history forward instead of backward'
+complete -f -c git -n '__fish_git_using_command blame' -s p -l porcelain -d 'Show in a format designed for machine consumption'
+complete -f -c git -n '__fish_git_using_command blame' -l line-porcelain -d 'Show the porcelain format'
+complete -f -c git -n '__fish_git_using_command blame' -l incremental -d 'Show the result incrementally'
+complete -f -c git -n '__fish_git_using_command blame' -l encoding -d 'Specifies the encoding'
@faho
faho May 31, 2016 Member

This needs an encoding. I'm not sure how git expects these - does "--encoding=utf-8" work, or does it need to be upper case? Anyway, this is shared with log at least so it should be in the shared options section (added recently).

@faho faho commented on an outdated diff May 31, 2016
share/completions/git.fish
@@ -645,5 +645,32 @@ complete -f -c git -n '__fish_git_using_command clean' -s x -d 'Remove ignored f
complete -f -c git -n '__fish_git_using_command clean' -s X -d 'Remove only ignored files'
# TODO -e option
+### git blame
+complete -f -c git -n '__fish_git_needs_command' -a blame -d 'Show what revision and author last modified each line of a file'
+complete -f -c git -n '__fish_git_using_command blame' -s b -d 'Show blank SHA-1 for boundary commits'
+complete -f -c git -n '__fish_git_using_command blame' -l root -d 'Do not treat root commits as boundaries'
+complete -f -c git -n '__fish_git_using_command blame' -l show-stats -d 'Include additional statistics at the end of blame output'
+complete -f -c git -n '__fish_git_using_command blame' -s L -d 'Annotate only the given line range'
+complete -f -c git -n '__fish_git_using_command blame' -s l -d 'Show long rev'
+complete -f -c git -n '__fish_git_using_command blame' -s t -d 'Show raw timestamp'
+complete -f -c git -n '__fish_git_using_command blame' -s S -d 'Use revisions from revs-file instead of calling git-rev-list'
+complete -f -c git -n '__fish_git_using_command blame' -l reverse -d 'Walk history forward instead of backward'
+complete -f -c git -n '__fish_git_using_command blame' -s p -l porcelain -d 'Show in a format designed for machine consumption'
+complete -f -c git -n '__fish_git_using_command blame' -l line-porcelain -d 'Show the porcelain format'
+complete -f -c git -n '__fish_git_using_command blame' -l incremental -d 'Show the result incrementally'
+complete -f -c git -n '__fish_git_using_command blame' -l encoding -d 'Specifies the encoding'
+complete -f -c git -n '__fish_git_using_command blame' -l contents -d 'Annotates the changes starting backwards from the working tree copy'
@faho
faho May 31, 2016 Member

I think you've stopped reading too early. From the man page:

This flag makes the command pretend as if the working tree copy has the contents of the named file

So something like "Instead of working tree, use the contents of the named file"?

@faho faho commented on an outdated diff May 31, 2016
share/completions/git.fish
+complete -f -c git -n '__fish_git_using_command blame' -l reverse -d 'Walk history forward instead of backward'
+complete -f -c git -n '__fish_git_using_command blame' -s p -l porcelain -d 'Show in a format designed for machine consumption'
+complete -f -c git -n '__fish_git_using_command blame' -l line-porcelain -d 'Show the porcelain format'
+complete -f -c git -n '__fish_git_using_command blame' -l incremental -d 'Show the result incrementally'
+complete -f -c git -n '__fish_git_using_command blame' -l encoding -d 'Specifies the encoding'
+complete -f -c git -n '__fish_git_using_command blame' -l contents -d 'Annotates the changes starting backwards from the working tree copy'
+complete -f -c git -n '__fish_git_using_command blame' -l date -d 'Specifies the format used to output dates'
+complete -f -c git -n '__fish_git_using_command blame' -s M -d 'Detect moved or copied lines within a file'
+complete -f -c git -n '__fish_git_using_command blame' -s C -d 'Detect lines moved or copied from other files that were modified in the same commit'
+complete -f -c git -n '__fish_git_using_command blame' -s h -d 'Show help message'
+complete -f -c git -n '__fish_git_using_command blame' -s c -d 'Use the same output mode as git-annotate'
+complete -f -c git -n '__fish_git_using_command blame' -s f -l show-name -d 'Show the filename in the original commit'
+complete -f -c git -n '__fish_git_using_command blame' -s n -l show-number -d 'Show the line number in the original commit'
+complete -f -c git -n '__fish_git_using_command blame' -s s -d 'Suppress the author name and timestamp from the output'
+complete -f -c git -n '__fish_git_using_command blame' -s e -l show-email -d 'Show the author email instead of author name'
+complete -f -c git -n '__fish_git_using_command blame' -s w -d 'Ignore whitespace when comparing the parent’s version and the child’s to find where the lines came from'
@faho
faho May 31, 2016 Member

Just "Ignore whitespace changes" should be enough. Keeping descriptions short allows us to use more columns. In general you probably want to paraphrase what the git man pages say as they have a rather... special style.

@faho
Member
faho commented May 31, 2016

For all the options that take a file, you'll want to replace the "-f" with a "-r" - they require an argument, and it can be a file - see complete --help.

These are "-S" and "--contents", for "--date" you'll probably want "-x" (no files but a required argument). Though that's another shared option (with git log again).

@faho faho self-assigned this May 31, 2016
@faho faho added the completions label May 31, 2016
@Hunsu
Contributor
Hunsu commented May 31, 2016 edited

You copy the file into a directory in $fish_complete_path, e.g. ~/.config/fish/completions, and then just use it.

That's what I did but I got an error about string not recognized.

I'm gonna add some more comments inline.

Thanks, I will fix the issues.

@faho
Member
faho commented May 31, 2016

That's what I dif but I got an error about string not recognized.

You're using completions from 2.3.0 but a fish before that. The string builtin is new in 2.3.0, so you'll want to upgrade to that.

@faho faho merged commit 24d6f6d into fish-shell:master Jun 2, 2016

1 check failed

continuous-integration/travis-ci/pr The Travis CI build could not complete due to an error
Details
@faho
Member
faho commented Jun 2, 2016

Merged, thanks!

We probably want to add some more stuff here, but as a first pass it's not bad.

@Hunsu
Contributor
Hunsu commented Jun 2, 2016

We probably want to add some more stuff here, but as a first pass it's not bad.

What more stuff do you want to add? I will look at the TODO to improve the completions for git. I read somewhere that fish shell's auto-completion uses man pages, is it true? If so why it doesn't work for git (or the other commands).

@faho
Member
faho commented Jun 2, 2016

I read somewhere that fish shell's auto-completion uses man pages, is it true?

You possibly read it on fishshell.com - it is true. We have a python script that tries to parse man pages and generate completion scripts from that. For simple stuff (commands that take files and only have long and short options that don't take arguments) it works, but for something like git man pages just aren't written in a precise enough format that it could do much. Even for simple stuff the descriptions are often "Something something something...[See the man page for details]".

So we have a lot of hand-written completions, which includes git (as you've probably seen).

What more stuff do you want to add?

Well, the arguments. From the man page, it appears git blame takes a "rev" and also files. We're not currently completing the "rev" part (which, in simplified terms, is a git-ism for those commit hashes you see all over the place).

Then we have the options that take arguments we're not completing yet, like "--encoding". We're also not yet sharing the shared options.

This is complicated stuff, and some of it might well be impossible with our current system - e.g. completing "dates", because there's an infinite number of them.

@zanchey zanchey added this to the next-2.x milestone Jun 6, 2016
@krader1961 krader1961 modified the milestone: fish 2.3.1, next-2.x Sep 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment