From 104b025d33b8cf5f9d42bda3ac3d158eb7a07701 Mon Sep 17 00:00:00 2001 From: Iain Patterson Date: Tue, 19 Jun 2007 20:00:37 +0000 Subject: [PATCH] First crack at auto resizing Qn mode for vim. Added TERM and PATH scripts. git-svn-id: https://svn.cambridge.iain.cx/profile/trunk@52 6be0d1a5-5cfe-0310-89b6-964be062b18b --- .profile.d/PATH.bashrc | 56 ++++++++++++++++++++++++++++++++++++++++++ .profile.d/TERM.bashrc | 13 ++++++++++ .vimrc | 22 +++++++++++++++-- has_term | 18 ++++++++++++++ 4 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 .profile.d/PATH.bashrc create mode 100644 .profile.d/TERM.bashrc create mode 100755 has_term diff --git a/.profile.d/PATH.bashrc b/.profile.d/PATH.bashrc new file mode 100644 index 0000000..a7d4420 --- /dev/null +++ b/.profile.d/PATH.bashrc @@ -0,0 +1,56 @@ +# $Id$ +# +# Path information is stored on separate lines in XXXdirs. +# We extract each directory exists and add it to the appropriate PATH. +# + +# Location of the XXXdirs files. +DIR=$HOME/.profile.d + +# Set one path to be the same as another. +function copypath() { + newpath="$1"; shift + oldpath="$1"; shift + + # Sanitise and export. + path="$(eval echo \$$oldpath)" + [ -z "$path" ] || eval export $newpath="$path" + + unset path newpath oldpath +} + +# Set a path from directories. +function makepath() { + newpath="$1"; shift + dirs="$1"; shift + + # Check the file exists. + [ -e "$DIR/$dirs" ] || return + + # Read them. + path= + for dir in $(cat "$DIR/$dirs"); do + [ -d "$dir" ] || continue + + path="$path:$dir" + done + + # Sanitise path. + path=${path#:} + [ -z "$path" ] && return + + # Export. + eval export $newpath="$path" + + unset path newpath dirs +} + +makepath PATH bindirs +makepath C_INCLUDE_PATH incdirs +copypath CPLUS_INCLUDE_PATH C_INCLUDE_PATH +makepath LD_LIBRARY_PATH libdirs +copypath LD_RUN_PATH LD_LIBRARY_PATH +makepath MANPATH mandirs +makepath PKG_CONFIG_PATH pkgdirs + +unset sedscr makepath copypath diff --git a/.profile.d/TERM.bashrc b/.profile.d/TERM.bashrc new file mode 100644 index 0000000..f9132c0 --- /dev/null +++ b/.profile.d/TERM.bashrc @@ -0,0 +1,13 @@ +# $Id$ +# +# Try to find a valid TERM entry. +# + +for term in linux dtterm xterm vt100; do + if has_term $term; then + export TERM=$term + break + fi +done + +unset term diff --git a/.vimrc b/.vimrc index 6a4438e..7b535bb 100755 --- a/.vimrc +++ b/.vimrc @@ -15,6 +15,7 @@ se ignorecase se smartcase se shm=aot se laststatus=2 +se t_WS=[8;%p1%d;%p2%dt syn enable if has("gui_running") se guifont=Bitstream\ Vera\ Sans\ Mono\ 12 @@ -81,6 +82,23 @@ fun! Show_StatusLine() exec "set statusline=" . sl1 . hexformat . sl2 endfun +fun! Cycle_Number() + if &number + " Restore width. + if &t_WS =~ '^.' + let &columns=g:numbercols + endif + set nonumber + else + " Save width between number toggling. + if &t_WS =~ '^' + let g:numbercols=&columns + let &columns=&columns+5 + endif + set number + endif +endfun + " Save the current window width so if we change it we can restore it " when we quit. let andyoldcols=&columns @@ -124,6 +142,8 @@ map Qx :call Cycle_HexStatusLine(): map Qc :call Invert_Case(): " Cycle list styles with Ql. map Ql :call Cycle_List(): +" Change number mode with Qn. +map Qn :call Cycle_Number(): " Change to ts=2 with Q2. map Q2 :se ts=2: " Change to ts=4 with Q4. @@ -136,8 +156,6 @@ map Q6 :se ts=16: map Q3 :se ts=32: " Change foldmethod with Qf. map Qf :se foldenable!: -" Change number mode with Qn. -map Qn :se number!: " Toggle paste mode with Qp. map Qp :se paste!: " Toggle tags with Qt. diff --git a/has_term b/has_term new file mode 100755 index 0000000..8150269 --- /dev/null +++ b/has_term @@ -0,0 +1,18 @@ +#!/usr/bin/perl +# +# $Id$ +# +# has_term: Check for a valid TERM value. +# Usage: has_term [] +# Exits: 0 if the TERM setting is valid. +# 1 otherwise. +# Example: has_term dtterm +# + +use Term::Cap; + +# Quit. +close STDERR; + +Tgetent Term::Cap { TERM => $ARGV[0], OSPEED => 9600 } and exit 0; +exit 100; -- 2.20.1