]> ruderich.org/simon Gitweb - config/dotfiles.git/blob - setup.sh
setup.sh: Use automic 256color check for GNU screen.
[config/dotfiles.git] / setup.sh
1 #!/bin/sh
2
3 # Setup script for shell configuration files.
4
5 # Copyright (C) 2011-2012  Simon Ruderich
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20
21 . ../lib.sh
22
23 # Helper functions.
24 terminal_info() {
25     infocmp "$@" 2>&1
26 }
27 terminal_available() {
28     terminal_info "$@" > /dev/null
29 }
30 # Check if `infocmp` is available.
31 if ! infocmp > /dev/null 2>&1; then
32     echo 'Warning: `infocmp` not available! 256color checks will fail.'
33     echo
34 fi
35
36
37 hostname=`hostname`
38
39 # Create private temporary directory used by many tools (including GNU screen
40 # and tmux).
41 mkdir -p ~/.tmp
42 chmod 0700 ~/.tmp
43
44 # Generate ~/.less with lesskey.
45 lesskey lesskey
46 chmod 0600 ~/.less
47
48 generate cat screenrc .in
49 # As screen-256color is not widely supported use it only on machines where the
50 # matching terminfo entry is available. This also requires a terminal emulator
51 # which supports 256 colors. Also used for tmux.
52 use_256colors=
53 if terminal_available screen-256color; then
54     # Called through SSH connection, assume the local system supports 256
55     # colors.
56     if test -n "$SSH_CONNECTION"; then
57         use_256colors=1
58     # We have rxvt-unicode installed, check if it supports 256 colors.
59     elif installed urxvt; then
60         # Thanks to deryni in #rxvt-unicode on Freenode (2012-10-14 22:54
61         # CEST) for the strings/grep idea. The grep check is for "correct" 256
62         # rxvt-unicode binaries (e.g. Debian's rxvt-unicode-256color), the
63         # terminal_info check for manual installations which modify
64         # rxvt-unicode's terminfo entry.
65         urxvt_path=`which urxvt`
66         urxvt_grep=`strings "$urxvt_path" | grep '^TERM=rxvt-')`
67         if test x"$urxvt_grep" = 'xTERM=rxvt-unicode-256color' \
68                 || terminal_info rxvt-unicode \
69                     | grep -F 'colors#256' >/dev/null; then
70             use_256colors=1
71         fi
72     # Check if XTerm supports 256 colors (not a perfect check, but most XTerm
73     # support 256 colors).
74     elif terminal_available xterm-256color; then
75         use_256colors=1
76     fi
77 fi
78 if test -z "$use_256colors"; then
79     echo screenrc: removing 256 colors
80     sed 's/Enable 256 color/Disable 256 color/;
81          s/screen-256color/screen/' screenrc > screenrc.tmp
82     mv screenrc.tmp screenrc
83 fi
84 # Some options are only necessary when running as root. They are marked as
85 # "(ROOT)".
86 if [ x`id -u` != x0 ]; then
87     echo screenrc: removing root options
88     grep -v '(ROOT)' screenrc > screenrc.tmp
89     mv screenrc.tmp screenrc
90 fi
91 # I use some features of screen which are only in Git. Drop them on machines
92 # which have older versions. They are marked as "(GIT)".
93 if [ $hostname != asp -o x`id -u` = x0 ]; then
94     echo screenrc: removing Git features
95     grep -v '(GIT)' screenrc > screenrc.tmp
96     mv screenrc.tmp screenrc
97 fi
98 # Rxvt doesn't need the attrcolor "fix". As I prefer rxvt assume I use it when
99 # it's installed.
100 if installed rxvt; then
101     echo screenrc: removing attrcolor \"fix\"
102     sed 's/attrcolor b ".I"/#attrcolor b ".I"/' screenrc > screenrc.tmp
103     mv screenrc.tmp screenrc
104 fi
105 # Display current battery charge on computers with a battery. Necessary lines
106 # are marked as "(BATTERY)".
107 if [ ! -d /sys/class/power_supply/BAT0 ]; then
108     echo screenrc: removing battery display
109     grep -v '(BATTERY)' screenrc > screenrc.tmp
110     mv screenrc.tmp screenrc
111 fi
112
113 # Htop overwrites the comments in its configuration file.
114 generate cat htoprc .in
115
116 # Link setup for shells.
117 link shell ~/.shell
118 link bash ~/.bash
119 link bash/rc ~/.bashrc
120 link bash/profile ~/.bash_profile
121 link bash/logout ~/.bash_logout
122 if installed csh; then
123     link csh/rc ~/.cshrc
124 fi
125 link zsh ~/.zsh
126 link zsh/env ~/.zshenv
127 link zsh/rc ~/.zshrc
128 link zsh/logout ~/.zlogout
129
130 # Link setup for additional files.
131 link lessfilter ~/.lessfilter
132 if installed colordiff; then
133     link colordiffrc ~/.colordiffrc
134 fi
135 link inputrc ~/.inputrc
136 link screenrc ~/.screenrc
137 if installed tmux; then
138     generate perl tmux.conf ./bin/remove-continuation.pl
139     link tmux.conf ~/.tmux.conf
140 fi
141 if installed htop; then
142     link htoprc ~/.htoprc
143 fi
144
145 # Create rlwrap history directory.
146 mkdir -p shell/rlwrap