~ubuntu-branches/debian/wheezy/byobu/wheezy

« back to all changes in this revision

Viewing changes to byobu-select-profile

  • Committer: Bazaar Package Importer
  • Author(s): Philipp Kern
  • Date: 2010-06-28 18:04:16 UTC
  • mfrom: (0.5.1 upstream) (0.3.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100628180416-3xgfpga8cvp872ye
Upload to Debian unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh -e
2
 
#
3
 
#    byobu-select-profile
4
 
#    Copyright (C) 2008 Canonical Ltd.
5
 
#
6
 
#    Authors: Dustin Kirkland <kirkland@canonical.com>
7
 
#             Nick Barcet <nick.barcet@ubuntu.com>
8
 
#
9
 
#    This program is free software: you can redistribute it and/or modify
10
 
#    it under the terms of the GNU General Public License as published by
11
 
#    the Free Software Foundation, version 3 of the License.
12
 
#
13
 
#    This program is distributed in the hope that it will be useful,
14
 
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
#    GNU General Public License for more details.
17
 
#
18
 
#    You should have received a copy of the GNU General Public License
19
 
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 
 
21
 
 
22
 
# If you change any strings, please generate localization information with:
23
 
#       ./debian/rules get-po
24
 
 
25
 
PKG="byobu"
26
 
 
27
 
TEXTDOMAIN="$PKG"
28
 
 
29
 
usage () {
30
 
    cat <<EOT
31
 
usage: byobu-select-profile [(-l|--list)][(-h|--help)][(-s|--set) PROFILE]
32
 
    -l,--list           list available profiles
33
 
    -s,--set PROFILE    set profile
34
 
    -h,--help           this help
35
 
 
36
 
    Without any parameters, runs interactively.
37
 
EOT
38
 
}
39
 
 
40
 
# Initialize variables
41
 
BASE_DIR="/usr/share/$PKG"
42
 
PROFILE_DIR="$BASE_DIR/profiles"
43
 
profile=""
44
 
selected=-1
45
 
 
46
 
assert_symlink() {
47
 
        if [ -e "$1" ]; then
48
 
                if [ ! -L "$1" ]; then
49
 
                        echo `gettext 'Error:'` $1 `gettext ' file exists, but is not a symlink'`
50
 
                        exit 1
51
 
                fi
52
 
        fi
53
 
}
54
 
 
55
 
mkdir -p "$HOME/.$PKG"
56
 
# If these files exist, they must be a symlink
57
 
assert_symlink "$HOME/.$PKG/profile"
58
 
 
59
 
listprofiles() {
60
 
        # Display list of profiles, one per line
61
 
        # Start with basic profiles
62
 
        basename $(ls $PROFILE_DIR/NONE 2>/dev/null) 2>/dev/null
63
 
        basename $(ls $PROFILE_DIR/light 2>/dev/null) 2>/dev/null
64
 
        basename $(ls $PROFILE_DIR/dark 2>/dev/null) 2>/dev/null
65
 
        basename $(ls $PROFILE_DIR/black 2>/dev/null) 2>/dev/null
66
 
        # Now, list advanced profiles
67
 
        for x in $(ls $PROFILE_DIR/*_* 2>/dev/null); do
68
 
                x=$(basename "$x")
69
 
                if [ $x = "common" -o $x = "misc" ]; then
70
 
                        # Skip the common profile, no value there
71
 
                        continue
72
 
                fi
73
 
                echo "$x"
74
 
        done
75
 
}
76
 
 
77
 
prompt() {
78
 
        # Prompt the user to choose among the available profiles
79
 
        echo
80
 
        echo `gettext "Select a screen profile: "`
81
 
        i=0
82
 
        profiles=$(listprofiles)
83
 
        for x in $profiles; do
84
 
                i=$(expr $i + 1)
85
 
                desc="          "
86
 
                if [ "$x" = "light" ]; then
87
 
                        simple=$i
88
 
                fi
89
 
                [ $i -lt 10 ] && i=" $i"
90
 
                echo " $i. $x$desc"
91
 
        done
92
 
        echo
93
 
        selected=x
94
 
        count=1
95
 
        while /bin/true; do
96
 
                if [ $count -gt 5 ]; then
97
 
                        echo `gettext "ERROR: Invalid selection"`
98
 
                        exit 1
99
 
                fi
100
 
                count=`expr $count + 1`
101
 
                if [ -z "$selected" -a ! -z "$simple" ]; then
102
 
                        selected="$simple"
103
 
                elif ! test $selected -gt 0 2>/dev/null; then
104
 
                        echo -n "`gettext 'Choose'` 1-$i [$simple]: "
105
 
                        selected=`head -n1`
106
 
                elif ! test $selected -le $i 2>/dev/null; then
107
 
                        echo -n "`gettext 'Choose'` 1-$i [$simple]: "
108
 
                        selected=`head -n1`
109
 
                else
110
 
                        break
111
 
                fi
112
 
        done
113
 
        SELECTED="$selected"
114
 
}
115
 
 
116
 
setprofile() {
117
 
        # Apply a profile by name or index
118
 
        if [ -n "$1" ]; then
119
 
                selected="$1"
120
 
        else
121
 
                selected="$SELECTED"
122
 
        fi
123
 
        i=0
124
 
        found=0
125
 
        profiles=$(listprofiles)
126
 
        for x in $profiles; do
127
 
                i=`expr $i + 1`
128
 
                if [ "$i" = "$selected" -o "$x" = "$selected" ]; then
129
 
                        rm -f "$HOME/.$PKG/profile"
130
 
                        ln -s "$PROFILE_DIR/$x" "$HOME/.$PKG/profile"
131
 
                        found=1
132
 
                        echo
133
 
                        if [ -n "$STY" ]; then
134
 
                                echo `gettext 'If you are using the default set of keybindings, press\n<F5> to activate these changes.\n\nOtherwise, exit this screen session and start a new one.'`
135
 
                        else
136
 
                                echo `gettext 'Run "byobu" to activate'`
137
 
                        fi
138
 
                        echo
139
 
                        break
140
 
                fi
141
 
        done
142
 
        if [ $found -eq 0 ]; then
143
 
                echo "Invalid profile"
144
 
        fi
145
 
}
146
 
 
147
 
if [ $# -eq 0 ]; then
148
 
        prompt
149
 
        setprofile
150
 
else
151
 
        TEMP=`getopt -o lhs: --long list,help,set: -- "$@"`
152
 
        eval set -- "$TEMP"
153
 
        while true; do
154
 
                case "$1" in
155
 
                        -s|--set)
156
 
                                setprofile "$2"
157
 
                                shift 2
158
 
                                break
159
 
                        ;;
160
 
                        -l|--list)
161
 
                                listprofiles
162
 
                                shift
163
 
                                break
164
 
                        ;;
165
 
                        *)
166
 
                                usage
167
 
                                exit 1
168
 
                        ;;
169
 
                        --)
170
 
                                shift
171
 
                                break
172
 
                        ;;
173
 
                esac
174
 
        done
175
 
fi
176
 
 
177
 
exit 0