|
###-begin-tiny-completion-### |
|
if complete &>/dev/null; then |
|
|
|
_tiny(){ |
|
local cur prev opts base user_recipes buildin_recipes project_recipes available_recipes |
|
COMPREPLY=() |
|
cur="${COMP_WORDS[COMP_CWORD]}" |
|
prev="${COMP_WORDS[COMP_CWORD-1]}" |
|
# prev_prev="${COMP_WORDS[COMP_CWORD-2]}" |
|
|
|
# |
|
# The basic options we'll complete. |
|
# |
|
opts="list recipes project save rename remove reset generate" |
|
|
|
|
|
# |
|
# build recipes list |
|
# |
|
# get recipes from `tn list`, but this is too slow :( so parsing several tn.json.. |
|
# available_recipes=$(tn list | sed '1,5d' | sed 's/:.*//g' | sed 's/^[ \t]*//;s/[ \t]*$//' | tr '\n' ' ') |
|
|
|
user_recipes=$(cat ~/.tn.json | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,"],"); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:.*\"//g' | sed 's/[\,]//g' | sed 's/\"//g' | sed 's/\]//g' | tr '\n' ' ') |
|
|
|
buildin_recipes=$(cat /usr/local/lib/node_modules/tn/tn.json | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,"],"); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:.*\"//g' | sed 's/[\,]//g' | sed 's/\"//g' | sed 's/\]//g' | tr '\n' ' ') |
|
|
|
if [ -e "./tn.json" ]; then |
|
project_recipes=$(cat ./tn.json | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,"],"); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:.*\"//g' | sed 's/[\,]//g' | sed 's/\"//g' | sed 's/\]//g' | tr '\n' ' ') |
|
available_recipes="${user_recipes} ${buildin_recipes} ${project_recipes}" |
|
else |
|
available_recipes="${user_recipes} ${buildin_recipes}" |
|
fi |
|
|
|
# |
|
# Complete the arguments to some of the basic commands. |
|
# |
|
case "${prev}" in |
|
project) |
|
local args_project="save rename remove reset" |
|
|
|
COMPREPLY=( $(compgen -W "${args_project}" -- ${cur}) ) |
|
return 0 |
|
;; |
|
list | recipes | generate | save | reset) # do nothing more |
|
return 0 |
|
;; |
|
rename | remove) # do recipt name completion |
|
COMPREPLY=( $(compgen -W "${available_recipes}" -- ${cur}) ) |
|
return 0 |
|
;; |
|
*) |
|
#COMPREPLY=( $(compgen -W "${recipe_list}" -- ${cur}) ) |
|
# return 0 |
|
;; |
|
esac |
|
|
|
if [[ ${cur} == -* ]] ; then |
|
local dash_recipes arrIN |
|
|
|
arrIN=(${available_recipes// / }) |
|
|
|
# add prefix -- |
|
for i in ${arrIN[@]/#/--} |
|
do |
|
dash_recipes=$dash_recipes" "$i |
|
done |
|
|
|
# # join |
|
# dash_recipes=$(IFS= ; echo "${arrIN[*]}") |
|
|
|
COMPREPLY=($(compgen -W "--help --verbose --version ${dash_recipes}" -- ${cur})) |
|
return 0 |
|
else |
|
COMPREPLY=($(compgen -W "${opts} ${available_recipes}" -- ${cur})) |
|
return 0 |
|
fi |
|
|
|
|
|
} |
|
complete -F _tiny tn |
|
|
|
fi |
|
###-end-tiny-completion-### |