Skip to content

Commit ea77e67

Browse files
Linus TorvaldsJunio C Hamano
authored andcommitted
Make "git help" react to window size correctly
Currently the git "show commands" function will react to the environment variable COLUMNS, or just default to a width of 80 characters. That's just soo eighties. Nobody sane sets COLUMNS any more, unless they need to support some stone-age software from before the age of steam engines, SIGWINCH and TIOCGWINSZ. So get with the new century, and use TIOCGWINSZ to get the terminal size. Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d808111 commit ea77e67

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

git.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <errno.h>
99
#include <limits.h>
1010
#include <stdarg.h>
11+
#include <sys/ioctl.h>
1112
#include "git-compat-util.h"
1213

1314
#ifndef PATH_MAX
@@ -26,6 +27,16 @@ static int term_columns(void)
2627
if (col_string && (n_cols = atoi(col_string)) > 0)
2728
return n_cols;
2829

30+
#ifdef TIOCGWINSZ
31+
{
32+
struct winsize ws;
33+
if (!ioctl(1, TIOCGWINSZ, &ws)) {
34+
if (ws.ws_col)
35+
return ws.ws_col;
36+
}
37+
}
38+
#endif
39+
2940
return 80;
3041
}
3142

0 commit comments

Comments
 (0)