mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-12 01:11:27 +02:00
gitlab !8: Support completion of installed lua rocks' versions
This commit is contained in:
parent
cecaad96cb
commit
6bf8c4720d
2 changed files with 34 additions and 14 deletions
|
@ -1,5 +1,8 @@
|
||||||
2019-05-06 Oliver Kiddle <okiddle@yahoo.co.uk>
|
2019-05-06 Oliver Kiddle <okiddle@yahoo.co.uk>
|
||||||
|
|
||||||
|
* Doron Behar: gitlab !8: Completion/Unix/Command/_luarocks:
|
||||||
|
Support completion of installed lua rocks' versions
|
||||||
|
|
||||||
* Doron Behar: gitlab !4: Completion/Unix/Command/_pandoc:
|
* Doron Behar: gitlab !4: Completion/Unix/Command/_pandoc:
|
||||||
Add pandoc completion
|
Add pandoc completion
|
||||||
|
|
||||||
|
|
|
@ -67,15 +67,8 @@ __luarocks_rock_version(){
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
"installed")
|
"installed")
|
||||||
# TODO: actually complete versions of installed rocks using the cache
|
|
||||||
# How does luarocks handles multiple versions of the same package?
|
|
||||||
# If anybody knows, please write something beautiful here
|
|
||||||
tree="$2"
|
tree="$2"
|
||||||
if [[ -z "${tree}" ]]; then
|
__luarocks_installed_rocks "${tree}" "${words[$i]}"
|
||||||
_message -e "version for installed rock ${words[$i]}"
|
|
||||||
else
|
|
||||||
_message -e "version for installed rock ${words[$i]} on tree ${tree}"
|
|
||||||
fi
|
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
"new_version")
|
"new_version")
|
||||||
|
@ -202,7 +195,11 @@ __luarocks_installed_rocks(){
|
||||||
# rocks which will be completed by this function will not use the cache which
|
# rocks which will be completed by this function will not use the cache which
|
||||||
# is valid only for installed rocks on default trees like /usr/lib/luarocks
|
# is valid only for installed rocks on default trees like /usr/lib/luarocks
|
||||||
# and ~/.luarocks
|
# and ~/.luarocks
|
||||||
|
#
|
||||||
|
# The second argument (optional as well) is meant for telling the function to
|
||||||
|
# complete a version of a installed rock and not the rock itself from the list
|
||||||
local tree="$1"
|
local tree="$1"
|
||||||
|
local complete_version_for_rock="$2"
|
||||||
if [[ -z ${tree} ]]; then
|
if [[ -z ${tree} ]]; then
|
||||||
local update_policy
|
local update_policy
|
||||||
zstyle -s ":completion:${curcontext}:" cache-policy update_policy
|
zstyle -s ":completion:${curcontext}:" cache-policy update_policy
|
||||||
|
@ -240,7 +237,7 @@ __luarocks_installed_rocks(){
|
||||||
if _cache_invalid luarocks_installed_descriptions; then
|
if _cache_invalid luarocks_installed_descriptions; then
|
||||||
rocks_descriptions=()
|
rocks_descriptions=()
|
||||||
for i in {1.."${#rocks_names[@]}"}; do
|
for i in {1.."${#rocks_names[@]}"}; do
|
||||||
name_version_description="$(luarocks show ${rocks_names[$i]} 2>/dev/null | head -2 | tail -1)"
|
name_version_description="$(luarocks show ${rocks_names[$i]} ${rocks_versions[$i]} 2>/dev/null | head -2 | tail -1)"
|
||||||
total_length=${#name_version_description}
|
total_length=${#name_version_description}
|
||||||
garbage_length="$((${#rocks_names[$i]} + ${#rocks_versions[$i]} + 5))"
|
garbage_length="$((${#rocks_names[$i]} + ${#rocks_versions[$i]} + 5))"
|
||||||
description="${name_version_description[${garbage_length},${total_length}]}"
|
description="${name_version_description[${garbage_length},${total_length}]}"
|
||||||
|
@ -253,7 +250,7 @@ __luarocks_installed_rocks(){
|
||||||
if _cache_invalid luarocks_installed_names_and_descriptions; then
|
if _cache_invalid luarocks_installed_names_and_descriptions; then
|
||||||
rocks_names_and_descriptions=()
|
rocks_names_and_descriptions=()
|
||||||
for i in {1.."${#rocks_names[@]}"}; do
|
for i in {1.."${#rocks_names[@]}"}; do
|
||||||
name_and_description=${rocks_names[$i]}:${rocks_descriptions[$i]}
|
name_and_description=${rocks_names[$i]}:"${rocks_versions[$i]} "${rocks_descriptions[$i]}
|
||||||
rocks_names_and_descriptions+=(${name_and_description})
|
rocks_names_and_descriptions+=(${name_and_description})
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
|
@ -275,7 +272,7 @@ __luarocks_installed_rocks(){
|
||||||
done
|
done
|
||||||
rocks_descriptions=()
|
rocks_descriptions=()
|
||||||
for i in {1.."${#rocks_names[@]}"}; do
|
for i in {1.."${#rocks_names[@]}"}; do
|
||||||
name_version_description="$(luarocks show ${rocks_names[$i]} 2> /dev/null | head -2 | tail -1)"
|
name_version_description="$(luarocks show ${rocks_names[$i]} ${rocks_versions[$i]} 2> /dev/null | head -2 | tail -1)"
|
||||||
total_length=${#name_version_description}
|
total_length=${#name_version_description}
|
||||||
garbage_length="$((${#rocks_names[$i]} + ${#rocks_versions[$i]} + 5))"
|
garbage_length="$((${#rocks_names[$i]} + ${#rocks_versions[$i]} + 5))"
|
||||||
description="${name_version_description[${garbage_length},${total_length}]}"
|
description="${name_version_description[${garbage_length},${total_length}]}"
|
||||||
|
@ -283,11 +280,30 @@ __luarocks_installed_rocks(){
|
||||||
done
|
done
|
||||||
rocks_names_and_descriptions=()
|
rocks_names_and_descriptions=()
|
||||||
for i in {1.."${#rocks_names[@]}"}; do
|
for i in {1.."${#rocks_names[@]}"}; do
|
||||||
name_and_description=${rocks_names[$i]}:${rocks_descriptions[$i]}
|
name_and_description=${rocks_names[$i]}:"${rocks_versions[$i]} "${rocks_descriptions[$i]}
|
||||||
rocks_names_and_descriptions+=(${name_and_description})
|
rocks_names_and_descriptions+=(${name_and_description})
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
_describe 'installed rocks' rocks_names_and_descriptions
|
if [[ -z "$complete_version_for_rock" ]]; then
|
||||||
|
_describe 'installed rock' rocks_names_and_descriptions
|
||||||
|
else
|
||||||
|
if [[ ! -z "${rocks_names[(r)${complete_version_for_rock}]}" ]]; then # checks if the requested rock exists in the list of rocks_names
|
||||||
|
local rock="${complete_version_for_rock}"
|
||||||
|
local first_match_index=${rocks_names[(i)${rock}]}
|
||||||
|
local last_match_index=${rocks_names[(I)${rock}]}
|
||||||
|
local versions=()
|
||||||
|
for i in {${first_match_index}..${last_match_index}}; do
|
||||||
|
versions+=("${rocks_versions[$i]}")
|
||||||
|
done
|
||||||
|
_values "rock's version" $versions
|
||||||
|
else
|
||||||
|
if [[ -z "${tree}" ]]; then
|
||||||
|
_message -r "no such rock installed"
|
||||||
|
else
|
||||||
|
_message -r "no such rock installed in tree ${tree}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
# Used to complete one or more of the followings:
|
# Used to complete one or more of the followings:
|
||||||
# - .rockspec file
|
# - .rockspec file
|
||||||
|
@ -542,7 +558,8 @@ local show_command_options=(
|
||||||
_luarocks_show(){
|
_luarocks_show(){
|
||||||
_arguments \
|
_arguments \
|
||||||
"${show_command_options[@]}" \
|
"${show_command_options[@]}" \
|
||||||
"1: :{__luarocks_rock 'installed' "${opt_args[--tree]}"}"
|
"1: :{__luarocks_rock 'installed' "${opt_args[--tree]}"}" \
|
||||||
|
'2:: :{__luarocks_rock_version "installed" '"${opt_args[--tree]}"'}'
|
||||||
}
|
}
|
||||||
|
|
||||||
(( $+functions[_luarocks_test] )) ||
|
(( $+functions[_luarocks_test] )) ||
|
||||||
|
|
Loading…
Reference in a new issue