xprompt: a dmenu rip-off with contextual completion - Programming On Unix

Users browsing this thread: 1 Guest(s)
seninha
Long time nixers
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


Messages In This Thread
RE: xprompt: a dmenu rip-off with contextual completion - by seninha - 16-08-2020, 07:25 PM
RE: What are you working on? - by movq - 16-08-2020, 03:54 AM
RE: What are you working on? - by venam - 16-08-2020, 07:34 AM
RE: What are you working on? - by seninha - 16-08-2020, 09:48 AM
RE: What are you working on? - by venam - 16-08-2020, 10:03 AM