I want to copy text in Terminal without using my mouse. For example to store a commit hash when doing a git log and use it for another command. Anyone has an idea how to move the cursor up and copy, maybe turning on something like a copy/visual mode or having a vim mode?
Asked
Active
Viewed 252 times
1
-
3My suggestion would be to run everything in *screen*. It has a separate copy mode. – poke Mar 11 '15 at 20:18
-
Similar to @poke's response. tmux is pretty great. Or, you could try byobu, which is a layer atop either tmux or screen. – Justin Wood Mar 11 '15 at 20:20
-
read about the screen's copy mode: http://aperiodic.net/screen/commands:copy – clt60 Mar 11 '15 at 20:21
-
There was a good answer over on SuperUser: http://superuser.com/questions/125190/select-text-from-terminal-app-using-the-keyboard-in-os-x – seanhodges Mar 11 '15 at 20:46
1 Answers
0
You can use git log --pretty=%H
to get only the commit hash of the commit in question, then pipe it to pbcopy
. The full command would be:
git log --pretty=%H | pbcopy
the --pretty=format
option can do a whole lot, actually look at http://git-scm.com/docs/git-log and search for "pretty formats"
But in general, using a combination of utilities such as grep
and cut
, as well as the options in the command you are using, is probably the most portable way to go.

Andrew McGlathery
- 21
- 1
- 6
-
Personally I prefer [`git rev-list`](https://www.kernel.org/pub/software/scm/git/docs/git-rev-list.html) for listing commit hashes, it has nearly the same options as log but is actually designed to only return the hashes. – Sascha Wolf Mar 12 '15 at 08:59