source: tags/confman-1.5/confman_completions @ 133

Revision 133, 3.9 KB checked in by ccowart, 5 years ago (diff)

Renaming the completions to correspond to the Makefile.

  • Property svn:keywords set to Id
Line 
1#!/bin/bash
2#
3#                                               TODO
4#
5#               * Right now this won't update module listings until they
6#                 get added to the recipe file.
7_confman()
8{
9        local cur prev cmds twoback cmds fd_cmds mod_cmds chkpt_cmds
10        local CONFMAN CONFMAN_CONF CONFMAN_RC RECIPE_PATH WORK_PATH
11
12        # Setup ConfMan specific vars
13        CONFMAN="/usr/local/rescomp/sbin/confman"
14        CONFMAN_CONF="/usr/local/rescomp/etc/confman.conf"
15        CONFMAN_RC="~/.confmanrc"
16        if [ -e ${CONFMAN_RC} ] ; then
17                RECIPE_PATH=$(grep '^RECIPE_PATH' ${CONFMAN_RC}|cut -d'"' -f2)
18                WORK_PATH=$(grep '^WORK_PATH' ${CONFMAN_RC}|cut -d'"' -f2)
19        elif [ -e ${CONFMAN_CONF} ] ; then
20                RECIPE_PATH=$(grep '^RECIPE_PATH' ${CONFMAN_CONF}|cut -d'"' -f2)
21                WORK_PATH=$(grep '^WORK_PATH' ${CONFMAN_CONF}|cut -d'"' -f2)
22        fi
23        RECIPE_PATH=$(eval echo $RECIPE_PATH)
24        WORK_PATH=$(eval echo $WORK_PATH)
25
26        # Setup Standard command completion vars
27        COMPREPLY=()
28        cur="${COMP_WORDS[COMP_CWORD]}"
29        prev="${COMP_WORDS[COMP_CWORD-1]}"
30        if [ ${#COMP_WORDS[*]} -gt 3 ] ; then
31            twoback="${COMP_WORDS[COMP_CWORD-2]}"
32        fi
33        if [ ${#COMP_WORDS[*]} -gt 4 ] ; then
34            threeback="${COMP_WORDS[COMP_CWORD-3]}"
35        fi
36        [ ! -x $CONFMAN ] && echo "confman support not available!!" && exit 1
37       
38        # These vars are to better organize things to complete to as well as
39        # provide loose documention about what this does.
40        #
41        #       fd_cmds:        commands that take files and directories as args
42        #       mod_cmds:       commands that take modules as args
43        #       chkpt_cmds:     commands that take modules that take checkpoints as args
44        #                               Ex. confman checknew MODULE CHECKPOINT
45        #                                                               /\ A chkpt_cmd
46        #       cmds:           commands that confman can take as the first arg
47        #
48        fd_cmds="rm cp mv mkdir ls chown chgrp chmod chcom log install revert"
49        mod_cmds="create rmmod import checklook checknew checkclear rollback"
50        # 'rollback' is also a chkpt_cmd, but needs to be handled separately
51        # because it's the only one that handles dated checkpoints.
52        chkpt_cmds="checklook checknew checkclear"
53        cmds="help setup update commit diff status rollback $fd_cmds $mod_cmds"
54       
55        if [ "${prev}" == "confman" -o "${prev}" == "help" ] ; then
56                COMPREPLY=($(compgen -W "${cmds}" -- ${cur})) 
57                return 0
58        elif [ `expr "${fd_cmds}" : ".*\(${prev}\).*"` ] ; then
59                COMPREPLY=( $(compgen -A directory -A file ${cur}) )
60                return 0
61        elif [ `expr "${mod_cmds}" : ".*\(${prev}\).*"` ] ; then
62                local modules=$(grep -vE '^#|^$' $RECIPE_PATH | tr '\n' ' ')
63                COMPREPLY=($(compgen -W "${modules}" -- ${cur}))
64                return 0
65        elif [ `expr "import ${fd_cmds}" : ".*\(${twoback}\).*"` ] ; then
66                COMPREPLY=($(compgen -A directory -A file ${cur}))
67                return 0
68        elif [ `expr "${chkpt_cmds}" : ".*\(${twoback}\).*"` ] ; then
69                local module=${prev}
70                local checkpoints=$(confman checklook ${module}|tr '\n' ' ')
71                COMPREPLY=($(compgen -W "${checkpoints}" -- ${cur}))
72                return 0
73        elif [ "rollback" == "${twoback}" ] ; then
74                local module=${prev}
75                local module_path="${WORK_PATH}/${module}"
76                local named_checkpoints=$(confman checklook ${module}|\
77                                                tr '\n' ' '
78                                        )
79                local numbered_checkpoints=$(confman log $module_path|grep '^r[0-9][0-9]*' |\
80                        sed 's/.*\(20[0-9][0-9]\)-\([0-9][0-9]\)-\([0-9][0-9]\).*/"\1\2\3"/'|\
81                        tr '\n' ' ')
82                checkpoints="${named_checkpoints} ${numbered_checkpoints}"
83                COMPREPLY=($(compgen -W "${checkpoints}" -- ${cur}))
84                return 0
85        elif [ "rollback" == "${threeback}" ] ; then
86                local module=${twoback}
87                local module_path="${WORK_PATH}/${module}"
88                local day=${prev:0:4}-${prev:4:2}-${prev:6:2}
89                local hoursmins=$(confman log $module_path|grep '^r[0-9][0-9]*' |\
90                                        grep 2006-04-06|\
91                                        sed 's/.*20[0-9][0-9]-[0-9][0-9]-[0-9][0-9] \([0-9][0-9]\):\([0-9][0-9]\).*/"\1\2"/'|\
92                                        tr '\n' ' '
93                                )
94                COMPREPLY=($(compgen -W "${hoursmins}" -- ${cur}))
95                return 0
96        fi
97
98        return 0
99}
100
101# It's necessary to not define a catch-all completion above so that we
102# can use the '-o filenames' switch to best handle {file,dir}name
103# completions.
104complete -F _confman -o filenames confman
105
106# vim:ts=4
Note: See TracBrowser for help on using the repository browser.