I do not see a direct way to do this, but I managed to get it to work using the following approach. I have not fully tested this, so I cannot guarantee that this will work in all situations.
Using this script:
#!/bin/bash TERM_HEIGHT=`tput lines` # determine terminal height WATCH_BANNER_HEIGHT=2 # account for the lines taken up by the header of "watch" let VIS_LINES="TERM_HEIGHT - WATCH_BANNER_HEIGHT" # height of visible area (yes " " | head -n $VIS_LINES; cat | head -n $VIS_LINES) | tail -n $VIS_LINES
Post the output process of your command, since it is called watch , for example. (assuming the script was saved as align_bottom , made an executable, and saved somewhere in your $PATH ):
watch -n 120 "mysql_query | column -t | align_bottom"
What the script does:
- Determine the height (number of lines) of the terminal
- Calculate the visible output area of
watch - Print blank lines for input output (press exit)
- Read the output from stdin and crop it so that we only display the top output if it goes off the screen. If you want to see the bottom of the output, simply remove the
head command after cat . tail output of steps (3) and (4), so that excess filling is removed, and the final output is tightly included in watch
I have to admit that this sounds a bit hacky, but hopefully it brings you closer to what you are trying to achieve.
Update:
It should also be possible to implement this as a function instead, so that it can be conveniently located in .bashrc .
function align_bottom() { (( VIS = $(tput lines) - 2 ))
Usage will be the same:
watch -n 120 "mysql_query | column -t | align_bottom"
Note that watch executes the given command using sh -c , so, as Dennis noted in the comments, on systems that do not associate /bin/sh with /bin/bash , the above function approach will not work.
You can make it work with usign:
watch -n 120 "mysql_query | column -t | bash -c align_bottom"
but for portability and usability, it just uses a shell script.