]> ruderich.org/simon Gitweb - config/dotfiles.git/blob - setup.sh
setup.sh: Fix GNU screen Git check.
[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 # Create private temporary directory used by many tools (including GNU screen
38 # and tmux).
39 mkdir -p ~/.tmp
40 chmod 0700 ~/.tmp
41
42 # Generate ~/.less with lesskey.
43 lesskey lesskey
44 chmod 0600 ~/.less
45
46 generate cat screenrc .in
47 # As screen-256color is not widely supported use it only on machines where the
48 # matching terminfo entry is available. This also requires a terminal emulator
49 # which supports 256 colors. Also used for tmux.
50 use_256colors=
51 if terminal_available screen-256color; then
52     # Called through SSH connection, assume the local system supports 256
53     # colors.
54     if test -n "$SSH_CONNECTION"; then
55         use_256colors=1
56     # We have rxvt-unicode installed, check if it supports 256 colors.
57     elif installed urxvt; then
58         # Thanks to deryni in #rxvt-unicode on Freenode (2012-10-14 22:54
59         # CEST) for the strings/grep idea. The grep check is for "correct" 256
60         # rxvt-unicode binaries (e.g. Debian's rxvt-unicode-256color), the
61         # terminal_info check for manual installations which modify
62         # rxvt-unicode's terminfo entry.
63         urxvt_path=`which urxvt`
64         urxvt_grep=`strings "$urxvt_path" | grep '^TERM=rxvt-')`
65         if test x"$urxvt_grep" = 'xTERM=rxvt-unicode-256color' \
66                 || terminal_info rxvt-unicode \
67                     | grep -F 'colors#256' >/dev/null; then
68             use_256colors=1
69         fi
70     # Check if XTerm supports 256 colors (not a perfect check, but most XTerm
71     # support 256 colors).
72     elif terminal_available xterm-256color; then
73         use_256colors=1
74     fi
75 fi
76 if test -z "$use_256colors"; then
77     echo screenrc: removing 256 colors
78     sed 's/Enable 256 color/Disable 256 color/;
79          s/screen-256color/screen/' screenrc > screenrc.tmp
80     mv screenrc.tmp screenrc
81 fi
82 # Some options are only necessary when running as root. They are marked as
83 # "(ROOT)".
84 if test "`id -u`" -ne 0; then
85     echo screenrc: removing root options
86     grep -v '(ROOT)' screenrc > screenrc.tmp
87     mv screenrc.tmp screenrc
88 fi
89 # I use some features of GNU screen which are only in Git or very recent GNU
90 # screen versions. Drop them on machines which have older versions. They are
91 # marked as "(GIT)".
92 if test ! -d "$HOME/development/shell/screen"; then
93     echo screenrc: removing Git features
94     grep -v '(GIT)' screenrc > screenrc.tmp
95     mv screenrc.tmp screenrc
96 fi
97 # Rxvt doesn't need the attrcolor "fix". As I prefer rxvt assume I use it when
98 # it's installed.
99 if installed rxvt; then
100     echo screenrc: removing attrcolor \"fix\"
101     sed 's/attrcolor b ".I"/#attrcolor b ".I"/' screenrc > screenrc.tmp
102     mv screenrc.tmp screenrc
103 fi
104 # Display current battery charge on computers with a battery. Necessary lines
105 # are marked as "(BATTERY)".
106 if test ! -d /sys/class/power_supply/BAT0; then
107     echo screenrc: removing battery display
108     grep -v '(BATTERY)' screenrc > screenrc.tmp
109     mv screenrc.tmp screenrc
110 fi
111
112 if installed tmux; then
113     generate perl tmux.conf ./bin/remove-continuation.pl
114
115     # 256 colors not available.
116     if test -z "$use_256colors"; then
117         echo tmux.conf: removing 256 colors
118         sed 's/Enable 256 color/Disable 256 color/;
119              s/screen-256color/screen/' tmux.conf > tmux.conf.tmp
120         mv tmux.conf.tmp tmux.conf
121     fi
122     # Tmux doesn't display a warning if the shell wasn't found!
123     if test ! -x '/bin/zsh'; then
124         echo tmux.conf: removing /bin/zsh as shell
125         sed 's/zsh/sh/' tmux.conf > tmux.conf.tmp
126         mv tmux.conf.tmp tmux.conf
127     fi
128 fi
129
130 # Htop overwrites the comments in its configuration file.
131 generate cat htoprc .in
132
133 # Link setup for shells.
134 link shell ~/.shell
135 link bash ~/.bash
136 link bash/rc ~/.bashrc
137 link bash/profile ~/.bash_profile
138 link bash/logout ~/.bash_logout
139 if installed csh; then
140     link csh/rc ~/.cshrc
141 fi
142 link zsh ~/.zsh
143 link zsh/env ~/.zshenv
144 link zsh/rc ~/.zshrc
145 link zsh/logout ~/.zlogout
146
147 # Link setup for additional files.
148 link lessfilter ~/.lessfilter
149 if installed colordiff; then
150     link colordiffrc ~/.colordiffrc
151 fi
152 link inputrc ~/.inputrc
153 link screenrc ~/.screenrc
154 if installed tmux; then
155     link tmux.conf ~/.tmux.conf
156 fi
157 if installed htop; then
158     link htoprc ~/.htoprc
159 fi
160
161 # Create rlwrap history directory.
162 mkdir -p shell/rlwrap