Created
May 13, 2014 15:34
-
-
Save ihodes/a664cdc68494ecfe2e13 to your computer and use it in GitHub Desktop.
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
# From https://gist.github.com/bahamas10/6567725 to fix stupid bash issues | |
# http://stackoverflow.com/questions/2575037/how-to-get-the-cursor-position-in-bash | |
# print the current column of the cursor | |
curcol() { | |
local pos oldstty row=0 col=0 | |
exec < /dev/tty | |
oldstty=$(stty -g) | |
stty raw -echo min 0 | |
tput u7 > /dev/tty | |
IFS=';' read -r -d R -a pos | |
stty "$oldstty" | |
# change from one-based to zero based so they work with: tput cup $row $col | |
col=${pos[1]} | |
col=$((${col:-1} - 1)) | |
echo "$col" | |
} | |
# conditonally output `%\n` based on the current column of the cursor | |
fancynewline() { | |
if (( $(curcol) != 0 )); then | |
tput bold | |
tput bold | |
tput rev | |
tput rev | |
echo '\n' | |
tput sgr0 | |
fi | |
} | |
PROMPT_COMMAND=fancynewline |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment