added auto-completion for change-wine

This commit is contained in:
Sergey Palcheh
2025-09-11 13:28:50 +06:00
parent bab49377a3
commit b98c6e5408
2 changed files with 35 additions and 1 deletions

View File

@@ -4,7 +4,7 @@ _winehelper_completions() {
COMPREPLY=() COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}" cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}" prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="--help --version --debug install installed install-dxvk install-vkd3d -r -i remove-all --clear-pfx killall remove-prefix backup-prefix restore-prefix create-prefix --changelog changelog" opts="--help --version --debug install installed install-dxvk install-vkd3d -r -i remove-all --clear-pfx killall remove-prefix backup-prefix restore-prefix create-prefix --changelog changelog change-wine"
wine_cmd="winecfg winereg winefile wineconsole winetricks desktop regedit explorer cmd run" wine_cmd="winecfg winereg winefile wineconsole winetricks desktop regedit explorer cmd run"
case "${prev}" in case "${prev}" in
@@ -34,6 +34,20 @@ _winehelper_completions() {
restore-prefix) restore-prefix)
return 0 return 0
;; ;;
install-dxvk|install-vkd3d)
local versions=$(winehelper "${prev}" list 2>/dev/null | grep ' - ' | sed 's/ - //')
COMPREPLY=( $(compgen -W "${versions} none list" -- "${cur}") )
return 0
;;
change-wine)
local wine_versions=$(awk '
/^#+\s*(WINE|WINE_LG|PROTON_LG|PROTON_STEAM)\s*#*$/ { in_group=1 }
/^#+/ { if (! ($0 ~ /^#+\s*(WINE|WINE_LG|PROTON_LG|PROTON_STEAM)\s*#*$/)) in_group=0 }
/^[a-f0-9]{64}/ && in_group { sub(/\.tar\.xz$/, "", $2); print $2 }
' /usr/share/winehelper/sha256sum.list 2>/dev/null)
COMPREPLY=( $(compgen -W "system ${wine_versions}" -- "${cur}") )
return 0
;;
*) *)
;; ;;
esac esac

View File

@@ -20,6 +20,7 @@ _winehelper() {
'remove-prefix[Удалить префикс и все связанные данные]' 'remove-prefix[Удалить префикс и все связанные данные]'
'backup-prefix[Создать резерную копию префикса]' 'backup-prefix[Создать резерную копию префикса]'
'restore-prefix[восстановить префикс из резервной копии "путь/до/whpack"]' 'restore-prefix[восстановить префикс из резервной копии "путь/до/whpack"]'
'change-wine[Изменить версию Wine/Proton для префикса]'
) )
wine_cmd=( wine_cmd=(
@@ -69,6 +70,9 @@ _winehelper() {
install-vkd3d) install-vkd3d)
_get_component_versions 'install-vkd3d' _get_component_versions 'install-vkd3d'
;; ;;
change-wine)
_get_wine_versions
;;
*) *)
_values 'winehelper options' "${opts[@]}" "${wine_cmd[@]}" _values 'winehelper options' "${opts[@]}" "${wine_cmd[@]}"
;; ;;
@@ -87,6 +91,22 @@ _get_component_versions () {
_values 'versions' "${versions[@]}" _values 'versions' "${versions[@]}"
} }
_get_wine_versions () {
local -a versions
local sha256_file="/usr/share/winehelper/sha256sum.list"
if [[ -f "$sha256_file" ]]; then
versions=( ${(f)"$(awk '
/^#+\s*(WINE|WINE_LG|PROTON_LG|PROTON_STEAM)\s*#*$/ { in_group=1 }
/^#+/ { if (! ($0 ~ /^#+\s*(WINE|WINE_LG|PROTON_LG|PROTON_STEAM)\s*#*$/)) in_group=0 }
/^[a-f0-9]{64}/ && in_group { sub(/\.tar\.xz$/, "", $2); print $2 }
' "$sha256_file" 2>/dev/null)"} )
fi
versions+=(system)
_values 'wine/proton versions' "${versions[@]}"
}
_get_prefixes () { _get_prefixes () {
prefixes=( ${(f)"$(ls -1 ~/.local/share/winehelper/prefixes 2>/dev/null)"} ) prefixes=( ${(f)"$(ls -1 ~/.local/share/winehelper/prefixes 2>/dev/null)"} )