Skip to content

Instantly share code, notes, and snippets.

@hchbaw
Created May 22, 2010 08:04
Show Gist options
  • Save hchbaw/409904 to your computer and use it in GitHub Desktop.
Save hchbaw/409904 to your computer and use it in GitHub Desktop.
#compdef clbuild
# TODO: clbuild-bash-completion.sh stuff (run/update/install/uninstall)
# Especially `update' found in this script is totally broken:)
_clbuild () {
local clbuild_dir=${clbuild_dir:=$(pwd)}
(( $+functions[__clbuild_commands] )) ||
__clbuild_commands () {
local -a commands
commands=(
'check:check availability of all necessary helper applications'
'list:[PATTERN] list all projects, or projects matching PATTERN'
# update [--dependencies|--no-dependencies] PROJECT_SPEC
# download/update this project
# update [--resume]
# download/update main projects. With --resume, consider
# only projects that a previous update run failed to fetch.
'update:[--dependencies|--no-dependencies] PROJECT_SPEC/[--resume]'
'skip:PROJECT_NAME mark this project as done for the purposes of update --resume'
'recompile:PROJECT_SPEC compile fasls'
'dumpcore:PROJECT_SPEC recompile and dump a core file for faster startup'
'diff:show local changes (for all version-controlled projects)'
'check-urls:compared installed repository urls agains current locations'
'clean-links:remove broken symlinks in systems/'
'rebuild-links:removes and adds .asd file symlinks for all projects'
'update-missing:download only projects not present yet'
'register-asd:PROJECT add .asd file symlinks for PROJECT'
'compile-implementation:sbcl [XC_HOST] compile SBCL'
'clean:[PROJECT] delete all compiled object files [in source/PROJECT]'
'trash:PROJECT move source/PROJECT to trash/'
'mrproper:trash all projects'
'slime:run the Superior Lisp Interaction Mode in a fresh Emacs'
'lisp:run Lisp in the terminal (using sbcl.core)'
'preloaded:run Lisp in the terminal (using monster.core)'
'slime-configuration:print .emacs excerpt for slime'
'make-project:NAME set up an new, empty project'
'record-dependencies:rebuild dependency information file'
)
_describe -t commands 'clbuild command' commands && return 0
}
(( $+functions[_clbuild-list] )) ||
_clbuild-list () {
local curcontext=$curcontext state line
typeset -A opt_args
_arguments ':pattern:' && ret=0
}
(( $+functions[_clbuild-update] )) ||
_clbuild-update () {
local curcontext=$curcontext state line
typeset -A opt_args
_arguments \
'--dependencies=-[download/update this project]' \
'--no-dependencies=-[download/update this project]' \
'--resume[only projects that a previous update run failed to fetch]' \
':project:__clbuild_projects' \
&& ret=0
}
(( $+functions[__clbuild_file_projects] )) ||
__clbuild_file_projects () {
local f="$1"
print ${(@)${${(@f)"$(<${f})"}:#\#*}%% *}
}
(( $+functions[__clbuild_projects] )) ||
__clbuild_projects () {
__clbuild_projects_1
__clbuild_project_groups
}
(( $+functions[__clbuild_projects_1] )) ||
__clbuild_projects_1 () {
local -a fs ps
fs=(projects wnpp-projects my-projects implementations)
for f in $fs; do
if [[ -f ${clbuild_dir}/$f ]]; then
ps=($ps $(__clbuild_file_projects "${clbuild_dir}/$f"))
fi
done
: ${(A)ps::=${(u)ps}}
local expl
_wanted projects expl project compadd $* - $ps
}
(( $+functions[__clbuild_project_groups] )) ||
__clbuild_project_groups () {
local expl
_wanted -V project-groups expl project-group compadd $* - \
--all-projects --main-projects --wnpp-projects --installed
}
(( $+functions[__clbuild_def_project_fn] )) ||
__clbuild_def_project_fn () {
local name="$1"
eval ${"$(<=(cat <<"EOT"
(( $+functions[$name] )) ||
$name () {
local curcontext=$curcontext state line
typeset -A opt_args
_arguments ':project:__clbuild_projects_1' && ret=0
}
EOT
))"//\$name/$name}
}
{
local fn
for fn in skip recompile dumpcore register-asd clean trash \
recompile show; do
__clbuild_def_project_fn _clbuild-$fn
done
}
local state line context ret=1 curcontext
typeset -A opt_args
_arguments -C \
'--help[display help messsage]' \
'--long-help[display help message]' \
'--implementation=-[specify lisp implementation]' \
'*::arg:->cmd_or_options' && ret=0
case $state in
(cmd_or_options)
if ((CURRENT == 1)); then
_call_function ret __clbuild_commands
else
(( $+functions[_clbuild-$words[1]] )) && {
curcontext="${curcontext%:*:*}:clbuild-$words[1]:"
_call_function ret _clbuild-$words[1]
}
fi
;;
esac
return ret
}
_clbuild
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment