3 # Setup script for shell configuration files.
5 # Copyright (C) 2011-2012 Simon Ruderich
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.
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.
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/>.
27 terminal_available() {
28 terminal_info "$@" > /dev/null
30 # Check if `infocmp` is available.
31 if ! infocmp > /dev/null 2>&1; then
32 echo 'Warning: `infocmp` not available! 256color checks will fail.'
37 # Create private temporary directory used by many tools (including GNU screen
42 # Generate ~/.less with lesskey.
46 # Find the required options to get colored ls output. GNU ls is preferred. See
47 # shell/aliases.in for details. Doing this here instead of in shell/aliases
48 # speeds up shell starts.
50 # Check if colors are available.
51 ls --color > /dev/null 2>&1
52 if test $? -eq 0; then
55 ls -G > /dev/null 2>&1
56 if test $? -eq 0; then
62 # Absolute path to `ls`.
65 if test "x$ls_color" = xgnu; then
68 # Normal (BSD) ls with colors.
69 elif test "x$ls_color" = xcli; then
70 ls_env='CLICOLOR_FORCE=1'
72 # Simple ls with no colors.
77 generate perl shell/aliases \
79 s/\bLS_ENV\b/$ARGV[0]/;
80 s/\bLS_PATH\b/$ARGV[1]/;
81 s/\bLS_COLOR\b/$ARGV[2]/;
84 "$ls_env" "$ls_path" "$ls_color"
86 generate cat screenrc .in
87 # As screen-256color is not widely supported use it only on machines where the
88 # matching terminfo entry is available. This also requires a terminal emulator
89 # which supports 256 colors. Also used for tmux.
91 if terminal_available screen-256color; then
92 # Called through SSH connection, assume the local system supports 256
94 if test -n "$SSH_CONNECTION"; then
96 # We have rxvt-unicode installed, check if it supports 256 colors.
97 elif installed urxvt; then
98 # Thanks to deryni in #rxvt-unicode on Freenode (2012-10-14 22:54
99 # CEST) for the strings/grep idea. The grep check is for "correct" 256
100 # rxvt-unicode binaries (e.g. Debian's rxvt-unicode-256color), the
101 # terminal_info check for manual installations which modify
102 # rxvt-unicode's terminfo entry.
103 urxvt_path=`which urxvt`
104 urxvt_grep=`strings "$urxvt_path" | grep '^TERM=rxvt-'`
105 if test x"$urxvt_grep" = 'xTERM=rxvt-unicode-256color' \
106 || terminal_info rxvt-unicode \
107 | grep -F 'colors#256' >/dev/null; then
110 # Check if XTerm supports 256 colors (not a perfect check, but most XTerm
111 # support 256 colors).
112 elif terminal_available xterm-256color; then
116 if test -z "$use_256colors"; then
117 echo screenrc: removing 256 colors
118 sed 's/Enable 256 color/Disable 256 color/;
119 s/screen-256color/screen/' screenrc > screenrc.tmp
120 mv screenrc.tmp screenrc
122 # Some options are only necessary when running as root. They are marked as
124 if test "`id -u`" -ne 0; then
125 echo screenrc: removing root options
126 grep -v '(ROOT)' screenrc > screenrc.tmp
127 mv screenrc.tmp screenrc
129 # I use some features of GNU screen which are only in Git or very recent GNU
130 # screen versions. Drop them on machines which have older versions. They are
132 if test ! -d "$HOME/development/shell/screen"; then
133 echo screenrc: removing Git features
134 grep -v '(GIT)' screenrc > screenrc.tmp
135 mv screenrc.tmp screenrc
137 # Rxvt doesn't need the attrcolor "fix". As I prefer rxvt assume I use it when
139 if installed rxvt; then
140 echo screenrc: removing attrcolor \"fix\"
141 sed 's/attrcolor b ".I"/#attrcolor b ".I"/' screenrc > screenrc.tmp
142 mv screenrc.tmp screenrc
144 # Display current battery charge on computers with a battery. Necessary lines
145 # are marked as "(BATTERY)".
146 if test ! -d /sys/class/power_supply/BAT0; then
147 echo screenrc: removing battery display
148 grep -v '(BATTERY)' screenrc > screenrc.tmp
149 mv screenrc.tmp screenrc
152 if installed tmux; then
153 generate perl tmux.conf ./bin/remove-continuation.pl
155 # 256 colors not available.
156 if test -z "$use_256colors"; then
157 echo tmux.conf: removing 256 colors
158 sed 's/Enable 256 color/Disable 256 color/;
159 s/screen-256color/screen/' tmux.conf > tmux.conf.tmp
160 mv tmux.conf.tmp tmux.conf
162 # Tmux doesn't display a warning if the shell wasn't found!
163 if test ! -x '/bin/zsh'; then
164 echo tmux.conf: removing /bin/zsh as shell
165 sed 's/zsh/sh/' tmux.conf > tmux.conf.tmp
166 mv tmux.conf.tmp tmux.conf
170 # Htop overwrites the comments in its configuration file.
171 generate cat htoprc .in
173 # Link setup for shells.
176 link bash/rc ~/.bashrc
177 link bash/profile ~/.bash_profile
178 link bash/logout ~/.bash_logout
179 if installed csh; then
183 link zsh/env ~/.zshenv
185 link zsh/logout ~/.zlogout
187 # Link setup for additional files.
188 link lessfilter ~/.lessfilter
189 if installed colordiff; then
190 link colordiffrc ~/.colordiffrc
192 link inputrc ~/.inputrc
193 link screenrc ~/.screenrc
194 if installed tmux; then
195 link tmux.conf ~/.tmux.conf
197 if installed htop; then
198 link htoprc ~/.htoprc
201 # Create rlwrap history directory.
202 mkdir -p shell/rlwrap