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.'
39 # Create private temporary directory used by many tools (including GNU screen
44 # Generate ~/.less with lesskey.
48 generate cat screenrc .in
49 # As screen-256color is not widely supported use it only on machines where the
50 # matching terminfo entry is available. This also requires a terminal emulator
51 # which supports 256 colors. Also used for tmux.
53 if terminal_available screen-256color; then
54 # Called through SSH connection, assume the local system supports 256
56 if test -n "$SSH_CONNECTION"; then
58 # We have rxvt-unicode installed, check if it supports 256 colors.
59 elif installed urxvt; then
60 # Thanks to deryni in #rxvt-unicode on Freenode (2012-10-14 22:54
61 # CEST) for the strings/grep idea. The grep check is for "correct" 256
62 # rxvt-unicode binaries (e.g. Debian's rxvt-unicode-256color), the
63 # terminal_info check for manual installations which modify
64 # rxvt-unicode's terminfo entry.
65 urxvt_path=`which urxvt`
66 urxvt_grep=`strings "$urxvt_path" | grep '^TERM=rxvt-')`
67 if test x"$urxvt_grep" = 'xTERM=rxvt-unicode-256color' \
68 || terminal_info rxvt-unicode \
69 | grep -F 'colors#256' >/dev/null; then
72 # Check if XTerm supports 256 colors (not a perfect check, but most XTerm
73 # support 256 colors).
74 elif terminal_available xterm-256color; then
78 if test -z "$use_256colors"; then
79 echo screenrc: removing 256 colors
80 sed 's/Enable 256 color/Disable 256 color/;
81 s/screen-256color/screen/' screenrc > screenrc.tmp
82 mv screenrc.tmp screenrc
84 # Some options are only necessary when running as root. They are marked as
86 if test "`id -u`" -ne 0; then
87 echo screenrc: removing root options
88 grep -v '(ROOT)' screenrc > screenrc.tmp
89 mv screenrc.tmp screenrc
91 # I use some features of GNU screen which are only in Git or very recent GNU
92 # screen versions. Drop them on machines which have older versions. They are
94 if test -d "$HOME/development/shell/screen"; then
95 echo screenrc: removing Git features
96 grep -v '(GIT)' screenrc > screenrc.tmp
97 mv screenrc.tmp screenrc
99 # Rxvt doesn't need the attrcolor "fix". As I prefer rxvt assume I use it when
101 if installed rxvt; then
102 echo screenrc: removing attrcolor \"fix\"
103 sed 's/attrcolor b ".I"/#attrcolor b ".I"/' screenrc > screenrc.tmp
104 mv screenrc.tmp screenrc
106 # Display current battery charge on computers with a battery. Necessary lines
107 # are marked as "(BATTERY)".
108 if test ! -d /sys/class/power_supply/BAT0; then
109 echo screenrc: removing battery display
110 grep -v '(BATTERY)' screenrc > screenrc.tmp
111 mv screenrc.tmp screenrc
114 # Htop overwrites the comments in its configuration file.
115 generate cat htoprc .in
117 # Link setup for shells.
120 link bash/rc ~/.bashrc
121 link bash/profile ~/.bash_profile
122 link bash/logout ~/.bash_logout
123 if installed csh; then
127 link zsh/env ~/.zshenv
129 link zsh/logout ~/.zlogout
131 # Link setup for additional files.
132 link lessfilter ~/.lessfilter
133 if installed colordiff; then
134 link colordiffrc ~/.colordiffrc
136 link inputrc ~/.inputrc
137 link screenrc ~/.screenrc
138 if installed tmux; then
139 generate perl tmux.conf ./bin/remove-continuation.pl
140 link tmux.conf ~/.tmux.conf
142 if installed htop; then
143 link htoprc ~/.htoprc
146 # Create rlwrap history directory.
147 mkdir -p shell/rlwrap