From: Iain Patterson Date: Thu, 17 Dec 2009 10:52:04 +0000 (+0000) Subject: Decide whether or not a terminal can be resized. X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=8258aae3ed4e6059d22911a4ad7e41d40ebe9ac3;p=profile.git Decide whether or not a terminal can be resized. Use resize.bashrc to set the RESIZABLE environment variable. If RESIZABLE is 0 the current terminal cannot be resized. If RESIZABLE is the same as TERM in can be resized. Maintain a list of terminals we know can't be resized, eg sun-color. Maintain a list of terminals which we can't be sure about, eg screen since whether or not screen can be resized depends on the (unknown) capabilities of the underlying terminal. For any other terminal assume it can be resized. In vim, set the g:resizable variable based on the value of RESIZABLE (and set it to 1 in the GUI). Call Can_Resize() before trying to resize the window. Allow setting g:resizable manually to override this logic. --- diff --git a/.profile.d/resize.bashrc b/.profile.d/resize.bashrc new file mode 100644 index 0000000..e74dbc5 --- /dev/null +++ b/.profile.d/resize.bashrc @@ -0,0 +1,18 @@ +# Can we resize this window? +case "$TERM" in + # Terminals we KNOW can't be resized. + cygwin|linux|sun-color) + export RESIZABLE=0 + ;; + + # Terminals we CANNOT know about. + screen*) + [ "$RESIZABLE" = "0" ] || RESIZABLE="$TERM" + export RESIZABLE + ;; + + # Anything else we'll assume can be. + *) + export RESIZABLE="$TERM" + ;; +esac diff --git a/.vimrc b/.vimrc index 26ce8db..9b1c07f 100644 --- a/.vimrc +++ b/.vimrc @@ -184,6 +184,7 @@ fun! Iain_Vars() "{{{2 call Prep_Var("g:marksigns", 0) call Prep_Var("g:firstsign", 100) endif + call Prep_Var("g:resizable", "''") endfun "}}}2 " Helper for status line. @@ -279,12 +280,38 @@ fun! Invert_Case() "{{{2 let &ic = ! &ic endfun "}}}2 +" Can we resize this window? +fun! Can_Resize() "{{{2 + call Iain_Vars() + + if g:resizable == "0" || g:resizable == "1" + return g:resizable + endif + + " Do we KNOW we can(not) resize? + if has("gui_running") + let g:resizable = 1 + elseif $RESIZABLE == &term + let g:resizable = 1 + elseif $RESIZABLE == "0" + let g:resizable = 0 + else + " Assume we can. Allow overriding. + let g:resizable = 1 + endif + return g:resizable +endfun "}}}2 + " Grow or shrink the window size. fun! Resize_Columns(op, ...) "{{{2 if a:op == "" return endif + if ! Can_Resize() + return + endif + if a:0 == 0 " Vim 5 hardcodes the size of numbers column to 8. if version >= "700"