Skip to content
Snippets Groups Projects
Commit 81037a60 authored by Mark OLESEN's avatar Mark OLESEN
Browse files

ENH: add tcsh completion functionality (issue #551)

- currently no cleanup of completions when deactivating an OpenFOAM
  tcsh environment

- tab completion with directories adds a space after the slash, which
  makes navigation a bit annoying.
parent 507d13c5
No related branches found
No related tags found
No related merge requests found
#!bash
# A bash -*- sh -*- adapter for re-using OpenFOAM bash completions with tcsh
#
# Called with appName and COMMAND_LINE
#
# Source the bash completions
. $WM_PROJECT_DIR/etc/config.sh/bash_completion
appName=$1
# Ensure COMP_LINE is available for bash function
if [ "$#" -eq 2 ]
then
COMP_LINE=$2
else
COMP_LINE=$COMMAND_LINE
fi
# Remove the colon as a completion separator because tcsh cannot handle it
COMP_WORDBREAKS=${COMP_WORDBREAKS//:}
# Set COMP_WORDS in a way that can be handled by the bash script.
COMP_WORDS=($COMP_LINE)
# The cursor is at the end of parameter #1.
# We must check for a space as the last character which will
# tell us that the previous word is complete and the cursor
# is on the next word.
if [ "${COMP_LINE: -1}" = " " ]
then
# The last character is a space, so our location is at the end
# of the command-line array
COMP_CWORD=${#COMP_WORDS[@]}
else
# The last character is not a space, so our location is on the
# last word of the command-line array, so we must decrement the
# count by 1
COMP_CWORD=$((${#COMP_WORDS[@]}-1))
fi
# bash completions are "complete ... -F _of_APPNAME APPNAME
_of_${appName} \
"$appName" "${COMP_WORDS[COMP_CWORD]}" "${COMP_WORDS[COMP_CWORD-1]}"
# Need slash on the end of directories for tcsh
reply=($(for i in ${COMPREPLY[@]}
do
if [ -d "$i" -a "${i#/}" = "$i" ]
then
echo "$i/"
else
echo "$i"
fi
done
))
echo ${reply[@]}
#------------------------------------------------------------------------------
#----------------------------------*-sh-*--------------------------------------
# Tcsh completions for OpenFOAM applications
# Using bash_completion functions for the hard work
if ($?tcsh) then # tcsh only
if ( -f $WM_PROJECT_DIR/etc/config.sh/bash_completion \
&& -f $WM_PROJECT_DIR/etc/config.csh/complete) then
foreach appName (`sed -ne 's/^.*&& complete.* //p' $WM_PROJECT_DIR/etc/config.sh/bash_completion`)
# Pass explicitly
## complete $appName 'p,*,`bash $WM_PROJECT_DIR/etc/config.csh/complete '$appName' "${COMMAND_LINE}"`,'
# Pass via environment
complete $appName 'p,*,`bash $WM_PROJECT_DIR/etc/config.csh/complete '$appName'`,'
end
endif
endif
#------------------------------------------------------------------------------
......@@ -219,6 +219,7 @@ _foamEtc config.csh/settings
if ($?prompt) then # Interactive shell
_foamEtc config.csh/aliases
_foamEtc config.csh/tcsh_completion
endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment