Zsh Utilities Work
This is part of the Zsh Utilities.
Zsh Utilities - Work
This file contains some function/alias in relation with "work" topic.
pkgtools aliases obsolete
pkgtools
is used as wrapper for installation. It is a bash program which wraps
cmake
or some Makefile
and is intensively used with SuperNEMO software.
alias pkg-notify='notify -t 2000 -i stock_dialog-info "pkgtools"' function pkgc () { ./pkgtools.d/pkgtool configure $@ && pkg-notify "Configure done" } function pkgb () { ./pkgtools.d/pkgtool build && pkg-notify "Build done" } function pkgt () { ./pkgtools.d/pkgtool test && pkg-notify "Running test programs done" } function pkgr () { ./pkgtools.d/pkgtool reset && pkg-notify "Reset done" } function pkgi () { ./pkgtools.d/pkgtool install && pkg-notify "Install done" }
ROOT aliases
alias root='root -l'
SN@ilWare setup
Environment variable
export SNAILWARE_SIMULATION_DIR=$WORKDIR/supernemo/simulations
Setup
alias do_nemo_setup='aggregator setup cadfael' alias do_aggregator_setup='aggregator setup all && mkdir -p /tmp/${USER}/snemo.d'
Working configuration
Legacy configuration load the legacy
svn branch to work with a full software
installation. Bayeux components are ordered by dependency and since there is a
change wrt to geomtools
vs. materials
dependency as well as genbb_help
depending on dpp
for programs, we have to set the full list of Bayeux
components.
alias build_snailware_legacy='do_nemo_setup && \ snailware git-branch --branch legacy datatools mygsl geomtools materials brio cuts genbb_help genvtx trackfit emfield && \ snailware git-branch --branch legacy sngeometry sncore sngenvertex sngenbb sng4 snreconstruction snvisualization snanalysis && \ snrebuild --no-ninja datatools mygsl geomtools materials brio cuts genbb_help genvtx trackfit emfield && \ snrebuild channel && snailware setup channel && \ snrebuild sngeometry sncore sngenvertex sngenbb sng4 snreconstruction snvisualization snanalysis' alias build_snailware_master='do_nemo_setup && \ snailware git-branch --branch master bayeux sngeometry sncore snreconstruction snvisualization && \ snailware git-branch --branch xg_devel snanalysis && \ snrebuild bayeux channel && \ snailware setup channel && \ snrebuild falaise'
dpp_processing
shortcuts
function do_snemo_chain () { __pkgtools__at_function_enter do_snemo_chain if [ -z $1 ]; then pkgtools__msg_error "Missing module name !" __pkgtools__at_function_exit return 1 fi if $(pkgtools__has_binary bxdpp_processing); then cm bxdpp_processing -m $1 -c $SNAILWARE_SIMULATION_DIR/snemo_simulation_configuration/master/module_manager.conf \ --dlls-config $SNAILWARE_SIMULATION_DIR/snemo_simulation_configuration/master/dlls.conf \ --datatools::resource_path=falaise@$SNAILWARE_PRO_DIR/falaise/install/share/Falaise-1.0.0/resources \ -M 100 --modulo 1 -P notice else pkgtools__msg_error "SN@ilWare has not been set" __pkgtools__at_function_exit return 1 fi __pkgtools__at_function_exit return 0 }
Aliases
if (( $+functions[cm] )); then function snemo_event_browser () { cm $(pkgtools__get_binary_path snemo_event_browser) $@ } function bxdpp_processing () { cm $(pkgtools__get_binary_path bxdpp_processing) $@ } fi # compdef _snemo_event_browser snemo_toto
Lyon ccali aliases
if [[ $HOSTNAME = ccage* ]]; then alias qjob_nemo_user='echo "Number of jobs run by NEMO users"; qstat -u \* -ext -s r| tail -n+3 | grep nemo | awk "{print \$5}" | sort | uniq -c' alias qjob_my_total='echo -ne "Total number of jobs: ";qstat | tail -n+3 | wc -l' alias qjob_my_run='echo -ne "Number of running jobs: ";qstat -s r | tail -n+3 | wc -l' alias qjob_summary='qjob_my_total; qjob_my_run; qjob_nemo_user' fi
Activate g++ warnings
function activate_cxxflags () { __pkgtools__at_function_enter activate_cxxflags export CXXFLAGS="-Waddress -Warray-bounds -Wc++11-compat -Wchar-subscripts \ -Wenum-compare -Wcomment -Wformat -Wmain -Wmaybe-uninitialized -Wmissing-braces \ -Wnonnull -Wparentheses -Wreorder -Wreturn-type -Wsequence-point -Wsign-compare \ -Wstrict-aliasing -Wstrict-overflow=1 -Wswitch -Wtrigraphs -Wuninitialized \ -Wunknown-pragmas -Wunused-function -Wunused-label -Wunused-value \ -Wunused-variable -Wvolatile-register-var -Wclobbered -Wempty-body \ -Wignored-qualifiers -Wmissing-field-initializers -Wsign-compare -Wtype-limits \ -Wuninitialized -Wunused-parameter -Wunused-but-set-parameter" __pkgtools__at_function_exit return 0 }
Generate org doc skeletons
Main function
- Parsing options
function make_org_doc () { __pkgtools__default_values __pkgtools__at_function_enter make_org_doc # Internal functions --mod::usage () { } local append_list_of_options local append_list_of_arguments local type local title local author="Xavier Garrido" local email="xavier.garrido@lal.in2p3.fr" local latex_class local latex_class_options local base_directory while [ -n "$1" ]; do local token=$1 if [ "${token[0,1]}" = "-" ]; then local opt=${token} append_list_of_options+="${opt} " if [ "${opt}" = "-h" -o "${opt}" = "--help" ]; then --mod::usage return 0 elif [ "${opt}" = "-d" -o "${opt}" = "--debug" ]; then pkgtools__msg_using_debug elif [ "${opt}" = "-D" -o "${opt}" = "--devel" ]; then pkgtools__msg_using_devel elif [ "${opt}" = "-v" -o "${opt}" = "--verbose" ]; then pkgtools__msg_using_verbose elif [ "${opt}" = "-W" -o "${opt}" = "--no-warning" ]; then pkgtools__msg_not_using_warning elif [ "${opt}" = "-q" -o "${opt}" = "--quiet" ]; then pkgtools__msg_using_quiet export PKGTOOLS_MSG_QUIET=1 elif [ "${opt}" = "-i" -o "${opt}" = "--interactive" ]; then pkgtools__ui_interactive elif [ "${opt}" = "-b" -o "${opt}" = "--batch" ]; then pkgtools__ui_batch elif [ "${opt}" = "--gui" ]; then pkgtools__ui_using_gui elif [ "${opt}" = "--doc-type" ]; then shift 1; type="$1" elif [ "${opt}" = "--title" ]; then shift 1; title="$1" elif [ "${opt}" = "--author" ]; then shift 1; author="$1" elif [ "${opt}" = "--email" ]; then shift 1; email="$1" elif [ "${opt}" = "--latex-class" ]; then shift 1; latex_class="$1" elif [ "${opt}" = "--latex-class-options" ]; then shift 1; latex_class_options="$1" elif [ "${opt}" = "--base-directory" ]; then shift 1; base_directory="$1" fi else arg=${token} if [ "x${arg}" != "x" ]; then append_list_of_arguments+="${arg} " fi fi shift 1 done
- Parsing options
local dirname="$(echo ${append_list_of_arguments} | awk '{print $1}')" if [ "${dirname}" = "" ]; then pkgtools__msg_error "You must give a repository name !" __pkgtools__at_function_exit return 1 fi if [ ! -n "$type" ]; then pkgtools__msg_error "Missing type of documents !" __pkgtools__at_function_exit return 1 fi case $type in (talk) test ! -n "$base_directory" && base_directory=~/Workdir/Talk test ! -n "$latex_class" && latex_class="beamer" test ! -n "$latex_class_options" && latex_class_options="snemo,nologo" ;; (note) ;; (article) test ! -n "$base_directory" && base_directory=~/Workdir/Papers/pub/nemo-note test ! -n "$latex_class" && latex_class="snemo-article" test ! -n "$latex_class_options" && latex_class_options="" ;; esac pkgtools__msg_devel "base_directory=${base_directory}" pkgtools__msg_devel "latex_class=${latex_class}" pkgtools__msg_devel "latex_class_options=${latex_class_options}" # Remove last space append_list_of_arguments=${append_list_of_arguments%?} append_list_of_options=${append_list_of_options%?} pkgtools__msg_devel "append_list_of_arguments=${append_list_of_arguments}" pkgtools__msg_devel "append_list_of_options=${append_list_of_options}"
- Internal functions
- Create directories
local directory=${base_directory}/${dirname} --mod::create_directories () { mkdir -p ${directory}/{pdf,figures} }
- Generate org skeleton
--mod::generate_org_skeleton () { local org_file case $type in (talk) org_file=${directory}/talk.org ;; (article) org_file=${directory}/note-$(date +%y%m%d).org ;; esac echo "#+TITLE: ${title}" > ${org_file} echo "#+AUTHOR: ${author}" >> ${org_file} echo "#+EMAIL: ${email}" >> ${org_file} echo "#+DATE: $(date +%d/%m/%Y)" >> ${org_file} case $type in (talk) echo "#+OPTIONS: toc:nil num:nil author:nil email:t ^:{}" >> ${org_file} echo "#+STARTUP: beamer" >> ${org_file} ;; (article) echo "#+OPTIONS: toc:nil date:nil author:nil email:t ^:{}" >> ${org_file} echo "#+STARTUP: entitiespretty" >> ${org_file} ;; esac echo "#+LATEX_CLASS: ${latex_class}" >> ${org_file} echo "#+LATEX_CLASS_OPTIONS: [${latex_class_options}]" >> ${org_file} echo "" >> ${org_file} # Special setup for article case $type in (article) begin="#+BEGIN" end="#+END" echo "* Abstract ::" >> ${org_file} echo "${begin}_ABSTRACT" >> ${org_file} echo "${end}_ABSTRACT" >> ${org_file} echo "* Introduction ::" >> ${org_file} echo "* Conclusion ::" >> ${org_file} echo "* References ::" >> ${org_file} echo "${begin}_BIBLIOGRAPHY" >> ${org_file} echo "${end}_BIBLIOGRAPHY" >> ${org_file} ;; esac }
- Generate
makefile
--mod::generate_makefile () { local make_file=${directory}/Makefile case $type in (talk) echo "# -*- mode: makefile; -*-" > ${make_file} echo "EMACS=emacs" >> ${make_file} echo "BATCH=\$(EMACS) --batch --eval '(setq starter-kit-dir \"~/.emacs.d\")' \ --load '~/.emacs.d/starter-kit-org.el'" >> ${make_file} echo "files_org = \$(wildcard *.org)" >> ${make_file} echo "files_pdf = \$(files_org:.org=.png)" >> ${make_file} echo >> ${make_file} echo "all: \$(files_pdf)" >> ${make_file} echo >> ${make_file} echo "%.png: %.org" >> ${make_file} echo "\t@echo \"NOTICE: Exporting \$< to pdf...\";" >> ${make_file} echo "\t@\$(BATCH) --visit \"\$<\" --funcall org-beamer-export-to-pdf" >> ${make_file} echo "\t@cp \$@ pdf/\${@:.png=_${dirname}.png}" >> ${make_file} echo >> ${make_file} echo "clean:" >> ${make_file} echo "\t@rm -rf latex.d *.tex *.png *.fdb* *~ " >> ${make_file} echo "\t@rm -rf *.out *.fls *.toc *.aux *.snm *.nav *.log" >> ${make_file} ;; (article) echo "# -*- mode: makefile; -*-" > ${make_file} echo "EMACS=emacs" >> ${make_file} echo "BATCH=\$(EMACS) --batch --eval '(setq starter-kit-dir \"~/.emacs.d\")' \ --load '~/.emacs.d/starter-kit-org.el'" >> ${make_file} echo "files_org = \$(wildcard note*.org)" >> ${make_file} echo "files_pdf = doc/pdf/\$(files_org:.org=.png)" >> ${make_file} echo "files_html = doc/html/\$(files_org:.org=.html)" >> ${make_file} echo >> ${make_file} echo "all: pdf" >> ${make_file} echo >> ${make_file} echo "pdf: \$(files_pdf)" >> ${make_file} echo "doc/pdf/%.png: %.org" >> ${make_file} echo "\t@echo \"NOTICE: Exporting $< to pdf...\"" >> ${make_file} echo "\t@zsh -i -c \"org-pages --pdf --debug generate\"" >> ${make_file} echo >> ${make_file} echo "html: \$(files_html)" >> ${make_file} echo "doc/html/%.html: %.org" >> ${make_file} echo "\t@echo \"NOTICE: Exporting $< to html...\"" >> ${make_file} echo "\t@zsh -i -c \"org-pages --html --debug generate\"" >> ${make_file} echo >> ${make_file} echo "clean:" >> ${make_file} echo "\t@rm -rf latex.d doc *.tex *.png *.toc *.fdb* *~ README.el" >> ${make_file} echo >> ${make_file} echo ".PHONY: all pdf html clean" >> ${make_file} ;; esac }
- Generate
.gitignore
--mod::generate_gitignore () { local gitignore=${directory}/.gitignore echo "/*.png" >> ${gitignore} echo "/*.tex" >> ${gitignore} echo "/*.auxlock" >> ${gitignore} echo "/*.vrb" >> ${gitignore} echo "/*.fdb_latexmk" >> ${gitignore} echo "/*.fls" >> ${gitignore} echo "/*.aux" >> ${gitignore} echo "*~" >> ${gitignore} echo "latex.d/" >> ${gitignore} }
- Import function
--mod::import_doc () { ( local svn_directory case $type in (talk) svn_directory=https://svn.lal.in2p3.fr/users/garrido/Talk ;; (article) svn_directory=https://svn.lal.in2p3.fr/users/garrido/Publications/nemo-note ;; esac if [ -d ${directory}/.git ]; then pkgtools__msg_warning "Directory '${directory}' is already under git-svn !" return 0 fi svn mkdir ${svn_directory}/${dirname} -m "create ${dirname} directory" svn import ${directory} ${svn_directory}/${dirname} -m "import trunk directory" rm -rf ${base_directory}/${dirname} mkdir -p ${base_directory}/${dirname} cd ${base_directory}/${dirname} git svn init --prefix=svn/ --trunk=. ${svn_directory}/${dirname} git svn fetch ) }
- Create directories
- Calling functions
--mod::create_directories --mod::generate_org_skeleton --mod::generate_makefile --mod::generate_gitignore --mod::import_doc # Finally goto the directory cd ${base_directory}/${dirname} unset title author email latex_class latex_class_options unset dirname directory base svn_directory org_file unset append_list_of_arguments append_list_of_options unfunction -- --mod::usage unfunction -- --mod::import_doc unfunction -- --mod::generate_gitignore unfunction -- --mod::generate_makefile unfunction -- --mod::generate_org_skeleton unfunction -- --mod::create_directories __pkgtools__at_function_exit return 0 }
Completion function
# Connect completion system compdef _make_org_doc make_org_doc _make_org_doc () { _arguments -C \ '(-h --help)'{-h,--help}'[print help message]' \ '(-v --verbose)'{-v,--verbose}'[produce verbose logging]' \ '(-d --debug)'{-d,--debug}'[produce debug logging]' \ '(-D --devel)'{-D,--devel}'[produce devel logging]' \ --doc-type'[set document type]:type:->type' \ --title'[set talk title]' \ --author'[set author name]' \ --email'[set email]' \ --latex-class'[set LaTeX class name]:class:->class' \ --latex-class-options'[set LaTeX class options]:class-options:->class-options' \ --base-directory'[directory to put document]' \ '*: :->args' && ret=0 case $state in (type) local types; types=('talk' 'article' 'note') _describe -t 'types' 'type' types && ret=0 ;; (class) local classes; classes=('beamer') _describe -t 'classes' 'class' classes && ret=0 ;; (class-options) local class_options; class_options=( 'snemo' 'cpp_teaching' 'ddpfo' 'nologo' 'notitlelogo' 'noheaderlogo' ) _describe -t 'class-options' 'option' class_options && ret=0 ;; (args) local dirname; dirname=($(date +%y%m%d)_) _describe -t 'dirname' 'dirname' dirname && ret=0 ;; esac }
Parse C++ program options
This function parse the content of a C++ program and extract command line options passed with boost::program_options
function parse_cpp_program_options () { __pkgtools__at_function_enter parse_cpp_program_options # Internal function to stream 'echo' command __parse () { local find_begin_description=0 local find_end_description=1 local data_type="" for token in $(sed -n '/add_options/,/;/p' $1) do if [[ "$token" == *';'* ]]; then break fi token=${token/\\n/ } pkgtools__msg_devel "token = ${token}" if [[ "$token" == *'"'* ]]; then # Get option indentificator if [[ "$token" == *'("'* ]]; then if [[ "$token" == *'")'* ]]; then continue fi if [ ${find_end_description} -eq 0 ]; then data_type="" find_end_description=1 find_begin_description=0 echo "]' \\" fi local tmp=$(echo ${token%?} | sed 's/[("\]//g') local opt1=$(echo $tmp | cut -d',' -f1) local opt2=$(echo $tmp | cut -d',' -f2) if [ ${#opt1} = ${#opt2} ]; then test ${#opt1} -gt 1 && echo -ne "--${opt1}" elif [ ${#opt1} -gt ${#opt2} ]; then echo -ne "{-${opt2},--${opt1}}" else echo -ne "{-${opt1},--${opt2}}" fi elif [[ "$token" == *'")'* ]]; then token=$(echo ${token} | sed 's/[."]//g') if [ ${find_begin_description} -eq 1 ]; then data_type="" find_end_description=1 find_begin_description=0 echo "${token%)}${data_type}]' \\" fi else token=$(echo ${token} | sed 's/["\\]//g') if [ ${find_end_description} -eq 1 ]; then find_end_description=0 find_begin_description=1 echo -ne "'[${token#\"} " else echo -ne "${token} " fi fi elif [[ "$token" != *'->'* ]]; then if [[ ${find_begin_description} -eq 1 && ${find_end_description} -eq 0 ]]; then if [ "$token" != ")" ]; then token=$(echo ${token} | sed 's/[;"\\]//g') echo -ne "${token} " fi # elif [[ "${token}" == *"::value<"* ]]; then # tmp=${token##*value<} # tmp=${tmp%%>*} # if [ "${tmp}" == "bool" ];then # data_type=":boolean:(true false)" # elif [ "${tmp}" == "int" ]; then # data_type=":number" # elif [ "${tmp}" == "double" ]; then # data_type=":number" # fi fi fi done if [ ${find_end_description} -eq 0 ]; then echo "]' \\" fi unset token unset find_begin_description find_end_description unset data_type } for program_file in $1 do local program_name=$(basename ${program_file%.cxx}) local completion_file=/tmp/_${program_name} cat ${program_file} | grep -q add_options if [ $? -ne 0 ]; then pkgtools__msg_warning "Program ${program_name} does not use boost::program_option ! Skip it !" continue else pkgtools__msg_notice "Build completion system for program ${program_name}" fi __header () { echo "#compdef ${program_name}" echo echo "function _${program_name} ()" echo "{" echo "typeset -A opt_args" echo "local context state line curcontext=\"$curcontext\"" echo echo " _arguments \\" } __header > ${completion_file} __parse ${program_file} >> ${completion_file} __footer () { echo "'*: :->args' \\" echo "&& ret=0" echo echo "case \$state in" echo "args)" echo "_files -/" echo ";;" echo "esac" echo echo "return ret" echo "}" echo echo "_${program_name} \"\$@\"" echo echo "# Local Variables:" echo "# mode: Shell-Script" echo "# sh-indentation: 2" echo "# indent-tabs-mode: nil" echo "# sh-basic-offset: 2" echo "# End:" } __footer >> ${completion_file} pkgtools__msg_notice "File has been parsed in ${completion_file} file" done __pkgtools__at_function_exit return 0 } compdef '_files -g "*.cxx"' parse_cpp_program_options
Completion system
compdef _dpp_processing bxdpp_processing compdef _genbb_inspector bxgenbb_inspector