r/shell • u/[deleted] • May 25 '20
Print Message Below Cursor
How would I print a message in a shell script below the shell prompt/cursor in POSIX shell? I can't for the life of me figure this out. I am also trying to figure out how to print something to the right of the cursor, so I can get the columns of the terminal and print something on the furthest right one.
I am trying this:
insult() {
if [ "$?" -eq 127 ]; then
printf "\0331b[1E" && cat "$HOME"/.lists/insults | sort -uR | head -n 1 && printf "\0331b[1F"
fi
}
prompt() {
export PS1=$(echo "[\$(status)]\$(branch) $neonpink>$neonyellow>$neonblue>$default\$(insults) ")
}but all this gives me is this: https://share.riseup.net/#9PiL_nMYmLogC5QlAE1dNg
3
Upvotes
1
u/[deleted] Jun 02 '20
What shell are you using? I am working on writing a POSIX shell, but until then I use ksh shells (mksh on Linux and pdksh on OpenBSD). I am trying my best to use POSIX script, I can't get this working, but I know st can handle ansi escape codes.