#1 Le 13/08/2008, à 15:32
- misterbgs
utliser la completion pour mon script
Bonjour,
j'ai créé un script et j'ai essayé de configurer mon mon ficher .bash_completion en ce sens. Mais il n'est pas pris en compte lors du lancement de la konsole.
le programme s'appelle vbu.sh, programme pour lequel j'ai crée l'alias vbu.
Voici le code de mon fichier .bash_completion :
# Completion pour le script vbu
have vbu &&
_vbu()
{
local cur
COMPREPLY=()
cur='_get_cword'
COMPREPLY=( $( compgen -W 'alcide bioskop ca-sys choublanc gogol \
horus icare nikopol parfip-mail toptechno \
warhole' $cur ) )
} &&
complete -F _vbu vbu
# Get the word to complete
# This is nicer than ${COMP_WORDS[$COMP_CWORD]}, since it handles cases
# where the user is completing in the middle of a word.
# (For example, if the line is "ls foobar",
# and the cursor is here --------> ^
# it will complete just "foo", not "foobar", which is what the user wants.)
_get_cword()
{
if [[ "${#COMP_WORDS[COMP_CWORD]}" -eq 0 ]] || [[ "$COMP_POINT" == "${#COMP_LINE}" ]]; then
echo "${COMP_WORDS[COMP_CWORD]}"
else
local i
local cur="$COMP_LINE"
local index="$COMP_POINT"
for (( i = 0; i <= COMP_CWORD; ++i )); do
while [[ "${#cur}" -ge ${#COMP_WORDS[i]} ]] && [[ "${cur:0:${#COMP_WORDS[i]}}" != "${COMP_WORDS[i]}" ]]; do
cur="${cur:1}"
index="$(( index - 1 ))"
done
if [[ "$i" -lt "$COMP_CWORD" ]]; then
local old_size="${#cur}"
cur="${cur#${COMP_WORDS[i]}}"
local new_size="${#cur}"
index="$(( index - old_size + new_size ))"
fi
done
if [[ "${COMP_WORDS[COMP_CWORD]:0:${#cur}}" != "$cur" ]]; then
# We messed up! At least return the whole word so things keep working
echo "${COMP_WORDS[COMP_CWORD]}"
else
echo "${cur:0:$index}"
fi
fi
}
### Local Variables
### mode: shell-script
### End:
Merci de votre aide.
Hors ligne