Reputation: 491
I have my ZSH theme outputting the status of my Vagrant/VBox VMs using RPROMPT='$(vbox_status)'
in my .zsh-theme file (where vbox_status
calls a script which outputs what's running), like so:
However, I'm wondering if there's a way I can make this output 'sticky' so that, rather than outputting at the end of every single line, it will stay at the position indicated by the arrow and simply update itself whenever a new line is output above.
eg.
Upvotes: 4
Views: 1099
Reputation: 4396
You can do this with a command called tput
.
I have made a basic script which puts a string in the corner of the screen which will get you started. You can make it much nicer by erasing things and highlighting or whatever but this is a starting point:
#!/bin/bash
screen_w=$(tput cols) # Get screen width.
screen_h=$(tput lines) # Get screen height.
str=$* # String to put in corner.
string_w=${#str}
let "x = $screen_w - $string_w"
tput sc # Save current position
tput cup $screen_h $x # Move to corner
echo -ne $str # Put string in the corner
tput rc # Go back to saved position.
echo " >" # Some kind of prompt
So you can set your prompt to run this like this (I called the above script pr.sh)
PS1=$(pr.sh $(date))
It might be different in zsh
but I'm sure you can work that part out.
Just change the $(date) part to your status command. (pr.sh must be on your path)
This is a bit clunky, but it will get you started. There is almost no limit to what you can do with tput
!
Upvotes: 3