6

I love to use tig client to navigate through git commits.

But I'm missing one thing for now.

Is there a key binding to take a sha number of a git commit I'm currently staying at?

megas
  • 21,401
  • 12
  • 79
  • 130

3 Answers3

9

Check if the command proposed in jonas/tig issue 557 would work for you:

bind generic 9 !sh -c "echo -n %(commit) | xclip -selection c && echo Copied %(commit) to clipboard"

That would copy the current commit SHA1 in your clipboard.

In the Wiki binding page, you also have example for Mac or Cygwin:

bind generic 9 !@sh -c "git show -s --format=%s %(commit) | xclip -selection c" # Linux
bind generic 9 !@sh -c "git show -s --format=%s %(commit) | pbcopy" # Mac
bind generic 9 !@sh -c "git show -s --format=%s %(commit) > /dev/clipboard" # Cygwin

The OP megas proposes in the comments to use git rev-parse:

bind generic 9 !@sh -c "git rev-parse --short %(commit) | pbcopy"
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    I came up with this solution: `bind generic 9 !@sh -c "git rev-parse --short %(commit) | pbcopy"` – megas Oct 01 '18 at 11:42
  • @megas OK, I have included your comment in the answer for more visibility. – VonC Oct 01 '18 at 11:56
2

To copy the short SHA1 on MacOS (can be easily adapted to other OS):

bind generic 9 +@sh -c "printf '%s' $(git rev-parse --short %(commit)) | pbcopy && echo Copied %(commit) to clipboard"

As an improvement to other answers, this version prints out a message to the status bar which is nicer to closing the tig UI or having nothing printed out. The + option flag enables to do so (source). Also no extra newline character at the end like VonC's answer.

tkhoa2711
  • 21
  • 1
1

MacOS

bind generic 9 !@sh -c "printf '%s' %(commit) | pbcopy"

Or, to copy the short sha-1:

bind generic 9 !@sh -c "printf '%s' $(git rev-parse --short %(commit)) | pbcopy"

Inspiration source: /tig/doc/tigrc(5) - Bind Command in the exemple section.

Solutions listed in VonC's answer did not work for me because of a return line in the pasted result (⌘+V). So I was not able to type such command in tig :!git rebase -i [paste_here_hitting_⌘+V]~

frouo
  • 5,087
  • 3
  • 26
  • 29