# $Id: .screenrc,v 1.2 2009-08-24 22:00:50 makipri Exp $

# unsetenv DISPLAY
# setenv LC_CTYPE en_US.UTF-8

# Run everything in UTF-8.
defutf8 on

# 256 color xterm
attrcolor b ".I"
termcapinfo xterm 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'
defbce "on"

# Make screen messages stand out a little more - black on bright green.
sorendition "+b kG"

# Keep dead windows around until I tell them to exit.
zombie cr

# And show the command for the windows when they're resurrected.
# verbose on

# Escape key is C-z.  (I use C-a too much in Emacs.)
escape ^gg

#nethack on
nethack off

#defflow on # will force screen to process ^S/^Q
deflogin on

# detach if connection lost
autodetach on

# no copyright page
startup_message off

# "alternate screen"
altscreen on

# turn visual bell on
vbell on
vbell_msg "   Wuff  ----  Wuff!!  "

# define a bigger scrollback, default is 100 lines
defscrollback 5000

# term can switch to dark bg, knows of function keys
#termcapinfo xterm*|rxvt* 'VR=\E[?5h:VN=\E[?5l'
#termcapinfo xterm*|rxvt* 'k1=\E[11~:k2=\E[12~:k3=\E[13~:k4=\E[14~'
#termcapinfo xterm*|rxvt* 'kh=\EOH:kI=\E[2~:kD=\E[3~:kH=\EOF:kP=\E[5~:kN=\E[6~'
# boost output buffer
#termcapinfo xterm*|rxvt* OL=10000
# allow ^A W
#termcapinfo xterm*|rxvt* Z0=\E[?3h:Z1=\E[?3l:is=\E[r\E[m\E[2J\E[H\E[?7h\E[?1;4;6l

# ------------------------------------------------------------------------------
# SCREEN KEYBINDINGS
# ------------------------------------------------------------------------------

# Remove some stupid / dangerous key bindings
bind ^k
#bind L
bind ^\
bind ^s
bind s
# Make them better
bind \\ quit
bind K kill
bind I login on
bind O login off
bind } history
# Vi style movement
bind j focus down
bind k focus up
bind ^j focus down
bind ^k focus up
bind ^J focus bottom
bind ^K focus top

bind = resize =
bind + resize +1
bind - resize -1
bind _ resize max

# An example of a "screen scraper" which will launch urlview on the current
# screen window
#
#bind ^B eval "hardcopy_append off" "hardcopy -h $HOME/.screen-urlview" "screen urlview $HOME/.screen-urlview"

# ------------------------------------------------------------------------------
# TERMINAL SETTINGS
# ------------------------------------------------------------------------------

# The vt100 description does not mention "dl". *sigh*
#termcapinfo vt100 dl=5\E[M

# turn sending of screen messages to hardstatus off
#hardstatus off
# Set the hardstatus prop on gui terms to set the titlebar/icon title
#termcapinfo xterm*|rxvt*|kterm*|Eterm* hs:ts=\E]0;:fs=\007:ds=\E]0;\007
# use this for the hard status string
hardstatus string "%h%? users: %u%?"

# set default hardstatus
defhstatus "screen@eniac: ^En (^Et)"
# and pass it to terminals to use as window title
termcapinfo xterm*|rxvt* 'hs:ts=\E]2;:fs=\007:ds=\E]2;screen\007'

shelltitle "$ |sh"

# set up the pretty status line with window info
# HH:MM (24h), :, ss, month name, day number, hostname (unless empty), load (unless empty)
# "%c:%s %M %d %H%? %l%?".
# %{-b gk} green black
# %-w left windows
# %{+b kg} bold black green
# %50> truncate from here to 50%
# %n %t window number, window title
# %{-b gk} green black
# %+w rest of the windows
# %< truncate, do not pad
# %= pad to display width
# %c HH:MM
# %H hostname

# clock and hostname on left
# caption always '%{-b gk}[%c] [%H] | %L=%-w%{+b kg}%n %t%{-b gk}%+w %-0<'

