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

completion: Simple rewrite attempt #541

Closed
wants to merge 3 commits into from

Conversation

lbonn
Copy link

@lbonn lbonn commented Nov 20, 2016

Work towards #540.

I made a small completion script which re-uses the base git's. It is supposed to have better support for revisions and options completions.

The drawback is that the base git's completion must be installed beforehand. For most bash users, this should be a given. For zsh, it would probably won't work in this state but tig's completion is already builtin in zsh (see git's completion in zsh's tree). It only matches git log behaviour though...

It should also be checked for compatibility with old git versions. Does tig have a minimum git version requirement?

A standalone version should not be too hard to write with heavy copy-pasting if needed.

Either way, this first draft can be used to validate its correct behaviour. I tried some common combinations but additional testing would be nice.

@jonas
Copy link
Owner

jonas commented Nov 21, 2016

Cool, I was not able to get the _completion_loader working on mac os x. Will take a closer look when I get more time.

I have one suggestion to improve blame completion to also match revisions:

diff --git i/contrib/tig-completion.bash w/contrib/tig-completion.bash
index a40088c..deba0cb 100755
--- i/contrib/tig-completion.bash
+++ w/contrib/tig-completion.bash
@@ -29,9 +29,10 @@
 
 __tig_cmds="blame status show log stash grep"
 
-__tig_complete_revlist_or_cmd ()
+__tig_complete_revlist_or_list ()
 {
 	local pfx ls ref cur_="$cur"
+	local list="$1"
 	case "$cur_" in
 	*..?*:*)
 		return
@@ -83,7 +84,7 @@ __tig_complete_revlist_or_cmd ()
 		__gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
 		;;
 	*)
-		__gitcomp "$__tig_cmds"
+		__gitcomp "$list"
 		__gitcomp_nl_append "$(__git_refs)"
 		;;
 	esac
@@ -118,7 +119,7 @@ _tig ()
 			__gitcomp "-v -h"
 			;;
 		*)
-			__tig_complete_revlist_or_cmd ;;
+			__tig_complete_revlist_or_list "$__tig_cmds" ;;
 		esac
 		return
 	fi
@@ -131,7 +132,7 @@ _tig ()
 	status)
 		_git_status;;
 	blame)
-		__gitcomp "$(__git_complete_file)";;
+		__tig_complete_revlist_or_list "$(__git_complete_file)";;
 	*)
 		_git_log ;;
 	esac

@lbonn
Copy link
Author

lbonn commented Nov 25, 2016

About OSX: maybe I overestimated the portability of this approach.

I also tried your patch but if I just type tig blame <tab><tab>, I only get a list of refs which is not what I need from blame in most of the cases. It only gives a list of files if the current word does not match any rev (eg: if I have a file mouse.c and a branch master, only master would appear if I type m<tab>).

__git_complete_file might be the cause, here is its definition along with __git_complete_revlist in git-completion.bash.

__git_complete_file ()
{
	__git_complete_revlist_file
}

__git_complete_revlist ()
{
	__git_complete_revlist_file
}

Apparently this is used to match a revision in priority and only files if none matches, typically for log, diff for which it is recommended to use -- to limit to files.

Is it common to supply a revision to tig blame? Even if the completion to files and revs works, having the full list of revs (which can be pretty large in some repos) if the user only seeks files is not really helpful.

But maybe I just don't know about the use cases of tig blame rev.

Also, the whole blame completion seems to be missing from git's script to let it fall back on bash's default completion to file. But this is probably an argument from authority :).

lbonn added 3 commits July 7, 2017 00:56
It re-uses utilities from the classic git completion script (with
`_completion_loader`)
So that we can avoid depending on git's completion installation.

The original completion functions are renamed from `__gitxxx` to
`__tigxxx`, with some exceptions.
@lbonn lbonn force-pushed the completion_simple branch from a3d70f2 to 88325b5 Compare July 6, 2017 22:56
@lbonn
Copy link
Author

lbonn commented Jul 6, 2017

I put all the mainline completion utilities we depend on directly in the file to avoid being too dependent on the environment and/or git's completion version (just like it was before).

In theory, the inlining could be semi-automatized (with some effort...) to ease the maintenance but we probably don't need to update the completion too often.

The issue you raised about the blame completion still need to be resolved. Personally, I'd still be in favor of using the mainline approach which favors the most common command usage.

@jonas
Copy link
Owner

jonas commented Jul 15, 2017

Thanks, I will install it and test it out next week

@lbonn
Copy link
Author

lbonn commented Oct 29, 2019

News on this?

FWIW, I have been using it almost daily since then.

Noteworthy examples:

tig ..<tab>  # shows refs on this branch, files on stock completion
tig master -- <tab>  # shows files on this branch, refs on stock completion

@lbonn lbonn closed this Jan 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants