From da1b53707a33a808615acc6371e2256c61f23eb5 Mon Sep 17 00:00:00 2001 From: Sam Tobin-Hochstadt Date: Fri, 16 Apr 2010 16:40:47 -0400 Subject: [PATCH] add bash completion script --- collects/meta/contrib/racket_completion | 95 +++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 collects/meta/contrib/racket_completion diff --git a/collects/meta/contrib/racket_completion b/collects/meta/contrib/racket_completion new file mode 100644 index 0000000000..58dee8e04b --- /dev/null +++ b/collects/meta/contrib/racket_completion @@ -0,0 +1,95 @@ +# -*- mode: shell-script; sh-basic-offset: 2; indent-tabs-mode: nil -*- +# ex: ts=2 sw=2 noet filetype=sh + +_racket() +{ + local cur prev singleopts doubleopts + COMPREPLY=() + cur=`_get_cword` + prev="${COMP_WORDS[COMP_CWORD-1]}" + #prev2="${COMP_WORDS[COMP_CWORD-2]}" + doubleopts="--help --version --eval --load --require --lib --script --require-script\ + --main --repl --no-lib --version --warn --syslog --collects --search --addon --no-compiled --no-init-file" + singleopts="-h -e -f -t -l -p -r -u -k -m -i -n -v -W -L -X -S -A -I -U -N -j -d -b -c -q" + warnlevels="none fatal error warning info debug" + + # if '--' is already given, complete all kind of files, but no options + for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do + if [[ ${COMP_WORDS[i]} == -- ]]; then + _filedir + return 0 + fi + done + + + case "${cur}" in + --*) + COMPREPLY=( $(compgen -W "${doubleopts}" -- ${cur}) ) + ;; + -*) + COMPREPLY=( $(compgen -W "${singleopts}" -- ${cur}) ) + ;; + *) + case "${prev}" in + # these do not take paths as options + --help|-h|-e|--eval|-p|-k) + ;; + # these take dirs (not files) as options + -X|-S|-A|--collects|--search|--addon) + _filedir '-d' + ;; + -W|--warn|-L|--syslog) + COMPREPLY=( $(compgen -W "${warnlevels}" -- ${cur}) ) + ;; + *) + _filedir #'@(rkt|ss|scm|scrbl)' + ;; + esac + ;; + esac + + return 0 +} +complete -F _racket $filenames racket + +_rico() +{ + local cur prev opts base + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + + # + # The basic commands we'll complete. + # + opts="make setup planet exe pack c-ext decompile distribute expand --help docs" + local makeopts="--disable-inline --no-deps -p --prefix --no-prim -v -vv --help -h" + + # + # Complete the arguments to some of the basic commands. + # + if [ $COMP_CWORD -eq 1 ]; then + COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + else + case "${prev}" in + make) + case "${cur}" in + -*) + COMPREPLY=( $(compgen -W "${makeopts}" -- ${cur}) ) + ;; + *) + _filedir + ;; + esac + ;; + --help) + ;; + *) + _filedir + ;; + esac + fi + return 0 +} + +complete -F _rico rico