]> ruderich.org/simon Gitweb - config/dotfiles.git/blob - shell/shell/rc
herbstluftwm/autostart: add bindings to run programs and select windows
[config/dotfiles.git] / shell / shell / rc
1 # Shell configuration file.
2
3 # Copyright (C) 2013-2014  Simon Ruderich
4 #
5 # This file is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This file is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this file.  If not, see <http://www.gnu.org/licenses/>.
17
18
19 # Normal umask for root (readable by all users).
20 if test "`id -u`" -eq 0; then
21     umask 022
22 # Restricted umask for normal users (readable only by me).
23 else
24     umask 077
25 fi
26
27 # Disable flow control (^s and ^q). I use GNU Screen/Tmux which also supports
28 # this in a similar way (entering copy mode) and enabling flow control by
29 # accident is annoying.
30 if test -t 0; then
31     stty -ixon -ixoff
32 fi
33
34 # Auto-logout after timeout on TTYs. It's easy to forget to logout after
35 # switching back to X11 from a TTY.
36 timeout_setup_screen_lock() {
37     echo "Locking GNU screen after $timeout seconds (TTY detected)."
38     screen -X idle $timeout lockscreen
39     echo
40 }
41 timeout_setup_tmux_lock() {
42     if type vlock >/dev/null; then
43         echo "Locking Tmux after $timeout seconds (TTY detected)."
44         tmux set-option lock-after-time $timeout
45         echo
46
47     else
48         echo "vlock not found, locking won't work in Tmux!" >&2
49         echo "Falling back to shell timeout." >&2
50         echo
51
52         timeout_setup_shell_logout
53     fi
54 }
55 timeout_setup_shell_logout() {
56     echo "Auto-logout after $timeout seconds (TTY detected)."
57     TMOUT=$timeout
58     echo
59 }
60 # Timeout in seconds.
61 local timeout >/dev/null 2>&1
62 timeout=600
63 case "$TERM" in
64     # `tty` doesn't work inside a pseudo-terminal as provided by GNU
65     # Screen/Tmux.
66     #
67     # The following settings for GNU Screen/Tmux will only auto-lock new
68     # sessions, not when attaching to existing sessions!
69     screen*)
70         if test -n "$STY"; then
71             case "$STY" in
72                 *.tty[0-9]*.*)
73                     timeout_setup_screen_lock
74                     ;;
75             esac
76         elif test -n "$TMUX"; then
77             case "`tmux display -p '#{client_tty}'`" in
78                 /dev/tty[0-9]*)
79                     timeout_setup_tmux_lock
80                     ;;
81                 /dev/*)
82                     # Not on TTY, nothing to do.
83                     ;;
84                 *)
85                     echo 'Tmux < 1.8 found, TTY check might be incorrect!' >&2
86
87                     local client >/dev/null 2>&1
88                     client=`printf '%s' "$TMUX" | sed 's/^.*,\([0-9]*\)$/\1/'`
89
90                     case "`tmux list-clients \
91                             | grep -E "^/dev/.*?: $client "`" in
92                         /dev/tty[0-9]*)
93                             timeout_setup_tmux_lock
94                             ;;
95                     esac
96                     ;;
97             esac
98         else
99             echo 'TERM=screen but neither $STY nor $TMUX found!' >&2
100             timeout_setup_shell_logout
101         fi
102         ;;
103
104     *)
105         case `tty` in
106             /dev/tty[0-9]*)
107                 timeout_setup_shell_logout
108                 ;;
109         esac
110         ;;
111 esac
112 unset timeout
113 unset timeout_setup_screen_lock
114 unset timeout_setup_tmux_lock
115 unset timeout_setup_screen_lock
116
117 # vim: ft=sh