Crombie Tools
crombie_completion.sh
Go to the documentation of this file.
1 ##
2 # @file crombie_completion.sh
3 #
4 # Sets the auto-complete available for people using the
5 # crombie command line tools
6 #
7 # @author Daniel Abercrombie <dabercro@mit.edu>
8 #
9 
10 dir=$CROMBIEPATH/scripts # First get the directory of all the executable scripts
11 files=($dir/*.[p,s]? $dir/*.R) # Get the list of files in the first level of this directory
12 
13 subcommands=() # Initialize list of crombie subcommands
14 
15 for f in ${files[@]} # For each file, create a subcommand that is just the basename
16 do # of the script with no extension
17  f=$(basename $f)
18  if [ "${f%%.*}" != "README" -a "${f%%.*}" != "noauto" ]
19  then
20  subcommands+="${f%%.*} "
21  fi
22 done
23 
24 _crombie_subs () { # Function to fill COMPREPLY, depending on the command line content
25 
26  cur=${COMP_WORDS[COMP_CWORD]} # Get the current word
27  prev=${COMP_WORDS[$((COMP_CWORD-1))]} # Get the previous word
28 
29  if [ "$prev" = "crombie" ] # If completing after "crombie", return the subcommands
30  then
31 
32  COMPREPLY=( $(compgen -W "${subcommands[@]}" $cur ) )
33 
34  elif [ "$prev" = "submitlxbatch" ] # Return the subcommands of "crombie submitlxbatch"
35  then
36 
37  COMPREPLY=( $(compgen -W "hadd test resub fresh" $cur ) )
38 
39  elif [ "$prev" = "submitcondor" ] # Return the subcommands of "crombie submitcondor"
40  then
41 
42  COMPREPLY=( $(compgen -W "test fresh" $cur ) )
43 
44  elif [ "$prev" = "terminalslim" ] # Return the subcommands of "crombie terminalslim"
45  then
46 
47  COMPREPLY=( $(compgen -W "hadd resub fresh" $cur ) )
48 
49  elif [ "$prev" = "presentation" ] # "crombie presentation" usually defaults to current date
50  then # so just return that
51 
52  COMPREPLY=( $(compgen -W `date +%y%m%d` $cur ) )
53 
54  elif [ "$prev" = "backupslides" ] # "crombie backupslides" has an "all" option to have all figures
55  then # so just return that
56 
57  COMPREPLY=( $(compgen -W "all" $cur ) )
58 
59  elif [ "$prev" = "workspace" ] # "crombie workspace" can only be varied with a test
60  then
61 
62  COMPREPLY=( $(compgen -W "test" $cur ) )
63 
64  elif [ "$prev" = "test" -a $COMP_CWORD -eq 2 ] # "crombie test" has a fast version
65  then
66 
67  COMPREPLY=( $(compgen -W "fast" $cur ) )
68 
69  elif [ "$prev" = "generatedocs" ] # "crombie generatedocs" can be a test or copy
70  then
71 
72  COMPREPLY=( $(compgen -W "copy test" $cur ) )
73 
74  elif [ "$prev" = "addxs" ] # "crombie addxs" can skip files commented in config
75  then
76 
77  COMPREPLY=( $(compgen -W "skip" $cur ) )
78 
79  elif [ "${COMP_WORDS[1]}" = "generatedocs" ] # "crombie generatedocs copy" can go to different places
80  then
81 
82  if [ "$prev" = "copy" ]
83  then
84  COMPREPLY=( $(compgen -W "athena lxplus" $cur ) )
85  else
86  COMPREPLY=()
87  fi
88 
89  elif [ "${COMP_WORDS[1]}" = "compile" ] # If "crombie compile" are the first two words,
90  then # user can give an array of Crombie objects
91 
92  fullobjects=($CROMBIEPATH/old/*/src/*.cc) # Get the list of loadable objects
93  objects=() # Initialize fill list
94 
95  for obj in ${fullobjects[@]}
96  do
97  withext="$( basename $obj )" # Get basename and strip extenstions
98  objects+="${withext%%.*} " # to return the COMPREPLY
99  done
100 
101  COMPREPLY=( $(compgen -W "${objects[@]}" $cur ) )
102 
103  else # If nothing else, just return the defaults from bash
104 
105  COMPREPLY=()
106 
107  fi
108 
109  return 0
110 
111 }
112 
113 complete -o bashdefault -o default -F _crombie_subs crombie # Call the previous function for "crombie" commands