Reputation: 21791
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?
Upvotes: 10
Views: 2302
Reputation: 41
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.
Upvotes: 4
Reputation: 5223
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]~
Upvotes: 1
Reputation: 1324278
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"
Upvotes: 11