Changeset 87


Ignore:
Timestamp:
04/18/2006 22:10:47 (6 years ago)
Author:
yontege
Message:

More refactoring, now safer handling of rollback.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • confman/bash_completions

    r86 r87  
    11#!/bin/bash 
    22# 
    3 #       TODO 
     3#                                               TODO 
    44# 
    5 # More intelligently complete absolute paths in file/dir names 
    6 #       e.g. et_TAB completes to etc_ rather than etc _ 
    7 # 
     5#                       Can't think of any.             -yontege 
    86_confman()  
    97{ 
    108        local cur prev cmds twoback cmds fd_cmds mod_cmds chkpt_cmds 
     9 
     10        # Setup ConfMan specific vars 
    1111        CONFMAN="/usr/local/rescomp/sbin/confman" 
    1212        CONFMAN_CONF="/usr/local/rescomp/etc/confman.conf" 
     
    1717                RECIPE_PATH=$(grep '^RECIPE_PATH' ${CONFMAN_RC}|cut -d'"' -f2) 
    1818        fi 
     19 
     20        # Setup Standard command completion vars 
    1921        COMPREPLY=() 
    2022        cur="${COMP_WORDS[COMP_CWORD]}" 
     
    2830        [ ! -x $CONFMAN ] && echo "confman support not available!!" && exit 1 
    2931         
     32        # These vars are to better organize things to complete to as well as  
     33        # provide loose documention about what this does. 
    3034        # 
    3135        #       fd_cmds:        commands that take files and directories as args 
     
    3842        fd_cmds="rm cp mv mkdir ls chown chgrp chmod chcom log install revert" 
    3943        mod_cmds="create rmmod import checklook checknew checkclear rollback" 
    40         chkpt_cmds="checklook checknew checkclear rollback" 
    41         cmds="help setup update commit diff status $fd_cmds $mod_cmds" 
     44        # 'rollback' is also a chkpt_cmd, but needs to be handled separately 
     45        # because it's the only one that handles dated checkpoints. 
     46        chkpt_cmds="checklook checknew checkclear" 
     47        cmds="help setup update commit diff status rollback $fd_cmds $mod_cmds" 
    4248         
    4349        if [ "${prev}" == "confman" -o "${prev}" == "help" ] ; then 
     
    5965                COMPREPLY=($(compgen -W "${checkpoints}" -- ${cur})) 
    6066                return 0 
    61         elif [ `expr "rollback" : ".*\(${threeback}\).*"` ] ; then 
     67        elif [ "rollback" == "${twoback}" ] ; then 
     68                local module=${prev} 
     69                local named_checkpoints=$(confman checklook ${module}|\ 
     70                                                tr '\n' ' ') 
     71                local numbered_checkpoints=$(confman log |grep '^r[0-9][0-9]*' |\ 
     72                        sed 's/.*\(20[0-9][0-9]\)-\([0-9][0-9]\)-\([0-9][0-9]\).*/"\1\2\3"/'|\ 
     73                        tr '\n' ' ') 
     74                checkpoints="${named_checkpoints} ${numbered_checkpoints}" 
     75                COMPREPLY=($(compgen -W "${checkpoints}" -- ${cur})) 
     76                return 0 
     77        elif [ "rollback" == "${threeback}" ] ; then 
    6278                local day=${prev:0:4}-${prev:4:2}-${prev:6:2} 
    6379                local hoursmins=$(confman log |grep '^r[0-9][0-9]*' |\ 
     
    6783                COMPREPLY=($(compgen -W "${hoursmins}" -- ${cur})) 
    6884                return 0 
    69         elif [ `expr "rollback" : ".*\(${twoback}\).*"` ] ; then 
    70                 local module=${prev} 
    71                 local checkpoints=$(confman checklook ${module}|tr '\n' ' ') 
    72                 local num_checkpoints=$(confman log |grep '^r[0-9][0-9]*' |\ 
    73                         sed 's/.*\(20[0-9][0-9]\)-\([0-9][0-9]\)-\([0-9][0-9]\).*/"\1\2\3"/'|\ 
    74                         tr '\n' ' ') 
    75                 checkpoints="${checkpoints} ${num_checkpoints}" 
    76                 COMPREPLY=($(compgen -W "${checkpoints}" -- ${cur})) 
    77                 return 0 
    7885        fi 
    7986 
    8087        return 0 
    8188} 
     89 
     90# It's necessary to not define a catch-all completion above so that we  
     91# can use the '-o filenames' switch to best handle {file,dir}name 
     92# completions. 
    8293complete -F _confman -o filenames confman 
Note: See TracChangeset for help on using the changeset viewer.