Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

A default terminal width might be 80 characters, however the output of a command might have been 100 characters (wider than the width of the terminal), so it spills over and puts 80 characters on one line, and perhaps puts 20 characters on the next line. When I resize the terminal to 200 character width, everything that has already been shown on the screen stays exactly as it was (80 on one line, and 20 on another line). I'm wondering if there is any solution that will have the terminal repaint the contents, so that all 100 characters will then fit on a single line.

My current system is Ubuntu Linux, and I use bash. I have the feeling there is a solution, since when I use OSX it seems to be able to repaint the contents of the terminal and rearrange previous lines.

share|improve this question

migrated from stackoverflow.com Feb 17 '12 at 5:34

This question came from our site for professional and enthusiast programmers.

    
I think that has more to do with the application running the terminal, not a setting. –  rubixibuc Feb 17 '12 at 6:43

1 Answer 1

up vote 1 down vote accepted

Since I posed this question, I've found a code-snippet out there that solves this.

I've tested it in RHEL5, and it is successfully solving the need I had. Thus, when get have a command output some text. Such as: ls -al you can then resize the window with your mouse more-or-less than 80 pixels, and the output with wrap onto the next line if theres not enough visible room on the screen, or unwrap to occupy just one line, as you widen your window.

Found it on: http://codesnippets.joyent.com/posts/show/1645

tput lines
tput cols

echo $LINES
echo $COLUMNS

stty size
stty size | awk '{print $1}'    # lines
stty size | awk '{print $NF}'   # columns

stty size | cut -d" " -f1   # lines
stty size | cut -d" " -f2   # columns 

stty -a | awk '/rows/ {print $4}'      # lines
stty -a | awk '/columns/ {print $6}'   # columns

stty -a | sed -E -n -e 's/^.*[^[:digit:]]([[:digit:]]+)[[:space:]]+rows;.*$/\1/p;q;'
stty -a | sed -E -n -e 's/^.*[^[:digit:]]([[:digit:]]+)[[:space:]]+columns;.*$/\1/p;q;'



# automatically resize the Terminal window if it gets smaller than the default size

# positive integer test (including zero)
function positive_int() { return $(test "$@" -eq "$@" > /dev/null 2>&1 && test "$@" -ge 0 > /dev/null 2>&1); }


# resize the Terminal window
function sizetw() { 
   if [[ $# -eq 2 ]] && $(positive_int "$1") && $(positive_int "$2"); then 
      printf "\e[8;${1};${2};t"
      return 0
   fi
   return 1
}


# the default Terminal window size: 26 lines and 107 columns
sizetw 26 107


# automatically adjust Terminal window size
function defaultwindow() {

   DEFAULTLINES=26
   DEFAULTCOLUMNS=107

   if [[ $(/usr/bin/tput lines) -lt $DEFAULTLINES ]] && [[ $(/usr/bin/tput cols) -lt $DEFAULTCOLUMNS ]]; then
      sizetw $DEFAULTLINES $DEFAULTCOLUMNS
   elif [[ $(/usr/bin/tput lines) -lt $DEFAULTLINES ]]; then
      sizetw $DEFAULTLINES $(/usr/bin/tput cols)
   elif [[ $(/usr/bin/tput cols) -lt $DEFAULTCOLUMNS ]]; then
      sizetw $(/usr/bin/tput lines) $DEFAULTCOLUMNS
   fi

   return 0
}


# SIGWINCH is the window change signal
trap defaultwindow SIGWINCH    


sizetw 26 70
sizetw 10 107
sizetw 4 15

For some good reason, OSX (atleast in my current 10.7.2) seems to support resizing natively.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.