10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-09-27 03:51:01 +02:00
quantum_package/etc/qp.rc

295 lines
6.6 KiB
Plaintext
Raw Normal View History

2019-01-09 11:31:59 +01:00
# Configuration of the qp shell command
2019-01-09 02:44:30 +01:00
if [[ "$(ps -p $$ -ocomm=)" == "zsh" ]] ; then
autoload bashcompinit
bashcompinit
fi
source ${QP_ROOT}/etc/ezfio.rc
function _qp_usage()
{
echo "
Usage:
qp set_file EZFIO_DIRECTORY
qp unset_file
qp has DIRECTORY ITEM
qp get DIRECTORY ITEM
qp set DIRECTORY ITEM VALUE : Scalar values
qp set DIRECTORY ITEM : Array values read from stdin
qp run PROGRAM
2019-01-14 22:37:24 +01:00
qp man PROGRAM
2019-01-09 02:44:30 +01:00
qp srun PROGRAM
qp mpirun PROGRAM
qp set_frozen_core
2019-01-14 22:37:24 +01:00
qp create_ezfio_from_xyz
qp convert_output_to_ezfio
qp update
qp set_mo_class
qp plugins
2019-01-09 02:44:30 +01:00
"
}
2019-01-11 19:10:12 +01:00
2019-01-09 02:44:30 +01:00
function qp()
{
case $1 in
"has"|"set"|"get"|"set_file"|"unset_file")
2019-01-12 15:17:11 +01:00
ezfio "$@"
2019-01-09 02:44:30 +01:00
;;
"set_frozen_core")
shift
2019-01-12 15:17:11 +01:00
qp_set_frozen_core "$@" ${EZFIO_FILE}
2019-01-09 02:44:30 +01:00
;;
"create_ezfio_from_xyz")
shift
2019-01-14 22:37:24 +01:00
# Replace ':' by spaces
for arg in $@ ; do
2019-01-15 00:41:39 +01:00
case $arg in
-*)
_ARGS+=("${arg}") ;;
*)
_ARGS+=("\"${arg//:/ }\"") ;;
esac
2019-01-14 22:37:24 +01:00
done
2019-01-15 00:41:39 +01:00
NAME=$(eval "qp_create_ezfio_from_xyz ${_ARGS[@]}")
2019-01-09 13:59:24 +01:00
if [[ -d $NAME ]] ; then
2019-01-11 19:10:12 +01:00
[[ -d $EZFIO_FILE ]] && ezfio unset_file
2019-01-09 13:59:24 +01:00
ezfio set_file $NAME
else
2019-01-15 00:43:33 +01:00
qp_create_ezfio_from_xyz -h | more
2019-01-09 13:59:24 +01:00
fi
2019-01-14 22:37:24 +01:00
unset _ARGS
2019-01-09 02:44:30 +01:00
;;
2019-01-12 15:17:11 +01:00
"convert_output_to_ezfio")
shift
qp_convert_output_to_ezfio "$@"
;;
2019-01-09 02:44:30 +01:00
"set_mo_class")
shift
2019-01-12 15:17:11 +01:00
qp_set_mo_class "$@" -- ${EZFIO_FILE}
2019-01-09 02:44:30 +01:00
;;
"edit")
shift
2019-01-12 15:17:11 +01:00
qp_edit "$@" -- ${EZFIO_FILE}
2019-01-09 02:44:30 +01:00
;;
"run")
shift
2019-01-12 15:17:11 +01:00
qp_run "$@" -- ${EZFIO_FILE}
2019-01-09 02:44:30 +01:00
;;
"srun")
shift
2019-01-12 15:17:11 +01:00
qp_srun "$@" ${EZFIO_FILE}
2019-01-09 02:44:30 +01:00
;;
"mpirun")
shift
2019-01-12 15:17:11 +01:00
qp_mpirun "$@" ${EZFIO_FILE}
2019-01-09 02:44:30 +01:00
;;
2019-01-11 19:10:12 +01:00
"man")
shift
man $QP_ROOT/man/${1}.?
;;
2019-01-13 00:02:22 +01:00
"prompt")
shift
function _check_ezfio() {
if [[ -d ${EZFIO_FILE} ]] ; then
printf "\e[0;32m|${EZFIO_FILE}>\e[m"
else
printf "\e[0;31m|${EZFIO_FILE}>\e[m"
fi
}
2019-01-13 13:47:05 +01:00
PS1="\$(_check_ezfio)\n$PS1"
2019-01-13 00:02:22 +01:00
;;
2019-01-14 22:37:24 +01:00
"plugins")
shift
qp_plugins $@
;;
"update")
shift
qp_update $@
;;
2019-01-09 02:44:30 +01:00
*)
_qp_usage
;;
esac
}
2019-01-14 22:37:24 +01:00
function _get_basis_sets () {
( qp_create_ezfio_from_xyz -b show \
| tr ' ' ':' \
| while IFS= read -r LINE ; do
printf '%s\n' ${LINE}
done
(cd ~/quantum_package/data/basis/ ; \ls)
) | sort | uniq
}
2019-01-15 00:41:39 +01:00
_qp_Complete()
2019-01-09 02:44:30 +01:00
{
local cur
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
2019-01-14 22:37:24 +01:00
first="${COMP_WORDS[1]}"
2019-01-09 02:44:30 +01:00
prev="${COMP_WORDS[COMP_CWORD-1]}"
prev2="${COMP_WORDS[COMP_CWORD-2]}"
2019-01-14 22:37:24 +01:00
case "${first}" in
update)
COMPREPLY=( $(compgen -W "-h" -- $cur ) )
return 0
;;
man)
COMPREPLY=( $(compgen -W "$(cd ${QP_ROOT}/man ; \ls | sed 's/\.1//')" -- $cur ) )
return 0
;;
convert_output_to_ezfio)
COMPREPLY=( $(compgen -W "-o $(\ls)" -- ${cur} ) )
return 0
;;
create_ezfio_from_xyz)
case "${prev}" in
create_ezfio_from_xyz)
COMPREPLY=( $(compgen -W "-b -a -c -d -h -m -o -p -x" -- $cur ) )
return 0
;;
-m|-d|-c)
COMPREPLY=( $(compgen -W "" -- $cur ) )
return 0;;
-b)
for iter in $(_get_basis_sets); do
if [[ $iter =~ ^$cur ]]; then
COMPREPLY+=( "${iter}" )
fi
done;
return 0
;;
-p)
COMPREPLY=( $(compgen -W "$(cd ~/quantum_package/data/pseudo ; \ls)" -- $cur ) )
return 0
;;
*)
COMPREPLY=( $(compgen -W "-b -a -c -d -h -m -o -p -x $(\ls)" -- $cur ) )
return 0
;;
esac;;
plugins)
case "${prev}" in
plugins)
COMPREPLY=( $(compgen -W "list download install uninstall create" -- $cur ) )
return 0
;;
list)
COMPREPLY=( $(compgen -W "-i -u -q" -- $cur ) )
return 0;;
download)
COMPREPLY=( $(compgen -W "http:// git@github.com: git@gitlab.com: " -- $cur ) )
return 0;;
install)
COMPREPLY=( $(compgen -W "$(qp_plugins list -u)" -- $cur ) )
return 0;;
uninstall)
COMPREPLY=( $(compgen -W "$(qp_plugins list -i)" -- $cur ) )
return 0;;
create)
COMPREPLY=( $(compgen -W "-n " -- $cur ) )
return 0;;
*)
COMPREPLY=( $(compgen -W "$( \ls ; cd ~/quantum_package/src ; \ls )" -- $cur ) )
return 0
;;
esac;;
*)
COMPREPLY=( $(compgen -W 'plugins \
man \
create_ezfio_from_xyz \
convert_output_to_ezfio \
-h update' -- $cur ) )
esac
2019-01-09 02:44:30 +01:00
if [[ -n ${EZFIO_FILE} && -d ${EZFIO_FILE} ]]
then
case "${prev2}" in
"set"|has|get)
if [[ ${prev} == "qp" ]] ; then
2019-01-14 22:37:24 +01:00
COMPREPLY=( $(compgen -W "plugins set set_frozen_core set_mo_class" -- $cur ) )
2019-01-09 02:44:30 +01:00
elif [[ ! -d ${EZFIO_FILE}/${prev} ]] ; then
COMPREPLY=( $(compgen -W "" -- $cur ) )
else
2019-01-14 22:37:24 +01:00
COMPREPLY=( $(compgen -W "$(cd ${EZFIO_FILE}/${prev} ; \ls | sed 's/\.gz//' )" -- $cur ) )
2019-01-09 02:44:30 +01:00
fi
return 0
;;
esac
2019-01-14 22:37:24 +01:00
case "${first}" in
2019-01-09 02:44:30 +01:00
run|srun|mpirun)
2019-01-14 22:37:24 +01:00
COMPREPLY=( $(compgen -W "-h $(cat ${QP_ROOT}/data/executables | cut -d ' ' -f 1)" -- $cur ) )
2019-01-09 02:44:30 +01:00
return 0
;;
2019-01-14 22:37:24 +01:00
unset_file|set_frozen_core)
2019-01-09 02:44:30 +01:00
COMPREPLY=()
return 0
;;
set_mo_class)
2019-01-14 22:37:24 +01:00
COMPREPLY=( $(compgen -W "-h -c -i -a -v -d -q" -- $cur ) )
2019-01-11 19:10:12 +01:00
return 0
;;
2019-01-09 02:44:30 +01:00
set|has|get)
2019-01-15 00:41:39 +01:00
COMPREPLY=( $(compgen -d "$(cd ${EZFIO_FILE} ; \ls -d */ | sed 's|/||g')" -- $cur ) )
2019-01-09 02:44:30 +01:00
return 0
;;
2019-01-14 22:37:24 +01:00
edit)
COMPREPLY=( $(compgen -W "-h -c -n -s" -- $cur ) )
return 0
;;
2019-01-09 02:44:30 +01:00
*)
2019-01-14 22:37:24 +01:00
COMPREPLY+=( $(compgen -W 'has get set unset_file edit \
2019-01-09 02:44:30 +01:00
run srun mpirun set_frozen_core \
2019-01-14 22:37:24 +01:00
set_mo_class ' \
-- $cur ) )
2019-01-09 02:44:30 +01:00
return 0
;;
esac
else
case "${prev}" in
set_file)
2019-01-15 00:41:39 +01:00
COMPREPLY=( $(compgen -W "$(for i in ./* ; do [[ -f ${i}/ezfio/.version ]] && echo $i ; done)" -- ${cur} ) )
2019-01-09 02:44:30 +01:00
return 0
;;
*)
2019-01-14 22:37:24 +01:00
COMPREPLY+=( $(compgen -W "set_file" -- $cur ) )
2019-01-09 02:44:30 +01:00
return 0
;;
esac
fi
}
2019-01-15 00:41:39 +01:00
complete -F _qp_Complete qp