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 generate cat screenrc .in
47 # As screen-256color is not widely supported use it only on machines where the
48 # matching terminfo entry is available. This also requires a terminal emulator
49 # which supports 256 colors. Also used for tmux.
51 if terminal_available screen-256color; then
52 # Called through SSH connection, assume the local system supports 256
54 if test -n "$SSH_CONNECTION"; then
56 # We have rxvt-unicode installed, check if it supports 256 colors.
57 elif installed urxvt; then
58 # Thanks to deryni in #rxvt-unicode on Freenode (2012-10-14 22:54
59 # CEST) for the strings/grep idea. The grep check is for "correct" 256
60 # rxvt-unicode binaries (e.g. Debian's rxvt-unicode-256color), the
61 # terminal_info check for manual installations which modify
62 # rxvt-unicode's terminfo entry.
63 urxvt_path=`which urxvt`
64 urxvt_grep=`strings "$urxvt_path" | grep '^TERM=rxvt-')`
65 if test x"$urxvt_grep" = 'xTERM=rxvt-unicode-256color' \
66 || terminal_info rxvt-unicode \
67 | grep -F 'colors#256' >/dev/null; then
70 # Check if XTerm supports 256 colors (not a perfect check, but most XTerm
71 # support 256 colors).
72 elif terminal_available xterm-256color; then
76 if test -z "$use_256colors"; then
77 echo screenrc: removing 256 colors
78 sed 's/Enable 256 color/Disable 256 color/;
79 s/screen-256color/screen/' screenrc > screenrc.tmp
80 mv screenrc.tmp screenrc
82 # Some options are only necessary when running as root. They are marked as
84 if test "`id -u`" -ne 0; then
85 echo screenrc: removing root options
86 grep -v '(ROOT)' screenrc > screenrc.tmp
87 mv screenrc.tmp screenrc
89 # I use some features of GNU screen which are only in Git or very recent GNU
90 # screen versions. Drop them on machines which have older versions. They are
92 if test -d "$HOME/development/shell/screen"; then
93 echo screenrc: removing Git features
94 grep -v '(GIT)' screenrc > screenrc.tmp
95 mv screenrc.tmp screenrc
97 # Rxvt doesn't need the attrcolor "fix". As I prefer rxvt assume I use it when
99 if installed rxvt; then
100 echo screenrc: removing attrcolor \"fix\"
101 sed 's/attrcolor b ".I"/#attrcolor b ".I"/' screenrc > screenrc.tmp
102 mv screenrc.tmp screenrc
104 # Display current battery charge on computers with a battery. Necessary lines
105 # are marked as "(BATTERY)".
106 if test ! -d /sys/class/power_supply/BAT0; then
107 echo screenrc: removing battery display
108 grep -v '(BATTERY)' screenrc > screenrc.tmp
109 mv screenrc.tmp screenrc
112 if installed tmux; then
113 generate perl tmux.conf ./bin/remove-continuation.pl
115 # 256 colors not available.
116 if test -z "$use_256colors"; then
117 echo tmux.conf: removing 256 colors
118 sed 's/Enable 256 color/Disable 256 color/;
119 s/screen-256color/screen/' tmux.conf > tmux.conf.tmp
120 mv tmux.conf.tmp tmux.conf
122 # Tmux doesn't display a warning if the shell wasn't found!
123 if test ! -x '/bin/zsh'; then
124 echo tmux.conf: removing /bin/zsh as shell
125 sed 's/zsh/sh/' tmux.conf > tmux.conf.tmp
126 mv tmux.conf.tmp tmux.conf
130 # Htop overwrites the comments in its configuration file.
131 generate cat htoprc .in
133 # Link setup for shells.
136 link bash/rc ~/.bashrc
137 link bash/profile ~/.bash_profile
138 link bash/logout ~/.bash_logout
139 if installed csh; then
143 link zsh/env ~/.zshenv
145 link zsh/logout ~/.zlogout
147 # Link setup for additional files.
148 link lessfilter ~/.lessfilter
149 if installed colordiff; then
150 link colordiffrc ~/.colordiffrc
152 link inputrc ~/.inputrc
153 link screenrc ~/.screenrc
154 if installed tmux; then
155 link tmux.conf ~/.tmux.conf
157 if installed htop; then
158 link htoprc ~/.htoprc
161 # Create rlwrap history directory.
162 mkdir -p shell/rlwrap