tempra
tempra

Reputation: 2331

How to get list of latest branches that auto exit (no need to press q)?

I here are the commands that I want to achieve in combined.

My question is how to show the list of branches from latest to order that auto-exit according to terminal height (without pressing q)?

note: I don't want to show the entire list of branches, I just want to show according to terminal height.

Upvotes: 1

Views: 121

Answers (2)

tempra
tempra

Reputation: 2331

in addition of @phd answer..

you can also add your own custom variable inside ~/.bashrc file. append the variable.

export CUSTOMLINE=24

and follow the same command given by @phd

git branch --sort=-committerdate | head -$CUSTOMLINE

Upvotes: 1

phd
phd

Reputation: 94676

You already know the option -P/--no-pager so you can use it here:

git -P branch --sort=-committerdate

But that could produce long listing. If you want exactly one screen-high output you have to clip it. For example using head

git branch --sort=-committerdate | head -$LINES

Bash stores the current terminal height in environment variable $LINES; if you don't use Bash you have to get the terminal height yourself. There is no need to use -P as Git doesn't use pager when the output is not a terminal (it's a pipe in the command above).

Upvotes: 1

Related Questions