Last active
July 6, 2019 15:15
-
-
Save joelagnel/381cc5e0a4bad4b63a04fdd55b303025 to your computer and use it in GitHub Desktop.
A kernel make command that turns errors into a ncurses list -> then select and jumps to VI to the line.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
rm /tmp/make-out* /tmp/make-error* >/dev/null 2>&1 | |
make $@ 2>&1 | tee /tmp/make-out-all-tmp | |
grep error: /tmp/make-out-all-tmp > /tmp/make-out-tmp | |
if [ $? -ne 0 ]; then exit; fi | |
MAKE_NCURSES_SCRIPT=/tmp/make-ncurses-errors-script.py | |
cat > $MAKE_NCURSES_SCRIPT <<END | |
#!/usr/bin/python | |
from __future__ import division #You don't need this in Python3 | |
import curses | |
from math import * | |
import sys | |
import os | |
import re | |
with open("/tmp/make-out-tmp") as f: | |
content = f.readlines() | |
strings = [x.rstrip() for x in content] | |
strings = [re.sub(r'[^\x00-\x7F]+',' ', x) for x in strings] | |
screen = curses.initscr() | |
curses.noecho() | |
curses.cbreak() | |
curses.start_color() | |
screen.keypad( 1 ) | |
curses.init_pair(1,curses.COLOR_BLACK, curses.COLOR_CYAN) | |
highlightText = curses.color_pair( 1 ) | |
normalText = curses.A_NORMAL | |
screen.border( 0 ) | |
curses.curs_set( 0 ) | |
max_row = 35 #max number of rows | |
box = curses.newwin( max_row + 2, 130, 1, 1 ) | |
box.box() | |
row_num = len( strings ) | |
pages = int( ceil( row_num / max_row ) ) | |
position = 1 | |
page = 1 | |
for i in range( 1, max_row + 1 ): | |
if row_num == 0: | |
box.addstr( 1, 1, "There aren't strings", highlightText ) | |
else: | |
if (i == position): | |
box.addstr( i, 2, str( i ) + " - " + strings[ i - 1 ], highlightText ) | |
else: | |
box.addstr( i, 2, str( i ) + " - " + strings[ i - 1 ], normalText ) | |
if i == row_num: | |
break | |
screen.refresh() | |
box.refresh() | |
x = screen.getch() | |
while x != 27: | |
if x == curses.KEY_DOWN: | |
if page == 1: | |
if position < i: | |
position = position + 1 | |
else: | |
if pages > 1: | |
page = page + 1 | |
position = 1 + ( max_row * ( page - 1 ) ) | |
elif page == pages: | |
if position < row_num: | |
position = position + 1 | |
else: | |
if position < max_row + ( max_row * ( page - 1 ) ): | |
position = position + 1 | |
else: | |
page = page + 1 | |
position = 1 + ( max_row * ( page - 1 ) ) | |
if x == curses.KEY_UP: | |
if page == 1: | |
if position > 1: | |
position = position - 1 | |
else: | |
if position > ( 1 + ( max_row * ( page - 1 ) ) ): | |
position = position - 1 | |
else: | |
page = page - 1 | |
position = max_row + ( max_row * ( page - 1 ) ) | |
if x == curses.KEY_LEFT: | |
if page > 1: | |
page = page - 1 | |
position = 1 + ( max_row * ( page - 1 ) ) | |
if x == curses.KEY_RIGHT: | |
if page < pages: | |
page = page + 1 | |
position = ( 1 + ( max_row * ( page - 1 ) ) ) | |
if x == 10: | |
with open("/tmp/make-error-selected", "w") as text_file: | |
text_file.write("{1}".format(x, strings[ position - 1 ])) | |
exit() | |
if x == ord('q'): | |
exit() | |
for i in range( 1 + ( max_row * ( page - 1 ) ), max_row + 1 + ( max_row * ( page - 1 ) ) ): | |
if row_num == 0: | |
box.addstr( 1, 1, "There aren't strings", highlightText ) | |
else: | |
if ( i + ( max_row * ( page - 1 ) ) == position + ( max_row * ( page - 1 ) ) ): | |
box.addstr( i - ( max_row * ( page - 1 ) ), 2, str( i ) + " - " + strings[ i - 1 ], highlightText ) | |
else: | |
box.addstr( i - ( max_row * ( page - 1 ) ), 2, str( i ) + " - " + strings[ i - 1 ], normalText ) | |
if i == row_num: | |
break | |
screen.refresh() | |
box.refresh() | |
x = screen.getch() | |
curses.endwin() | |
exit() | |
END | |
chmod +x $MAKE_NCURSES_SCRIPT | |
while [ 1 ]; do | |
rm /tmp/make-error-selected | |
$MAKE_NCURSES_SCRIPT | |
tput reset | |
if [ ! -f /tmp/make-error-selected ]; then | |
break | |
fi | |
if [ -f /tmp/make-error-selected ]; then | |
file=$(cat /tmp/make-error-selected | cut -d ':' -f1) | |
line=$(cat /tmp/make-error-selected | cut -d ':' -f2) | |
vi $file +$line | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment