~ubuntu-branches/ubuntu/utopic/byobu/utopic

« back to all changes in this revision

Viewing changes to usr/bin/byobu-status

  • Committer: Bazaar Package Importer
  • Author(s): Dustin Kirkland
  • Date: 2010-01-11 22:54:36 UTC
  • mto: This revision was merged to the branch mainline in revision 49.
  • Revision ID: james.westby@ubuntu.com-20100111225436-csnrc41k0bewth1e
Tags: upstream-2.47
ImportĀ upstreamĀ versionĀ 2.47

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh -e
 
2
#
 
3
#    byobu-status
 
4
#    Copyright (C) 2008 Canonical Ltd.
 
5
#
 
6
#    Authors: Dustin Kirkland <kirkland@canonical.com>
 
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
PKG="byobu"
 
21
 
 
22
find_script () {
 
23
        # Allow for local status scripts
 
24
        if [ -x "$HOME/.$PKG/bin/$1" ]; then
 
25
                echo "$HOME/.$PKG/bin/$1"
 
26
        elif [ -x "/usr/lib/$PKG/$1" ]; then
 
27
                echo "/usr/lib/$PKG/$1"
 
28
        else
 
29
                echo "/dev/null"
 
30
        fi
 
31
}
 
32
 
 
33
# Define colors
 
34
ESC="\005"
 
35
color() {
 
36
        if [ -z "$1" ] || [ "$COLOR" = "none" ]; then
 
37
                return 0
 
38
        fi
 
39
        case $1 in
 
40
                -)   printf "$ESC{-}" ;;
 
41
                esc)    printf "$ESC" ;;
 
42
                bold1)  printf "$ESC{=b }" ;;
 
43
                bold2)  printf "$ESC{+b }" ;;
 
44
                none)   printf "$ESC{= }" ;;
 
45
                invert) printf "$ESC{=r }" ;;
 
46
                *)
 
47
                        if [ "$#" = "2" ]; then
 
48
                                [ "$COLOR" = "monochrome" ] && printf "$ESC{= }" || printf "$ESC{= $1$2}"
 
49
                        else
 
50
                                [ "$COLOR" = "monochrome" ] && printf "$ESC{=$1 }" || printf "$ESC{=$1 $2$3}"
 
51
                        fi
 
52
                ;;
 
53
        esac
 
54
}
 
55
 
 
56
# Source configurations
 
57
[ -r "$HOME/.$PKG/color" ] && . "$HOME/.$PKG/color"
 
58
[ -r "/etc/$PKG/statusrc" ] && . "/etc/$PKG/statusrc"
 
59
[ -r "$HOME/.$PKG/status" ] && . "$HOME/.$PKG/status"
 
60
[ -r "$HOME/.$PKG/statusrc" ] && . "$HOME/.$PKG/statusrc"
 
61
 
 
62
export P="$1"
 
63
case "$P" in
 
64
        --detail)
 
65
                VER=
 
66
                if which dpkg-query >/dev/null; then
 
67
                        VER=`dpkg-query --show $PKG | awk '{print "-" $2 }'`
 
68
                fi
 
69
                printf "$PKG$VER Detailed Status Navigation\n  Expand all - zr\t\tCollapse all - zm\n  Expand one - zo\t\tCollapse one - zc\n\n"
 
70
                for i in $(ls "/usr/lib/$PKG" "$HOME/.$PKG/bin" 2>/dev/null | grep -v "^/" | sort -u); do
 
71
                        [ "$i" = "menu" ] && continue
 
72
                        script=`find_script $i`
 
73
                        short=`$script --short | sed 's/^\s*//' | sed 's/\s*$//' | sed 's/.{[^}]*}//g'` || true
 
74
                        detail=`$script --detail | sed '/^$/d' | sed 's/^/\t/g'` || true
 
75
                        printf "%s\n\t(%s)\n" "$short" "$i"
 
76
                        [ -n "$detail" ] && printf "%s\n" "$detail"
 
77
                done
 
78
        ;;
 
79
        color)
 
80
                [ -z "$FOREGROUND" ] && FOREGROUND="w"
 
81
                [ -z "$BACKGROUND" ] && BACKGROUND="k"
 
82
                printf "$ESC{= $BACKGROUND$FOREGROUND}"
 
83
        ;;
 
84
        *)
 
85
                eval x="\$$P" || exit 1
 
86
                [ "$x" = "1" ] || exit 0
 
87
                . $(find_script "$P")
 
88
esac