简体   繁体   中英

Git Log in ZSH Terminal

I remember in a Git-tutorial video that the user's terminal (probably ZSH) was split into two; one for the standard terminal commands, and below that there was something like Git log graphical representation. It was always visible at the bottom of the terminal with nice colors.

终端屏幕 .

How is it possible to split the terminal screen into two and display Git log (something like git log --pretty=format:'%h : %s' --graph ) on the terminal screen?

UPDATE: I found the video on Vimeo, http://vimeo.com/16018419 . I am trying to do the exact same setup on my ZSH terminal.

with tmux, you can split-pane zsh -c while :; do sleep 60; git log ...; done zsh -c while :; do sleep 60; git log ...; done zsh -c while :; do sleep 60; git log ...; done and this should achieve an automagically refreshing git log output in a pane.

supply [-vh] [percent] to split-pane to split vert or horiz with a given percent of the terminal. iirc, it splits from bottom and/or right side of terminal, so adjust percentage accordingly.

this should have the desired effect of having git log in a pane beside $EDITOR (or below), with appropriate dimensions and automagically refresh every minute. feel free to alter or clean up syntax to suit your needs.

EDIT: respawning a pane in tmux can be done with the tmux builtin respawn-pane . you can bind a key something like this to get a simple shortcut

bind-key -n Mr respawn-pane -t git:0.1 [command]

in this example, i assume 3 things. first, that you have a named tmux session (named git, but this is arbitrary and to your choosing by using rename-session in tmux or by launching the session with new-session -s name ). second, that the git log (which is what we want to refresh) is at window of index 0 (this is the first window opened in a session, by default, unless you set base-index to else) and the pane of index 1.

so here, it respawns the second pane of the first window in the "git" session by pressing alt-r. if you use the loop i provided before, this is unnecessary to do because the log will refresh itself after each sleep. that may be considered wasteful to some, so you may arbitrarily decide to respawn this pane at your whim instead.

[command] is optional. tmux's respawn-pane will execute the command that was given when the pane was spawned at first. in this example, it will be the while loop by default. if you skip the loop and instead just use split-pane [-hv] [percent] "git log ..." then do not provide the optional command parameter as the pane will run it for you smartly. providing the command parameter to respawn-pane will take precedence over the initial command used when spawning the pane.

finally, if you do not provide the command parameter to split-pane initially, tmux will run whatever value default-command is.

so there you have an overly verbose explanation of how to do what this video does in multiple ways.

git log --oneline --graph --decorate --color=always for the git log output.

The terminal splitting feature depends on your console.

Okay,

he is using iTerm on Mac, the split is made by default, You just need to go on menu or use any short command. You can take this with terminator on ubuntu/linux. If you want to continue using gnome-terminal, you can use screen or tmux to simulate this.

In log, he is using tig ( http://jonas.nitro.dk/tig/ ): a git browsing tool. It can be installed easy easy. By the way you can use watch to auto update your log, so you can have an "autolog" on another part of your terminal. ;)

watch git log --graph

Here, I'm using tmux in my console:

将tmux与某些应用程序一起使用

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM