3
# byobu-ctrl-a - set the ctrl-a behavior
4
# Copyright (C) 2011 Canonical Ltd.
6
# Authors: Dustin Kirkland <kirkland@byobu.co>
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation, version 3 of the License.
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/>.
22
Usage: ${0##*/} [mode]
23
mode is one of 'screen' or 'emacs'
24
if not specified, prompt the user
29
[ -r "$HOME/.byoburc" ] && . "$HOME/.byoburc"
30
[ -z "${BYOBU_PREFIX}" ] && export BYOBU_PREFIX="@prefix@" || export BYOBU_PREFIX
31
. "${BYOBU_PREFIX}/lib/${PKG}/include/common"
34
keybindings="$BYOBU_CONFIG_DIR/keybindings"
35
[ "$BYOBU_BACKEND" = "tmux" ] && keybindings="$keybindings.tmux"
38
# If the user has already chosen an escape sequence, then
39
# presumably they want ctrl-a to operate in emacs mode
40
case "$BYOBU_BACKEND" in
42
if grep -qs "^escape" "$keybindings"; then
43
# Check for escape definition in local keybindings config
48
if grep -qs "^set -g prefix" "$keybindings"e; then
49
# Check for escape definition in local keybindings config
52
# Check for some other escape sequence in tmux keys
53
if tmux list-keys | grep -qs "^bind-key\s\+[^a]\s\+send-prefix"; then
60
-h|--help) Usage; exit 0;;
61
screen) bind_to="screen";;
62
emacs) bind_to="emacs";;
64
*) { Usage printf "%s\n" "Bad argument $1"; } 1>&2; exit 1;;
68
KEY=$(printf "$2" | $BYOBU_SED 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/')
69
key=$(printf "$2" | $BYOBU_SED 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/')
75
while [ -z "$bind_to" ]; do
77
echo "Configure Byobu's ctrl-a behavior..."
79
echo "When you press ctrl-a in Byobu, do you want it to operate in:"
80
echo " (1) Screen mode (GNU Screen's default escape sequence)"
81
echo " (2) Emacs mode (go to beginning of line)"
84
echo " - F12 also operates as an escape in Byobu"
85
echo " - You can press F9 and choose your escape character"
86
echo " - You can run 'byobu-ctrl-a' at any time to change your selection"
88
printf "Select [1 or 2]: "
92
1) bind_to="screen"; break;;
93
2) bind_to="emacs"; break;;
99
case "$BYOBU_BACKEND" in
101
$BYOBU_SED -i -e "/^register x /d" -e "/^bindkey /d" -e "/^escape /d" "$keybindings"
102
echo "bindkey \"^${KEY}\"" >> "$keybindings"
103
$BYOBU_BACKEND -X at 0 source "$BYOBU_CONFIG_DIR/profile"
106
$BYOBU_SED -i -e "/^set -g prefix/d" -e "/ send-prefix/d" -e "/^unbind-key -n C-${key}/d" "$keybindings"
107
echo "set -g prefix F12" >> "$keybindings"
108
echo "unbind-key -n C-${key}" >> "$keybindings"
109
$BYOBU_BACKEND source "$BYOBU_PREFIX/share/byobu/profiles/tmuxrc"
112
echo "INFO: ctrl-a will now operate in emacs mode"
115
case "$BYOBU_BACKEND" in
117
$BYOBU_SED -i -e "/^register x /d" -e "/^bindkey \"^\"/d" -e "/^escape /d" "$keybindings"
118
echo "escape \"^${KEY}${key}\"" >> "$keybindings"
119
echo "register x \"^${KEY}\"" >> "$keybindings"
120
echo "bindkey \"^${KEY}\" eval \"process x\"" >> "$keybindings"
121
$BYOBU_BACKEND -X at 0 source "$BYOBU_CONFIG_DIR/profile"
124
$BYOBU_SED -i -e "/^set -g prefix/d" -e "/ send-prefix/d" -e "/^unbind-key -n C-${key}/d" "$keybindings"
125
echo "unbind-key -n C-${key}" >> "$keybindings"
126
if $BYOBU_BACKEND -V | grep " 1.5"; then
127
# tmux 1.5 supports a list of prefixes
128
echo "set -g prefix ^${KEY},F12" >> "$keybindings"
130
# tmux 1.6 and above supports prefix and prefix2
131
echo "set -g prefix ^${KEY}" >> "$keybindings"
132
echo "set -g prefix2 ^${KEY}" >> "$keybindings"
134
echo "bind ${key} send-prefix" >> "$keybindings"
135
$BYOBU_BACKEND source "$BYOBU_PREFIX/share/byobu/profiles/tmuxrc"
138
echo "INFO: ctrl-a will now operate in GNU Screen mode"
141
echo "Error: bad value for binding: $bind_to"
145
if [ -z "${2}" ]; then
146
echo "To modify this behavior again later, run 'byobu-ctrl-a'"
150
# vi: syntax=sh ts=4 noexpandtab