added: cmake glue for adding bash tab completion for an installed product
This commit is contained in:
parent
4c6d4ee201
commit
564f064392
@ -161,3 +161,6 @@ endif()
|
|||||||
|
|
||||||
# Install build system files
|
# Install build system files
|
||||||
install(DIRECTORY cmake DESTINATION share/opm)
|
install(DIRECTORY cmake DESTINATION share/opm)
|
||||||
|
|
||||||
|
# Install tab completion skeleton
|
||||||
|
install(FILES etc/opm_bash_completion.sh.in DESTINATION share/opm/etc)
|
||||||
|
6
cmake/Modules/OpmBashCompletion.cmake
Normal file
6
cmake/Modules/OpmBashCompletion.cmake
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# Installs bash tab completion for a product
|
||||||
|
macro(opm_add_bash_completion binary)
|
||||||
|
set(PRODUCT ${binary})
|
||||||
|
configure_file(${OPM_MACROS_ROOT}/etc/opm_bash_completion.sh.in ${binary}_bash_completion.sh @ONLY)
|
||||||
|
install(FILES ${PROJECT_BINARY_DIR}/${binary}_bash_completion.sh DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/bash_completion.d)
|
||||||
|
endmacro()
|
60
etc/opm_bash_completion.sh.in
Normal file
60
etc/opm_bash_completion.sh.in
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
# this snippet enables parameter completion via the tabulator key
|
||||||
|
# for bash for opm products.
|
||||||
|
|
||||||
|
# this is a bash readline completer for the case where a binary is
|
||||||
|
# already known to be an eWoms simulator.
|
||||||
|
_ewoms_parameter_completor()
|
||||||
|
{
|
||||||
|
if test "$COMP_WORDS" == ""; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
cmd="${COMP_WORDS[0]}"
|
||||||
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
|
fullcmd="$(which "$cmd")"
|
||||||
|
ALL_OPTS=$("$fullcmd" --help 2> /dev/null | grep '^ *--' | sed 's/ *\(--[a-zA-Z0-9\-]*\)=.*/\1=/')
|
||||||
|
ALL_OPTS=$(echo "$ALL_OPTS" | sed 's/^ *--help.*/--help/')
|
||||||
|
COMPREPLY=( $(compgen -A file -W "$ALL_OPTS" -- "${cur}") )
|
||||||
|
}
|
||||||
|
|
||||||
|
# this is a bash readline default completer which attempts to find out
|
||||||
|
# if a given binary is an eWoms simulation. this needs to be set as a
|
||||||
|
# default completer because the name of eWoms binaries cannot be known
|
||||||
|
# a-priori.
|
||||||
|
_ewoms_generic_parameter_completor()
|
||||||
|
{
|
||||||
|
if test "$COMP_WORDS" == ""; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
COMPREPLY=()
|
||||||
|
local cmd cur ALL_OPTS
|
||||||
|
cmd="${COMP_WORDS[0]}"
|
||||||
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
|
|
||||||
|
fullcmd="$(which "$cmd")"
|
||||||
|
if test -z "$fullcmd" || \
|
||||||
|
! test -x "$fullcmd" || \
|
||||||
|
(! test -f "$fullcmd" && ! test -h "$fullcmd" ) || \
|
||||||
|
! test -r "$fullcmd" || \
|
||||||
|
! grep -q "Ewoms[a-zA-Z0-9]*Simulator[a-zA-Z0-0]" "$fullcmd"
|
||||||
|
then
|
||||||
|
if test -n "$DEFAULT_COMPLETION_LOADER"; then
|
||||||
|
"$DEFAULT_COMPLETION_LOADER" $@
|
||||||
|
elif type -t _completion_loader 2>&1 > /dev/null; then
|
||||||
|
# the default DEFAULT_COMPLETION_LOADER variable has not
|
||||||
|
# been set and the _completion_loader function exists, so
|
||||||
|
# we use _completion_loader as the default completer.
|
||||||
|
_completion_loader $@
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
return $?
|
||||||
|
fi
|
||||||
|
|
||||||
|
_ewoms_parameter_completor $@
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
complete -o nospace -F _ewoms_parameter_completor @PRODUCT@
|
Loading…
Reference in New Issue
Block a user