tig icon indicating copy to clipboard operation
tig copied to clipboard

Feature request – a few sophisticated bindings in default tigrc

Open psprint opened this issue 3 years ago • 1 comments

I'm using the following bindings with much of comfort from them. I thought that maybe they could be added to the default .tigrc?

# Open up all files affected by a selected commit
# `x` is for "external command"

bind generic xE !sh -c '$EDITOR $(git diff --name-only %(commit)~..%(commit))'

# Four commit/compile commands, prompting for the commit
# message, routing back to the $EDITOR if message empty (i.e.:
# `git commit` without the -m option), with 4 combinations
# from no-following-make/with-following-make and
# commit-all-changes/commit-only-staged-changes:
# `C` is for "commit"

bind generic CA !sh -c 'q="%(prompt [WITH make EVERYTHING]! Commit message [empty opens up $EDITOR]: )"; if [ "$q;" != ";" ]; then opt=-m; fi; git commit -av $opt ${q:+"$q"} && make'
bind generic Ca !sh -c 'q="%(prompt [WITHOUT make EVERYTHING!] Commit message [empty opens up $EDITOR]: )"; if [ "$q;" != ";" ]; then opt=-m; fi; git commit -av $opt ${q:+"$q"}'
bind generic CC !sh -c 'q="%(prompt [WITH make!] Commit message [empty opens up $EDITOR]: )"; if [ "$q;" != ";" ]; then opt=-m; fi; git commit -v $opt ${q:+"$q"} && make'
bind generic Cc !sh -c 'q="%(prompt [WITHOUT make!] Commit message [empty opens up $EDITOR]: )"; if [ "$q;" != ";" ]; then opt=-m; fi; git commit -v $opt ${q:+"$q"}'

# Copies a file from a selected blob. Can be run in view-tree
# or any other view, because it obtains its SHA from %(commit)
# and %(file)
# `f` is for "file"

bind generic fc :!sh -c 'p="%(prompt Enter a file path to copy into: )"; q="$(git rev-parse %(commit):%(file))"; git show "$q" > "$p" && cat "$p" && { printf "\\nFile %(file) saved to $p.\\nContents of $q being the file \\`%(file)\\` is above.\\n\\n"; ((1)); } || printf "Problem saving file %(file)"'

# Touches a selected file on the disk (useful to trigger recompilation)
bind generic ft +sh -c "command touch -- %(file) && printf 'File touched (%(file))' || printf 'Problem touching %(file)'"

What do you think? The value of the first binding is obvious, from the 4 commit bindings it's the condition on the immediate message from command prompt and failing back to $EDITOR if empty, from the fc command – obtaining of the correct %(blob) from %(commit) and %(file), which is needed as %(blob) is surprisingly empty anywhere outside view-tree, from ft it's an useful and at the same pretty obvious exploitation of the file-browsing/selecting property that TIG has (it's pretty close to a file manager like MC I would even say).

psprint avatar Jun 20 '22 16:06 psprint

I'm not the maintainer, and I don't know why someone thumbed-down, but your example are oriented around make which isn't necessarily someone everyone who uses git will use.

But I do think a repository of tigrc examples would be great.

Thanks for sharing.

Lockszmith-GH avatar Nov 29 '22 18:11 Lockszmith-GH