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. Prevent cluttering ~/ by storing the history
43 # file in this directory; this requires replacing the constant HISTORY_PATH in
45 echo lesskey: generating .lesskey
48 s/\bHISTORY_PATH\b/$ARGV[0]/;
55 # Find the required options to get colored ls output. GNU ls is preferred. See
56 # shell/aliases.in for details. Doing this here instead of in shell/aliases
57 # speeds up shell starts.
59 # Check if colors are available.
60 ls --color > /dev/null 2>&1
61 if test $? -eq 0; then
64 ls -G > /dev/null 2>&1
65 if test $? -eq 0; then
71 # Absolute path to `ls`.
74 if test "x$ls_color" = xgnu; then
77 # Normal (BSD) ls with colors.
78 elif test "x$ls_color" = xcli; then
79 ls_env='CLICOLOR_FORCE=1'
81 # Simple ls with no colors.
86 generate perl shell/aliases \
88 s/\bLS_ENV\b/$ARGV[0]/;
89 s/\bLS_PATH\b/$ARGV[1]/;
90 s/\bLS_COLOR\b/$ARGV[2]/;
93 "$ls_env" "$ls_path" "$ls_color"
95 generate cat screenrc .in
96 # As screen-256color is not widely supported use it only on machines where the
97 # matching terminfo entry is available. This also requires a terminal emulator
98 # which supports 256 colors. Also used for tmux.
100 if terminal_available screen-256color; then
101 # Called through SSH connection, assume the local system supports 256
103 if test -n "$SSH_CONNECTION"; then
105 # We have rxvt-unicode installed, check if it supports 256 colors.
106 elif installed urxvt; then
107 # Thanks to deryni in #rxvt-unicode on Freenode (2012-10-14 22:54
108 # CEST) for the strings/grep idea. The grep check is for "correct" 256
109 # rxvt-unicode binaries (e.g. Debian's rxvt-unicode-256color), the
110 # terminal_info check for manual installations which modify
111 # rxvt-unicode's terminfo entry.
112 urxvt_path=`which urxvt`
113 urxvt_grep=`strings "$urxvt_path" | grep '^TERM=rxvt-'`
114 if test x"$urxvt_grep" = 'xTERM=rxvt-unicode-256color' \
115 || terminal_info rxvt-unicode \
116 | grep -F 'colors#256' >/dev/null; then
119 # Check if XTerm supports 256 colors (not a perfect check, but most XTerm
120 # support 256 colors).
121 elif terminal_available xterm-256color; then
125 if test -z "$use_256colors"; then
126 echo screenrc: removing 256 colors
127 sed 's/Enable 256 color/Disable 256 color/;
128 s/screen-256color/screen/' screenrc > screenrc.tmp
129 mv screenrc.tmp screenrc
131 # Some options are only necessary when running as root. They are marked as
133 if test "`id -u`" -ne 0; then
134 echo screenrc: removing root options
135 grep -v '(ROOT)' screenrc > screenrc.tmp
136 mv screenrc.tmp screenrc
138 # I use some features of GNU screen which are only in Git or very recent GNU
139 # screen versions. Drop them on machines which have older versions. They are
141 if test ! -d "$HOME/development/shell/screen"; then
142 echo screenrc: removing Git features
143 grep -v '(GIT)' screenrc > screenrc.tmp
144 mv screenrc.tmp screenrc
146 # Rxvt doesn't need the attrcolor "fix". As I prefer rxvt assume I use it when
148 if installed rxvt; then
149 echo screenrc: removing attrcolor \"fix\"
150 sed 's/attrcolor b ".I"/#attrcolor b ".I"/' screenrc > screenrc.tmp
151 mv screenrc.tmp screenrc
153 # Display current battery charge on computers with a battery. Necessary lines
154 # are marked as "(BATTERY)".
155 if test ! -d /sys/class/power_supply/BAT0; then
156 echo screenrc: removing battery display
157 grep -v '(BATTERY)' screenrc > screenrc.tmp
158 mv screenrc.tmp screenrc
161 if installed tmux; then
162 generate perl tmux.conf ./bin/remove-continuation.pl
164 # Add mappings to switch to windows 10-29 quickly. See tmux-window.pl for
166 perl ./tmux-window.pl 1 "`pwd`/tmux-window2.conf" > tmux-window1.conf
167 perl ./tmux-window.pl 2 > tmux-window2.conf
168 # Set absolute path to tmux-window1.conf in tmux.conf.
169 perl < tmux.conf > tmux.conf.tmp \
170 -e 'while (<STDIN>) {
171 s/\bTMUX_WINDOW_PATH\b/$ARGV[0]/;
174 "`pwd`/tmux-window1.conf"
175 mv tmux.conf.tmp tmux.conf
177 # 256 colors not available.
178 if test -z "$use_256colors"; then
179 echo tmux.conf: removing 256 colors
180 sed 's/Enable 256 color/Disable 256 color/;
181 s/screen-256color/screen/' tmux.conf > tmux.conf.tmp
182 mv tmux.conf.tmp tmux.conf
184 # Tmux doesn't display a warning if the shell wasn't found!
185 if test ! -x '/bin/zsh'; then
186 echo tmux.conf: removing /bin/zsh as shell
187 sed 's/zsh/sh/' tmux.conf > tmux.conf.tmp
188 mv tmux.conf.tmp tmux.conf
192 # Htop overwrites the comments in its configuration file.
193 generate cat htoprc .in
195 # Copy remindrc template if ~/.reminders doesn't exist yet.
196 if installed remind && test ! -e "$HOME/.reminders"; then
197 echo remind: copying template to .reminders
198 cp reminders.in "$HOME/.reminders"
201 # Link setup for shells.
204 link bash/rc ~/.bashrc
205 link bash/profile ~/.bash_profile
206 link bash/logout ~/.bash_logout
207 if installed csh; then
211 link zsh/env ~/.zshenv
213 link zsh/logout ~/.zlogout
215 # Link setup for additional files.
216 link lessfilter ~/.lessfilter
217 if installed colordiff; then
218 link colordiffrc ~/.colordiffrc
220 link inputrc ~/.inputrc
221 link screenrc ~/.screenrc
222 if installed tmux; then
223 link tmux.conf ~/.tmux.conf
225 if installed htop; then
226 link htoprc ~/.htoprc
229 # Create rlwrap history directory.
230 mkdir -p shell/rlwrap