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/>.
30 terminal_available() {
31 terminal_info "$@" > /dev/null
36 # Check if `infocmp` is available.
37 if ! infocmp >/dev/null 2>&1; then
38 echo 'Warning: `infocmp` not available! 256color checks will fail.'
45 # Create private temporary directory used by many tools (including GNU screen
50 # Create rlwrap history directory.
52 # Create zsh cache directory.
58 # Generate ~/.less with lesskey. Prevent cluttering ~/ by storing the history
59 # file in this directory; this requires replacing the constant HISTORY_PATH in
61 echo 'lesskey: generating .lesskey'
63 HISTORY_PATH -- "`pwd`/lesshistory" \
67 # Custom colors for GNU ls.
68 if installed dircolors; then
69 echo '# WARNING! DO NOT EDIT THIS FILE!' >shell/dircolors
70 dircolors -b shell/dircolors.in >>shell/dircolors
73 # Find the required options to get colored ls output. GNU ls is preferred. See
74 # shell/aliases.in for details. Doing this here instead of in shell/aliases
75 # speeds up shell starts.
77 # Check if colors are available.
78 if ls --color >/dev/null 2>&1; then
81 if ls -G >/dev/null 2>&1; then
87 # Absolute path to `ls`.
88 ls_path=`installed_path ls`
90 if test "x$ls_color" = xgnu; then
93 # Normal (BSD) ls with colors.
94 elif test "x$ls_color" = xcli; then
95 ls_env='CLICOLOR_FORCE=1'
97 # Simple ls with no colors.
103 # Also check if `column -t` is available.
104 if echo test | column -t >/dev/null 2>&1; then
105 column=' | column -t'
110 generate shell/aliases .in simple_cpp \
111 LS_ENV LS_PATH LS_COLOR COLUMN -- \
112 "$ls_env" "$ls_path" "$ls_color" "$column"
114 # If `tig` is not available use my simple replacement.
115 if ! installed tig; then
116 echo "alias tig='git tig'" >>shell/aliases
119 # Check if grep supports --color=auto.
120 if echo test | grep --color=auto test >/dev/null 2>&1; then
123 echo 'shell/aliases: removing grep --color=auto'
124 sed_i '/^alias grep=/ s/^/#/' shell/aliases
127 generate screenrc .in cat
128 # As screen-256color is not widely supported use it only on machines where the
129 # matching terminfo entry is available. This also requires a terminal emulator
130 # which supports 256 colors. Also used for tmux.
132 if terminal_available screen-256color; then
133 # Called through SSH connection, assume the local system supports 256
135 if test -n "$SSH_CONNECTION"; then
137 # We have rxvt-unicode installed, check if it supports 256 colors.
138 elif installed urxvt; then
139 # Thanks to deryni in #rxvt-unicode on Freenode (2012-10-14 22:54
140 # CEST) for the strings/grep idea. The grep check is for "correct" 256
141 # rxvt-unicode binaries (e.g. Debian's rxvt-unicode-256color), the
142 # terminal_info check for manual installations which modify
143 # rxvt-unicode's terminfo entry.
144 urxvt_path=`installed_path urxvt`
145 urxvt_grep=`strings "$urxvt_path" | grep '^TERM=rxvt-'`
146 if test x"$urxvt_grep" = 'xTERM=rxvt-unicode-256color' \
147 || terminal_info rxvt-unicode \
148 | grep -F 'colors#256' >/dev/null; then
151 # Check if XTerm supports 256 colors (not a perfect check, but most XTerm
152 # support 256 colors).
153 elif terminal_available xterm-256color; then
157 if test -z "$use_256colors"; then
158 echo 'screenrc: removing 256 colors'
159 sed_i 's/Enable 256 color/Disable 256 color/;
160 s/screen-256color/screen/' screenrc
162 # Some options are only necessary when running as root. They are marked as
164 if test "`id -u`" -ne 0; then
165 echo 'screenrc: removing root options'
166 grep_i -v '(ROOT)' screenrc
168 # I use some features of GNU screen which are only in Git or very recent GNU
169 # screen versions. Drop them on machines which have older versions. They are
171 if test ! -d "$HOME/development/shell/screen"; then
172 echo 'screenrc: removing Git features'
173 grep_i -v '(GIT)' screenrc
175 # Rxvt doesn't need the attrcolor "fix". As I prefer rxvt assume I use it when
177 if installed rxvt; then
178 echo 'screenrc: removing attrcolor "fix"'
179 sed_i 's/attrcolor b ".I"/#attrcolor b ".I"/' screenrc
181 # Display current battery charge on computers with a battery. Necessary lines
182 # are marked as "(BATTERY)".
183 if test ! -d /sys/class/power_supply/BAT0; then
184 echo 'screenrc: removing battery display'
185 grep_i -v '(BATTERY)' screenrc
188 if installed tmux; then
189 generate tmux.conf .in perl ./bin/remove-continuation.pl
191 # Add mappings to switch to windows 10-29 quickly. See tmux-window.pl for
193 perl ./tmux-window.pl 1 "`pwd`/tmux-window2.conf" >tmux-window1.conf
194 perl ./tmux-window.pl 2 >tmux-window2.conf
195 # Set absolute path to tmux-window1.conf in tmux.conf.
196 generate tmux.conf '' simple_cpp \
197 TMUX_WINDOW_PATH -- "`pwd`/tmux-window1.conf"
199 # 256 colors not available.
200 if test -z "$use_256colors"; then
201 echo 'tmux.conf: removing 256 colors'
202 sed_i 's/Enable 256 color/Disable 256 color/;
203 s/screen-256color/screen/' tmux.conf
205 # Tmux doesn't display a warning if the shell wasn't found!
206 if test ! -x '/bin/zsh'; then
207 echo 'tmux.conf: removing /bin/zsh as shell'
208 sed_i 's/zsh/sh/' tmux.conf
212 # Htop overwrites the comments in its configuration file.
213 generate htoprc .in cat
218 # Link setup for shells.
221 link bash/rc ~/.bashrc
222 link bash/profile ~/.bash_profile
223 link bash/logout ~/.bash_logout
224 if installed csh; then
228 link zsh/env ~/.zshenv
230 link zsh/logout ~/.zlogout
232 # Link setup for additional files.
233 if installed crontab; then
234 link crontab.d ~/.crontab.d
236 link lessfilter ~/.lessfilter
237 if installed colordiff; then
238 link colordiffrc ~/.colordiffrc
240 link inputrc ~/.inputrc
241 link screenrc ~/.screenrc
242 if installed tmux; then
243 link tmux.conf ~/.tmux.conf
245 if installed htop; then
246 link htoprc ~/.htoprc
247 # New location for htoprc. Use both for compatibility.
248 mkdir -p ~/.config/htop
249 link htoprc ~/.config/htop/htoprc
251 if test -d ~/.ssh && test -O ~/.ssh; then
252 link ssh_config ~/.ssh/config