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
33 # Check if `infocmp` is available.
34 if ! infocmp >/dev/null 2>&1; then
35 echo 'Warning: `infocmp` not available! 256color checks will fail.'
42 # Create private temporary directory used by many tools (including GNU screen
47 # Create rlwrap history directory.
49 # Create zsh cache directory.
55 # Generate ~/.less with lesskey. Prevent cluttering ~/ by storing the history
56 # file in this directory; this requires replacing the constant HISTORY_PATH in
58 echo 'lesskey: generating .lesskey'
60 HISTORY_PATH -- "`pwd`/lesshistory" \
64 # Custom colors for GNU ls.
65 if installed dircolors; then
66 echo '# WARNING! DO NOT EDIT THIS FILE!' >shell/dircolors
67 dircolors -b shell/dircolors.in >>shell/dircolors
70 # Find the required options to get colored ls output. GNU ls is preferred. See
71 # shell/aliases.in for details. Doing this here instead of in shell/aliases
72 # speeds up shell starts.
74 # Check if colors are available.
75 if ls --color >/dev/null 2>&1; then
78 if ls -G >/dev/null 2>&1; then
84 # Absolute path to `ls`.
85 ls_path=`installed_path ls`
87 if test "x$ls_color" = xgnu; then
90 # Normal (BSD) ls with colors.
91 elif test "x$ls_color" = xcli; then
92 ls_env='CLICOLOR_FORCE=1'
94 # Simple ls with no colors.
100 # Also check if `column -t` is available.
101 if echo test | column -t >/dev/null 2>&1; then
102 column=' | column -t'
107 generate shell/aliases .in simple_cpp \
108 LS_ENV LS_PATH LS_COLOR COLUMN -- \
109 "$ls_env" "$ls_path" "$ls_color" "$column"
111 # If `tig` is not available use my simple replacement.
112 if ! installed tig; then
113 echo "alias tig='git tig'" >>shell/aliases
116 # Check if grep supports --color=auto.
117 if echo test | grep --color=auto test >/dev/null 2>&1; then
120 echo 'shell/aliases: removing grep --color=auto'
121 sed_i '/^alias grep=/ s/^/#/' shell/aliases
124 generate screenrc .in cat
125 # As screen-256color is not widely supported use it only on machines where the
126 # matching terminfo entry is available. This also requires a terminal emulator
127 # which supports 256 colors. Also used for tmux.
129 if terminal_available screen-256color; then
130 # Called through SSH connection, assume the local system supports 256
132 if test -n "$SSH_CONNECTION"; then
134 # We have rxvt-unicode installed, check if it supports 256 colors.
135 elif installed urxvt; then
136 # Thanks to deryni in #rxvt-unicode on Freenode (2012-10-14 22:54
137 # CEST) for the strings/grep idea. The grep check is for "correct" 256
138 # rxvt-unicode binaries (e.g. Debian's rxvt-unicode-256color), the
139 # terminal_info check for manual installations which modify
140 # rxvt-unicode's terminfo entry.
141 urxvt_path=`installed_path urxvt`
142 urxvt_grep=`strings "$urxvt_path" | grep '^TERM=rxvt-'`
143 if test x"$urxvt_grep" = 'xTERM=rxvt-unicode-256color' \
144 || terminal_info rxvt-unicode \
145 | grep -F 'colors#256' >/dev/null; then
148 # Check if XTerm supports 256 colors (not a perfect check, but most XTerm
149 # support 256 colors).
150 elif terminal_available xterm-256color; then
154 if test -z "$use_256colors"; then
155 echo 'screenrc: removing 256 colors'
156 sed_i 's/Enable 256 color/Disable 256 color/;
157 s/screen-256color/screen/' screenrc
159 # Some options are only necessary when running as root. They are marked as
161 if test "`id -u`" -ne 0; then
162 echo 'screenrc: removing root options'
163 grep_i -v '(ROOT)' screenrc
165 # I use some features of GNU screen which are only in Git or very recent GNU
166 # screen versions. Drop them on machines which have older versions. They are
168 if test ! -d "$HOME/development/shell/screen"; then
169 echo 'screenrc: removing Git features'
170 grep_i -v '(GIT)' screenrc
172 # Rxvt doesn't need the attrcolor "fix". As I prefer rxvt assume I use it when
174 if installed rxvt; then
175 echo 'screenrc: removing attrcolor "fix"'
176 sed_i 's/attrcolor b ".I"/#attrcolor b ".I"/' screenrc
178 # Display current battery charge on computers with a battery. Necessary lines
179 # are marked as "(BATTERY)".
180 if test ! -d /sys/class/power_supply/BAT0; then
181 echo 'screenrc: removing battery display'
182 grep_i -v '(BATTERY)' screenrc
185 if installed tmux; then
186 generate tmux.conf .in perl ./bin/remove-continuation.pl
188 # Add mappings to switch to windows 10-29 quickly. See tmux-window.pl for
190 perl ./tmux-window.pl 1 "`pwd`/tmux-window2.conf" >tmux-window1.conf
191 perl ./tmux-window.pl 2 >tmux-window2.conf
192 # Set absolute path to tmux-window1.conf in tmux.conf.
193 generate tmux.conf '' simple_cpp \
194 TMUX_WINDOW_PATH -- "`pwd`/tmux-window1.conf"
196 # 256 colors not available.
197 if test -z "$use_256colors"; then
198 echo 'tmux.conf: removing 256 colors'
199 sed_i 's/Enable 256 color/Disable 256 color/;
200 s/screen-256color/screen/' tmux.conf
202 # Tmux doesn't display a warning if the shell wasn't found!
203 if test ! -x '/bin/zsh'; then
204 echo 'tmux.conf: removing /bin/zsh as shell'
205 sed_i 's/zsh/sh/' tmux.conf
209 # Htop overwrites the comments in its configuration file.
210 generate htoprc .in cat
215 # Link setup for shells.
218 link bash/rc ~/.bashrc
219 link bash/profile ~/.bash_profile
220 link bash/logout ~/.bash_logout
221 if installed csh; then
225 link zsh/env ~/.zshenv
227 link zsh/logout ~/.zlogout
229 # Link setup for additional files.
230 if installed crontab; then
231 link crontab.d ~/.crontab.d
233 link lessfilter ~/.lessfilter
234 if installed colordiff; then
235 link colordiffrc ~/.colordiffrc
237 link inputrc ~/.inputrc
238 link screenrc ~/.screenrc
239 if installed tmux; then
240 link tmux.conf ~/.tmux.conf
242 if installed htop; then
243 link htoprc ~/.htoprc
244 # New location for htoprc. Use both for compatibility.
245 mkdir -p ~/.config/htop
246 link htoprc ~/.config/htop/htoprc
248 if test -d ~/.ssh && test -O ~/.ssh; then
249 link ssh_config ~/.ssh/config