There is an alias for output the last page (based on your terminal size) if I understand correctly:
alias tail='tail -n $((${LINES:-`tput lines 2>/dev/null||echo -n 80`} - 2))'
This tail alias is intended to give you a pageful output with the prompt you use to issue the command and the prompt after the tail. But often a line will be wrapped into two lines or more. The goal can not be achieved if you only count the physical lines. The first few lines including the prompt with the command may be pushed out of window.
I commented with the following command:
ps aux | fold -w $COLUMNS | tail -n $((LINES - 2))
(Side-question: why commandlinefu.com does not have comments feed? I have no idea how I can track follow-ups effectively.)
I think this will work better. There is a side-effect with this command, line returns are added by fold command. If you resize the window, the long line can not be adjusted to new window size because they have already been broken into multiple lines. The terminal does not have information to bring them back to original lines.
However, its not really a big deal if you are a tmux user. tmux adds line returns to long lines. I also notice xterm does the same, but rxvt-unicode does not (if you dont run tmux within).
Another minor issue is if the command you issue is already a multi-line, then some lines will be pushed out for sure.
I tried to find a single command to achieve the same goal, the closest one is using less:
cat FILE | less -X -E +G
-X causes no screen clear when quits so stuff will remain on screen, -E causes less quits when encounter EOF, and +G is as if you press G which means jumping to the end of file.
Combining the three options, you will have the last page. But the problem is the prompt with the command is the only line being pushed out. I cant find an option to set the window size, LINES environment variable doesnt affect.
I also tried to pipe out to tail, but I think less detects if there is a pipe-out. If so, it passes input content directly out to pipe.
0 comments:
Post a Comment