Automate vim line position to show nxstyle errors

This is how a create a automated process to move to the next lines where nxstyle error are reported (actual from last error to the first one direction).

First we need to run nxstyle in the file to be fixed:

$ ./tools/nxstyle arch/arm/src/stm32l4/stm32l4_usbdev.c 2>&1 | sed -e 's/.*usbdev.c://g' | sed -e 's/:.*//g' > /tmp/lines.txt

Then create a script (i.e: /home/alan/test.sh) to be executed when a key combination is pressed. It will read the above lines file from the last line to the first one and type that line on vim to move to that line:

#!/bin/bash
LINE=$(tail -1 /tmp/lines.txt)
cp /tmp/lines.txt /tmp/lines.txt.tmp
sed '$ d' /tmp/lines.txt.tmp > /tmp/lines.txt
rm -f /tmp/lines.txt.tmp
WID=`xdotool search "Terminal" | head -1`
xdotool windowactivate --sync $WID
xdotool type ":$LINE"
xdotool key Return

Finally edit teh xbindkeysrc to execute the above script when Alt+F7 is pressed:

$ vi ~/.xbindkeysrc
"/home/alan/test.sh"
    Alt + F7

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s