mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: restrict aliases, completions to interactive shells
- minor cleanup of bash completion script
This commit is contained in:
@ -29,40 +29,56 @@
|
|||||||
# Create bash completions for OpenFOAM applications
|
# Create bash completions for OpenFOAM applications
|
||||||
#
|
#
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
#set -x
|
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
exec 1>&2
|
exec 1>&2
|
||||||
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
||||||
cat<<USAGE
|
cat<<USAGE
|
||||||
|
|
||||||
Usage: $Script [OPTION] <file>
|
Usage: ${0##*/} [OPTION] <outputFile>
|
||||||
|
options:
|
||||||
* Create bash completions for OpenFOAM applications and write to <file>.
|
-d dir | -dir dir Directory to process
|
||||||
By default searches directories \$FOAM_APPBIN and \$FOAM_USER_APPBIN
|
-u | -user Add \$FOAM_USER_APPBIN to the search directories
|
||||||
|
|
||||||
|
|
||||||
Options:
|
|
||||||
-d | -directory Directory to process
|
|
||||||
-h | -help Print the usage
|
-h | -help Print the usage
|
||||||
|
|
||||||
|
Create bash completions for OpenFOAM applications and write to <outputFile>.
|
||||||
|
By default searches \$FOAM_APPBIN only.
|
||||||
|
|
||||||
USAGE
|
USAGE
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Report error and exit
|
||||||
|
die()
|
||||||
|
{
|
||||||
|
exec 1>&2
|
||||||
|
echo
|
||||||
|
echo "Error encountered:"
|
||||||
|
while [ "$#" -ge 1 ]; do echo " $1"; shift; done
|
||||||
|
echo
|
||||||
|
echo "See '${0##*/} -help' for usage"
|
||||||
|
echo
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
#set -x
|
||||||
|
|
||||||
unset outFile
|
unset outFile
|
||||||
searchDirs="$FOAM_APPBIN $FOAM_USER_APPBIN"
|
searchDirs="$FOAM_APPBIN"
|
||||||
while [ "$#" -gt 0 ]
|
while [ "$#" -gt 0 ]
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-h | -help)
|
-h | -help)
|
||||||
usage
|
usage
|
||||||
;;
|
;;
|
||||||
-d | -directory)
|
-d | -dir)
|
||||||
searchDirs="$2"
|
searchDirs="$2"
|
||||||
[ -d $searchDirs ] || usage "directory not found '$searchDirs'"
|
[ -d $searchDirs ] || usage "directory not found '$searchDirs'"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
-u | -user)
|
||||||
|
searchDirs="$searchDirs $FOAM_USER_APPBIN"
|
||||||
|
;;
|
||||||
-*)
|
-*)
|
||||||
usage "unknown option: '$1'"
|
usage "unknown option: '$1'"
|
||||||
;;
|
;;
|
||||||
@ -74,14 +90,14 @@ do
|
|||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
[ -n "$outFile" ] || usage
|
[ -n "$outFile" ] || usage "No output file specified"
|
||||||
\rm -f $outFile
|
|
||||||
touch $outFile
|
|
||||||
|
|
||||||
|
|
||||||
writeFilterFunction()
|
# Generate header
|
||||||
{
|
cat << HEADER > $outFile
|
||||||
cat<< WRITEFILTER >> $1
|
#----------------------------------*-sh-*--------------------------------------
|
||||||
|
# Bash completions for OpenFOAM applications
|
||||||
|
|
||||||
unset -f _of_filter_opts 2>/dev/null
|
unset -f _of_filter_opts 2>/dev/null
|
||||||
_of_filter_opts()
|
_of_filter_opts()
|
||||||
{
|
{
|
||||||
@ -92,17 +108,20 @@ _of_filter_opts()
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
WRITEFILTER
|
HEADER
|
||||||
}
|
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#
|
||||||
|
# Produce contents for switch for common options
|
||||||
|
#
|
||||||
commonOptions()
|
commonOptions()
|
||||||
{
|
{
|
||||||
local options=$@
|
|
||||||
local indent1=" "
|
local indent1=" "
|
||||||
local indent2=" "
|
local indent2=" "
|
||||||
for o in ${options[@]}; do
|
for opt
|
||||||
case $o in
|
do
|
||||||
|
case $opt in
|
||||||
-case)
|
-case)
|
||||||
echo "${indent1}-case)"
|
echo "${indent1}-case)"
|
||||||
echo "${indent2}COMPREPLY=(\$(compgen -d -- \${cur}))"
|
echo "${indent2}COMPREPLY=(\$(compgen -d -- \${cur}))"
|
||||||
@ -137,27 +156,26 @@ commonOptions()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Generate header
|
#------------------------------------------------------------------------------
|
||||||
cat << HEADER > $outFile
|
|
||||||
#----------------------------------*-sh-*--------------------------------------
|
|
||||||
# Bash completions for OpenFOAM applications
|
|
||||||
|
|
||||||
HEADER
|
|
||||||
|
|
||||||
writeFilterFunction $outFile
|
|
||||||
|
|
||||||
for dir in ${searchDirs}
|
for dir in ${searchDirs}
|
||||||
do
|
do
|
||||||
|
if [ -d "$dir" ]
|
||||||
|
then
|
||||||
echo "Processing directory $dir" 1>&2
|
echo "Processing directory $dir" 1>&2
|
||||||
|
else
|
||||||
|
echo "No such directory: $dir" 1>&2
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
# Sort with ignore-case
|
# Sort with ignore-case
|
||||||
apps=($(\ls $dir | sort -f))
|
set -- $(\ls $dir | sort -f)
|
||||||
for appName in "${apps[@]}"
|
for appName
|
||||||
do
|
do
|
||||||
[ -f "$dir/$appName" -a -x "$dir/$appName" ] || continue
|
[ -f "$dir/$appName" -a -x "$dir/$appName" ] || continue
|
||||||
appHelp=$($appName -help)
|
appHelp=$($appName -help)
|
||||||
|
|
||||||
echo "Processing $appName" 1>&2
|
echo " $appName" 1>&2
|
||||||
|
|
||||||
# Options with args
|
# Options with args
|
||||||
optsWithArgs=($(awk '/^ {0,4}-[a-z]/ && /</ {print $1}' <<< "$appHelp"))
|
optsWithArgs=($(awk '/^ {0,4}-[a-z]/ && /</ {print $1}' <<< "$appHelp"))
|
||||||
@ -165,7 +183,7 @@ do
|
|||||||
# Options without args
|
# Options without args
|
||||||
opts=($(awk '/^ {0,4}-[a-z]/ && !/</ {print $1}' <<< "$appHelp"))
|
opts=($(awk '/^ {0,4}-[a-z]/ && !/</ {print $1}' <<< "$appHelp"))
|
||||||
|
|
||||||
cat<<WRITECOMPLETION >> $outFile
|
cat << WRITECOMPLETION >> $outFile
|
||||||
unset -f _of_${appName} 2>/dev/null
|
unset -f _of_${appName} 2>/dev/null
|
||||||
_of_${appName}()
|
_of_${appName}()
|
||||||
{
|
{
|
||||||
@ -178,10 +196,10 @@ _of_${appName}()
|
|||||||
case \${prev} in
|
case \${prev} in
|
||||||
$(commonOptions ${optsWithArgs[@]})
|
$(commonOptions ${optsWithArgs[@]})
|
||||||
*)
|
*)
|
||||||
if [ "\${optsWithArgs/\${prev} /}" != "\${optsWithArgs}" ]; then
|
if [ "\${optsWithArgs/\${prev} /}" != "\${optsWithArgs}" ]
|
||||||
# Unknown what type of arg follows - set to files
|
then
|
||||||
# not always correct but at least can still navigate path if
|
# Unknown type of arg follows - set to files.
|
||||||
# needed...
|
# Not always correct but can still navigate path if needed...
|
||||||
COMPREPLY=(\$(compgen -f -- \${cur}))
|
COMPREPLY=(\$(compgen -f -- \${cur}))
|
||||||
else
|
else
|
||||||
# Catch-all - present all remaining options
|
# Catch-all - present all remaining options
|
||||||
10
etc/bashrc
10
etc/bashrc
@ -169,12 +169,16 @@ export PATH LD_LIBRARY_PATH MANPATH
|
|||||||
# Source project setup files
|
# Source project setup files
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
_foamEtc config.sh/settings
|
_foamEtc config.sh/settings
|
||||||
_foamEtc config.sh/aliases
|
|
||||||
|
|
||||||
# Bash completions
|
if /usr/bin/tty -s 2>/dev/null # Interactive shell
|
||||||
if command -v complete > /dev/null 2>&1
|
|
||||||
then
|
then
|
||||||
|
_foamEtc config.sh/aliases
|
||||||
|
|
||||||
|
# Bash completions
|
||||||
|
if command -v complete > /dev/null 2>&1
|
||||||
|
then
|
||||||
_foamEtc config.sh/bashcompletion
|
_foamEtc config.sh/bashcompletion
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -216,7 +216,11 @@ if ( $status == 0 ) setenv MANPATH $cleaned
|
|||||||
# Source project setup files
|
# Source project setup files
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
_foamEtc config.csh/settings
|
_foamEtc config.csh/settings
|
||||||
_foamEtc config.csh/aliases
|
|
||||||
|
if ($?prompt) then # Interactive shell
|
||||||
|
_foamEtc config.csh/aliases
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
# Source user setup files for optional packages
|
# Source user setup files for optional packages
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|||||||
Reference in New Issue
Block a user