bash-completion/install-completions

76 lines
1.3 KiB
Plaintext
Raw Normal View History

2009-09-14 23:01:19 +02:00
#!/bin/sh
# install relevant completions, by sourcing every scriptlet
# found in a given directory, and symlinking those matching
# an installed command to another directory
2009-09-14 23:01:19 +02:00
2009-09-20 22:12:18 +02:00
have()
{
PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin type $1 &>/dev/null
}
usage()
{
echo "usage: $0 <completion_dir> [installation_dir]"
}
while getopts ":h" flag; do
2009-09-14 23:01:19 +02:00
case $flag in
2009-09-20 22:12:18 +02:00
h) usage; exit 0;;
2009-09-14 23:01:19 +02:00
esac
done
shift $((OPTIND - 1))
2009-09-20 22:12:18 +02:00
completion_dir=$1
if [ -z "$completion_dir" ]; then
echo "missing completion directory"
usage
2009-09-14 23:01:19 +02:00
exit 1
fi
if [ ! -d $completion_dir ]; then
echo "invalid directory $completion_dir"
2009-09-20 22:12:18 +02:00
usage
2009-09-14 23:01:19 +02:00
exit 1
fi
installation_dir=$2
if [ ! -d $installation_dir ]; then
echo "invalid directory $installation_dir"
2009-09-20 22:12:18 +02:00
usage
2009-09-14 23:01:19 +02:00
exit 1
fi
# many scripts require this
2009-09-14 23:01:19 +02:00
shopt -s extglob
# and some require this also
UNAME=$(uname -s)
UNAME=${UNAME/CYGWIN_*/Cygwin}
case $UNAME in
Linux|GNU|GNU/*) USERLAND=GNU ;;
*) USERLAND=$UNAME ;;
esac
2009-09-14 23:01:19 +02:00
for script in $completion_dir/*; do
# reset completion
complete -r
# source script
source $script 2>/dev/null
# check completion output
output=$(complete -p)
2009-09-20 22:12:18 +02:00
if [ -z "$output" ]; then
continue
2009-09-14 23:01:19 +02:00
fi
2009-09-20 22:12:18 +02:00
if [ -n "$installation_dir" ]; then
ln -sf $script $installation_dir/$(basename $script)
else
echo "$script OK"
2009-09-14 23:01:19 +02:00
fi
2009-09-20 22:12:18 +02:00
2009-09-14 23:01:19 +02:00
done