~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to fai/aba/aba

  • Committer: Robert Collins
  • Date: 2005-09-08 11:21:38 UTC
  • mto: (147.2.6) (364.1.3 bzrtools)
  • mto: This revision was merged to the branch mainline in revision 324.
  • Revision ID: robertc@robertcollins.net-20050908112138-033369d3cacacb55
test and deliver basic pending-merges into bzr so that merging is recorded

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
# Copyright (C) 2004 Aaron Bentley
 
3
#
 
4
# See the file "COPYING" for further information about
 
5
# the copyright and warranty status of this work.
 
6
 
 
7
readlink_qualify () {
 
8
    case $2 in
 
9
        /*) readlink_f "$2";;
 
10
        *) readlink_f "$1/$2";;
 
11
    esac
 
12
}
 
13
 
 
14
readlink_f () {
 
15
    if [ -h "$1" ]; then
 
16
        readlink_qualify `dirname -- "$1"` `readlink "$1"`
 
17
    else
 
18
        echo "$1";
 
19
    fi
 
20
}
 
21
 
 
22
# Get directory where this script resides -- allows systemwide installation.
 
23
test -z "$abadir" -a -f "$HOME/.aba/aba-lib" && abadir="$HOME/.aba"
 
24
test -z "$abadir" && abadir=$(dirname $(readlink_f "$0"))
 
25
test -f "$abadir/aba-lib" || {
 
26
    echo "* Can't find aba-lib. Please set abadir to wherever it resides." >&2
 
27
    exit 1
 
28
}
 
29
export abadir
 
30
abaname=$(basename $0)
 
31
export abaname
 
32
 
 
33
cmd=$1
 
34
[ -z "$cmd" ] || shift 
 
35
if tmp=`tla tree-root 2>/dev/null`; then treeroot=$tmp; fi
 
36
 
 
37
if [ -n "$treeroot" -a -f "$treeroot/{arch}/++options/$cmd" ]; then
 
38
    prefix=`cat "$treeroot/{arch}/++options/$cmd"`
 
39
elif [ -f ~/.aba/options/$cmd ]; then
 
40
    prefix=`cat ~/.aba/options/$cmd`
 
41
elif [ -f "$abadir/options/$cmd" ]; then
 
42
    prefix=`cat "$abadir/options/$cmd"`
 
43
fi
 
44
 
 
45
if [ -f ~/.aba/aliases ]; then
 
46
    aliaschar=$(grep '^[        ]*aliaschar=.*' <~/.aba/aliases)
 
47
    eval "$aliaschar" # So we honor quoting
 
48
    aliaschar=${aliaschar:-^} # With zsh's extended globbing, ^ is no good choice.
 
49
fi
 
50
 
 
51
if [ -n "$aliaschar" ]; then
 
52
    case $aliaschar in
 
53
        \*)
 
54
            echo 'Aliaschar "*" '"won't work." >&2
 
55
            exit 1;;
 
56
        \[|\]|.|^|\\)
 
57
            prepare_alias () {
 
58
                sed "s:[\$]:\\\\\$:g;s:\\$aliaschar:\$:g" <<EOS
 
59
$1
 
60
EOS
 
61
            } ;;
 
62
        $)
 
63
            prepare_alias () { 
 
64
                echo "$1" 
 
65
            } ;;
 
66
        *)
 
67
            prepare_alias () {
 
68
                sed "s:[\$]:\\\\\$:g;s:$aliaschar:\$:g" <<EOS
 
69
$1
 
70
EOS
 
71
            } ;;
 
72
    esac
 
73
 
 
74
    # This runs in subshell due to round brackets.
 
75
    expand_alias () (
 
76
        if [ -n "$treeroot" ]; then
 
77
          if [ -f $treeroot/++aliases ]; then
 
78
            . $treeroot/++aliases
 
79
          fi
 
80
        fi
 
81
        . ~/.aba/aliases
 
82
        eval "printf '%s' \"$(prepare_alias "$1")\""
 
83
    )
 
84
 
 
85
    # Spacewise correct expand-aliases, inline
 
86
    # Well, actualy it's not correct for arguments that are expanded, but
 
87
    # I don't know how to do that (command-substitution is not correct).
 
88
    for arg; do
 
89
        shift
 
90
        case $arg in
 
91
            $aliaschar$aliaschar*)
 
92
                set -- "$@" "$arg";;
 
93
            *$aliaschar*)
 
94
                arg=$(expand_alias "$arg") 
 
95
                set -- "$@" "$arg";;
 
96
            *)  set -- "$@" "$arg";;
 
97
        esac
 
98
    done
 
99
fi
 
100
 
 
101
if [ ! -z "$cmd" ] &&  [ -x ~/.aba/commands/$cmd ] && [ ! -d ~/.aba/commands/$cmd ]; then
 
102
#    echo ~/.aba/commands/$cmd exec $prefix "$@"
 
103
    ~/.aba/commands/$cmd exec $prefix "$@"
 
104
elif [ ! -z "$cmd" ] &&  [ -x "$abadir/commands/$cmd" ] && [ ! -d "$abadir/commands/$cmd" ]; then
 
105
#    echo "$abadir/commands/$cmd" exec $prefix "$@"
 
106
    "$abadir/commands/$cmd" exec $prefix "$@"
 
107
else
 
108
#    echo tla $cmd $prefix "$@"
 
109
  if [ -n "$ABAFILTER" ]; then
 
110
    unset EDITOR
 
111
    export EDITOR
 
112
    tla $cmd $prefix "$@" | $ABAFILTER
 
113
  else
 
114
    tla $cmd $prefix "$@"
 
115
  fi
 
116
fi
 
117
# arch-tag: aba by Aaron Bentley (12:14 Jan 15, 2004)