# no truncating, clock and hostname on right
# caption always '%{-b gk}%-w%{+b kg}%50>%n %t%{-b gk}%+w%< %=[%c] [%H]'

# works, clock and hostname on right
# caption always "%{= .w}%-Lw%20L>%{=b .c}%n%f %t%{-}%+Lw %-015= [%c] [%H]"
# caption always "%{= .w}%-w%20L>%{=b .c}%n %t%{-}%+w %-015= [%c] [%H]"
caption always "%{= kg}%-w%20L>%{=b bw}%n %t%{-}%+w %-016= [%c] [%H]"


# As a special case, "%{-}" restores the attributes and colors that  were set
# before the last change was made (i.e. pops one level of the color-change
# stack).

# An alternative hardstatus to display a bar at the bottom listing the
# windownames and highlighting the current windowname in blue. (This is only
# enabled if there is no hardstatus setting for your terminal)
#
#hardstatus lastline "%-Lw%{= BW}%50>%n%f* %t%{-}%+Lw%<"

# set these terminals up to be 'optimal' instead of vt100
termcapinfo xterm*|linux*|rxvt*|Eterm* OP

# Change the xterm initialization string from is2=\E[!p\E[?3;4l\E[4l\E>
# (This fixes the "Aborted because of window size change" konsole symptoms found
#  in bug #134198)
termcapinfo xterm 'is=\E[r\E[m\E[2J\E[H\E[?7h\E[?1;4;6l'

# To get screen to add lines to xterm's scrollback buffer, uncomment the
# following termcapinfo line which tells xterm to use the normal screen buffer
# (which has scrollback), not the alternate screen buffer.
#
termcapinfo xterm|xterms|xs|rxvt ti@:te@

# defnonblock on
# nonblock on
defnonblock 5
nonblock 5
#escape ^Zz
obuflimit 4096

# Prepend/append register [/] to the paste if ^a^] is pressed.
# This lets me have autoindent mode in vi.
register [ "\033:se noai\015a"
register ] "\033:se ai\015a"
bind ^] paste [.]

# Use the function keys to switch among windows.
#bindkey -k k1 select 1
#bindkey -k k2 select 2
#bindkey -k k3 select 3
#bindkey -k k4 select 4
#bindkey -k k5 select 5
#bindkey -k k6 select 6
#bindkey -k k7 select 7
#bindkey -k k8 select 8
#bindkey -k k9 select 9
#bindkey -k k; select 10
#bindkey -k F1 select 11
#bindkey -k F2 select 12

# windows 13-24 are Shift-Fn.  May not work in all terminals.
#bindkey -k F3 select 13
#bindkey -k F4 select 14
#bindkey -k F5 select 15
#bindkey -k F6 select 16
#bindkey -k F7 select 17
#bindkey -k F8 select 18
#bindkey -k F9 select 19
#bindkey -k FA select 20

# screen only seems to understand up to FA.
#bindkey -k FB select 21
#bindkey -k FC select 22
#bindkey -k FD select 23
#bindkey -k FE select 24

#bind c screen 1
#bind 0 select 10

# Make shift-PgUp and shift-PgDn work like they do in xterm.  (Note that this
# requires xterm to be configured to pass those keys through, and not try to
# act on them itself.)
bindkey "^[[5;2~" eval "copy" "stuff ^u"
bindkey -m "^[[5;2~" stuff ^u
bindkey -m "^[[6;2~" stuff ^d

# It's sometimes useful to have a quote key.
bind ^Q mapdefault
bind q mapdefault

# And since that leaxes xon unbound, let's remove xoff, too.
bind ^S

bind s encoding iso-8859-1
bind u encoding utf-8

bindkey "^[[D" prev  # change window with ctrl-left
bindkey "^[[C" next  # change window with ctrl-right

# \033
bind R screen -ln -t root -h 1000 9 su

bind b eval writebuf 'exec /bin/sh -c "xsel -i -b < /tmp/screen-exchange"' 'exec /bin/sh -c "killall xsel"'
