Here is my script that feeds xprompt. It is not as involved as venam's because I have to list the completions of each command separately. Also, it was done in a couple of minutes after I have written xprompt, I need to improve it.
It only provides completion for mpc commands, .desktop applications (with my run script, whose -t flag lists .desktop entries) and manpages (with my xman script, whose -t flag lists the manpages).
Here is xprompt.sh:
Code:
#!/bin/sh
# xprompt.sh
# Run `$ xprompt.sh gen` to generate a cache file.
# Run `$ xprompt.sh` to run xprompt.
CACHEDIR="$HOME/usr/local/cache"
CACHEFILE="xprompt.cache"
CACHEPATH="${CACHEDIR}/${CACHEFILE}"
usage() {
echo "usage: xprompt.sh [gen]" >&2
exit 1
}
comp_xman() {
xman -t | sed 's/^/ /'
}
comp_run() {
run -t | sed 's/^/ /'
}
comp_mpc() {
mpc help | grep "^ *mpc" | tail +2 |\
sed 's/\(.......................................................\)./\1 /' |\
sed 's/ mpc \([^ ]*\) [^ ]*/ \1/'
}
gencompcache() {
ls $(echo $PATH | tr ':' ' ') | grep -v '/' | grep . | sort | grep -v '^\"' | {
while read cmd
do
echo $cmd
if [ "$cmd" = xman ]
then
comp_xman
elif [ "$cmd" = run ]
then
comp_run
elif [ "$cmd" = mpc ]
then
comp_mpc
fi
done
}
}
case $# in
0)
<"${CACHEPATH}" xprompt -f -i "exec:" | sh &
;;
1)
case $1 in
gen) gencompcache >"${CACHEPATH}" ;;
*) usage ;;
esac
;;
*)
usage
;;
esac