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/>.
29 terminal_available() {
30 terminal_info "$@" > /dev/null
32 # Check if `infocmp` is available.
33 if ! infocmp > /dev/null 2>&1; then
34 echo 'Warning: `infocmp` not available! 256color checks will fail.'
41 # Create private temporary directory used by many tools (including GNU screen
46 # Create rlwrap history directory.
52 # Generate ~/.less with lesskey. Prevent cluttering ~/ by storing the history
53 # file in this directory; this requires replacing the constant HISTORY_PATH in
55 echo lesskey: generating .lesskey
58 s/\bHISTORY_PATH\b/$ARGV[0]/;
65 # Find the required options to get colored ls output. GNU ls is preferred. See
66 # shell/aliases.in for details. Doing this here instead of in shell/aliases
67 # speeds up shell starts.
69 # Check if colors are available.
70 ls --color > /dev/null 2>&1
71 if test $? -eq 0; then
74 ls -G > /dev/null 2>&1
75 if test $? -eq 0; then
81 # Absolute path to `ls`.
84 if test "x$ls_color" = xgnu; then
87 # Normal (BSD) ls with colors.
88 elif test "x$ls_color" = xcli; then
89 ls_env='CLICOLOR_FORCE=1'
91 # Simple ls with no colors.
96 generate perl shell/aliases \
98 s/\bLS_ENV\b/$ARGV[0]/;
99 s/\bLS_PATH\b/$ARGV[1]/;
100 s/\bLS_COLOR\b/$ARGV[2]/;
103 "$ls_env" "$ls_path" "$ls_color"
105 generate cat screenrc .in
106 # As screen-256color is not widely supported use it only on machines where the
107 # matching terminfo entry is available. This also requires a terminal emulator
108 # which supports 256 colors. Also used for tmux.
110 if terminal_available screen-256color; then
111 # Called through SSH connection, assume the local system supports 256
113 if test -n "$SSH_CONNECTION"; then
115 # We have rxvt-unicode installed, check if it supports 256 colors.
116 elif installed urxvt; then
117 # Thanks to deryni in #rxvt-unicode on Freenode (2012-10-14 22:54
118 # CEST) for the strings/grep idea. The grep check is for "correct" 256
119 # rxvt-unicode binaries (e.g. Debian's rxvt-unicode-256color), the
120 # terminal_info check for manual installations which modify
121 # rxvt-unicode's terminfo entry.
122 urxvt_path=`which urxvt`
123 urxvt_grep=`strings "$urxvt_path" | grep '^TERM=rxvt-'`
124 if test x"$urxvt_grep" = 'xTERM=rxvt-unicode-256color' \
125 || terminal_info rxvt-unicode \
126 | grep -F 'colors#256' >/dev/null; then
129 # Check if XTerm supports 256 colors (not a perfect check, but most XTerm
130 # support 256 colors).
131 elif terminal_available xterm-256color; then
135 if test -z "$use_256colors"; then
136 echo screenrc: removing 256 colors
137 sed 's/Enable 256 color/Disable 256 color/;
138 s/screen-256color/screen/' screenrc > screenrc.tmp
139 mv screenrc.tmp screenrc
141 # Some options are only necessary when running as root. They are marked as
143 if test "`id -u`" -ne 0; then
144 echo screenrc: removing root options
145 grep -v '(ROOT)' screenrc > screenrc.tmp
146 mv screenrc.tmp screenrc
148 # I use some features of GNU screen which are only in Git or very recent GNU
149 # screen versions. Drop them on machines which have older versions. They are
151 if test ! -d "$HOME/development/shell/screen"; then
152 echo screenrc: removing Git features
153 grep -v '(GIT)' screenrc > screenrc.tmp
154 mv screenrc.tmp screenrc
156 # Rxvt doesn't need the attrcolor "fix". As I prefer rxvt assume I use it when
158 if installed rxvt; then
159 echo screenrc: removing attrcolor \"fix\"
160 sed 's/attrcolor b ".I"/#attrcolor b ".I"/' screenrc > screenrc.tmp
161 mv screenrc.tmp screenrc
163 # Display current battery charge on computers with a battery. Necessary lines
164 # are marked as "(BATTERY)".
165 if test ! -d /sys/class/power_supply/BAT0; then
166 echo screenrc: removing battery display
167 grep -v '(BATTERY)' screenrc > screenrc.tmp
168 mv screenrc.tmp screenrc
171 if installed tmux; then
172 generate perl tmux.conf ./bin/remove-continuation.pl
174 # Add mappings to switch to windows 10-29 quickly. See tmux-window.pl for
176 perl ./tmux-window.pl 1 "`pwd`/tmux-window2.conf" > tmux-window1.conf
177 perl ./tmux-window.pl 2 > tmux-window2.conf
178 # Set absolute path to tmux-window1.conf in tmux.conf.
179 perl < tmux.conf > tmux.conf.tmp \
180 -e 'while (<STDIN>) {
181 s/\bTMUX_WINDOW_PATH\b/$ARGV[0]/;
184 "`pwd`/tmux-window1.conf"
185 mv tmux.conf.tmp tmux.conf
187 # 256 colors not available.
188 if test -z "$use_256colors"; then
189 echo tmux.conf: removing 256 colors
190 sed 's/Enable 256 color/Disable 256 color/;
191 s/screen-256color/screen/' tmux.conf > tmux.conf.tmp
192 mv tmux.conf.tmp tmux.conf
194 # Tmux doesn't display a warning if the shell wasn't found!
195 if test ! -x '/bin/zsh'; then
196 echo tmux.conf: removing /bin/zsh as shell
197 sed 's/zsh/sh/' tmux.conf > tmux.conf.tmp
198 mv tmux.conf.tmp tmux.conf
202 # Htop overwrites the comments in its configuration file.
203 generate cat htoprc .in
205 # Copy remindrc template if ~/.reminders doesn't exist yet.
206 if installed remind && test ! -e "$HOME/.reminders"; then
207 echo remind: copying template to .reminders
208 cp reminders.in "$HOME/.reminders"
214 # Link setup for shells.
217 link bash/rc ~/.bashrc
218 link bash/profile ~/.bash_profile
219 link bash/logout ~/.bash_logout
220 if installed csh; then
224 link zsh/env ~/.zshenv
226 link zsh/logout ~/.zlogout
228 # Link setup for additional files.
229 if installed crontab; then
230 link crontab.d ~/.crontab.d
232 link lessfilter ~/.lessfilter
233 if installed colordiff; then
234 link colordiffrc ~/.colordiffrc
236 link inputrc ~/.inputrc
237 link screenrc ~/.screenrc
238 if installed tmux; then
239 link tmux.conf ~/.tmux.conf
241 if installed htop; then
242 link htoprc ~/.htoprc
243 # New location for htoprc. Use both for compatibility.
244 mkdir -p ~/.config/htop
245 link htoprc ~/.config/htop/htoprc