~ubuntu-branches/ubuntu/trusty/byobu/trusty-proposed

« back to all changes in this revision

Viewing changes to .pc/1274720-1311919.patch/usr/bin/byobu-ctrl-a.in

  • Committer: Package Import Robot
  • Author(s): Dustin Kirkland
  • Date: 2014-04-23 18:28:16 UTC
  • Revision ID: package-import@ubuntu.com-20140423182816-tdsyygya8g2ewbba
Tags: 5.77-0ubuntu1.1
* usr/bin/byobu-ctrl-a.in: LP: #1274720
  - cherry pick upstream r2338
  - revert r2317, as this is breaking ctrl-a in byobu-screen in a bad way
* usr/bin/byobu-janitor.in: LP: #1311919
  - cherry pick upstream r2337
  - ensure that windows.tmux exists;  fixes nasty warning with F5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
#
 
3
#    byobu-ctrl-a - set the ctrl-a behavior
 
4
#    Copyright (C) 2011 Canonical Ltd.
 
5
#
 
6
#    Authors: Dustin Kirkland <kirkland@byobu.co>
 
7
#
 
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.
 
11
#
 
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.
 
16
#
 
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/>.
 
19
 
 
20
Usage() {
 
21
        cat <<EOF
 
22
Usage: ${0##*/} [mode]
 
23
   mode is one of 'screen' or 'emacs'
 
24
   if not specified, prompt the user
 
25
EOF
 
26
}
 
27
 
 
28
PKG="byobu"
 
29
[ -r "$HOME/.byoburc" ] && . "$HOME/.byoburc"
 
30
[ -z "${BYOBU_PREFIX}" ] && export BYOBU_PREFIX="@prefix@" || export BYOBU_PREFIX
 
31
. "${BYOBU_PREFIX}/lib/${PKG}/include/common"
 
32
 
 
33
bind_to=""
 
34
keybindings="$BYOBU_CONFIG_DIR/keybindings"
 
35
[ "$BYOBU_BACKEND" = "tmux" ] && keybindings="$keybindings.tmux"
 
36
touch "$keybindings"
 
37
 
 
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
 
41
        "screen")
 
42
                if grep -qs "^escape" "$keybindings"; then
 
43
                        # Check for escape definition in local keybindings config
 
44
                        bind_to="emacs"
 
45
                fi
 
46
        ;;
 
47
        "tmux")
 
48
                if grep -qs "^set -g prefix" "$keybindings"e;  then
 
49
                        # Check for escape definition in local keybindings config
 
50
                        bind_to="emacs"
 
51
                fi
 
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
 
54
                        bind_to="emacs"
 
55
                fi
 
56
        ;;
 
57
esac
 
58
 
 
59
case "${1}" in
 
60
        -h|--help) Usage; exit 0;;
 
61
        screen) bind_to="screen";;
 
62
        emacs) bind_to="emacs";;
 
63
        "") :;;
 
64
        *) { Usage printf "%s\n" "Bad argument $1"; } 1>&2; exit 1;;
 
65
esac
 
66
 
 
67
if [ "${2}" ]; then
 
68
        KEY=$(printf "$2" | $BYOBU_SED 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/')
 
69
        key=$(printf "$2" | $BYOBU_SED 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/')
 
70
else
 
71
        KEY="A"
 
72
        key="a"
 
73
fi
 
74
 
 
75
while [ -z "$bind_to" ]; do
 
76
        echo
 
77
        echo "Configure Byobu's ctrl-a behavior..."
 
78
        echo
 
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)"
 
82
        echo
 
83
        echo "Note that:"
 
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"
 
87
        echo
 
88
        printf "Select [1 or 2]: "
 
89
        s=$(head -n1)
 
90
        echo
 
91
        case "$s" in
 
92
                1) bind_to="screen"; break;;
 
93
                2) bind_to="emacs"; break;;
 
94
        esac
 
95
done
 
96
 
 
97
case "$bind_to" in
 
98
        emacs)
 
99
                case "$BYOBU_BACKEND" in
 
100
                        screen)
 
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"
 
104
                        ;;
 
105
                        tmux)
 
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"
 
110
                        ;;
 
111
                esac
 
112
                echo "INFO: ctrl-a will now operate in emacs mode"
 
113
        ;;
 
114
        screen)
 
115
                case "$BYOBU_BACKEND" in
 
116
                        screen)
 
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"
 
122
                        ;;
 
123
                        tmux)
 
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"
 
129
                                else
 
130
                                        # tmux 1.6 and above supports prefix and prefix2
 
131
                                        echo "set -g prefix ^${KEY}" >> "$keybindings"
 
132
                                        echo "set -g prefix2 ^${KEY}" >> "$keybindings"
 
133
                                fi
 
134
                                echo "bind ${key} send-prefix" >> "$keybindings"
 
135
                                $BYOBU_BACKEND source "$BYOBU_PREFIX/share/byobu/profiles/tmuxrc"
 
136
                        ;;
 
137
                esac
 
138
                echo "INFO: ctrl-a will now operate in GNU Screen mode"
 
139
        ;;
 
140
        *)
 
141
                echo "Error: bad value for binding: $bind_to"
 
142
        ;;
 
143
esac
 
144
 
 
145
if [ -z "${2}" ]; then
 
146
        echo "To modify this behavior again later, run 'byobu-ctrl-a'"
 
147
        echo
 
148
fi
 
149
 
 
150
# vi: syntax=sh ts=4 noexpandtab