Skip to content

Commit dd921c2

Browse files
umireonDhavalKapil
authored andcommitted
Add the completion for bash
TODO: * Completions with install command are painfully slow. * list commands should be modified for machine readability.
1 parent b72c0b3 commit dd921c2

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

completions/luaver.bash

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
3+
_luaver_download()
4+
{
5+
if curl -V >/dev/null 2>&1
6+
then
7+
curl -fsSL "$1"
8+
else
9+
wget -qO- "$1"
10+
fi
11+
}
12+
13+
_luaver()
14+
{
15+
local cur="${COMP_WORDS[COMP_CWORD]}"
16+
local opts
17+
case $COMP_CWORD in
18+
1 )
19+
opts=($(luaver help | 'awk' '/^ / { print $2 }')) # UGLY HACK
20+
;;
21+
2 )
22+
case ${COMP_WORDS[COMP_CWORD-1]} in
23+
install )
24+
opts=($(_luaver_download "https://www.lua.org/ftp/" | 'awk' 'match($0, /lua-5\.[0-9]+(\.[0-9]+)?/) { print substr($0, RSTART + 4, RLENGTH - 4) }'))
25+
;;
26+
install-luajit )
27+
opts=($(_luaver_download "http://luajit.org/download.html" | awk '/MD5 Checksums/,/<\/pre/ { print }' | awk '/LuaJIT.*gz/ { print $2 }' | sed -e s/LuaJIT-// -e s/\.tar\.gz//))
28+
;;
29+
install-luarocks )
30+
opts=($(wget -qO- http://luarocks.github.io/luarocks/releases/releases.json | 'awk' 'match($0, /"[0-9]+\.[0-9]\.[0-9]"/) { print substr($0, RSTART, RLENGTH) } '))
31+
;;
32+
use | set-default | uninstall)
33+
opts=($(luaver list | grep '[0-9].[0-9].[0-9]' | tr - ' ')) # UGLY HACK
34+
;;
35+
use-luajit | set-default-luajit | uninstall-luajit )
36+
opts=($(luaver list-luajit | grep '[0-9].[0-9].[0-9]' | tr - ' ')) # UGLY HACK
37+
;;
38+
use-luarocks | set-default-luarocks | uninstall-luarocks)
39+
opts=($(luaver list-luarocks | grep '[0-9].[0-9].[0-9]' | tr - ' ')) # UGLY HACK
40+
;;
41+
esac
42+
;;
43+
esac
44+
COMPREPLY=($(compgen -W "${opts[*]}" -- "$cur"))
45+
}
46+
47+
complete -F _luaver luaver

0 commit comments

Comments
 (0)