From d38b2ca2fb1d40db7e84cf55d6b9b89f555eb0b8 Mon Sep 17 00:00:00 2001 From: Ivan Mazhukin Date: Wed, 2 Jul 2025 19:31:32 +0300 Subject: [PATCH] zsh_completion: init --- auto_completion/zsh_completion/_winehelper | 114 +++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 auto_completion/zsh_completion/_winehelper diff --git a/auto_completion/zsh_completion/_winehelper b/auto_completion/zsh_completion/_winehelper new file mode 100644 index 0000000..d6831c8 --- /dev/null +++ b/auto_completion/zsh_completion/_winehelper @@ -0,0 +1,114 @@ +#compdef winehelper +# shellcheck disable=SC2034,SC2206 +_winehelper() { + local -a opts wine_cmd scripts installed prefixes + + opts=( + '--help[Вывести справку]' + '--version[Показать информацию о пакете и его версии]' + '--debug[Режим отладки]' + 'install[Запустить скрипт установки программы]' + 'installed[Список установленных программ]' + '-r[Запуск программы (отладка)]' + '-i[Запустить скрипт установки программы]' + 'remove-all[Удалить WineHelper и все связанные данные]' + '--clear-pfx[Очистить префикс \[имя_префикса\]]' + 'killall[Убить все процессы]' + 'remove-prefix[Удалить префикс и все связанные данные]' + 'backup-prefix[Создать резерную копию префикса]' + 'restore-prefix[восстановить префикс из резервной копии "путь/до/whpack"]' + ) + + wine_cmd=( + winecfg + winereg + winefile + wineconsole + winetricks + desktop + regedit + explorer + cmd + 'run[Запуск программы (отладка)]' + ) + + local context state line + _arguments -C \ + '1:command:->cmds' \ + '2:subcommand or argument:->args' + + case $state in + cmds) + _values 'winehelper options' "${opts[@]}" "${wine_cmd[@]}" + ;; + args) + case $words[2] in + --debug) + _values 'wine commands' "${wine_cmd[@]}" + ;; + install|-i) + _get_list_for_install + ;; + run|installed) + _get_installed_list + ;; + remove-prefix|backup-prefix) + _get_prefixes + ;; + restore-prefix) + _files + ;; + *) + _values 'winehelper options' "${opts[@]}" "${wine_cmd[@]}" + ;; + esac + ;; + esac +} + +_get_prefixes () { + prefixes=( ${(f)"$(ls -1 ~/.local/share/winehelper/prefixes 2>/dev/null)"} ) + + if ((! ${#prefixes[@]} == 0 )); then + _values 'prefixes' "${prefixes[@]}" + fi +} + +_get_list_for_install () { + + packages=(${(f)"$(winehelper install list 2>/dev/null | + awk -F ' - ' ' + /^[^ ]+ - \("/ {next} + /^[[:space:]]*$/ {next} + /^Информация:/ {next} + /^[^ ]+ - / { + name=$1; + desc=$2; + gsub(/^[[:space:]]+|[[:space:]]+$/, "", name); + gsub(/^[[:space:]]*"?|"?[[:space:]]*$/, "", desc); + if (name && desc) print name ":" desc + } + ')"}) + + packages+=( + scadoffice:"SCAD Office" + t-flex-cad17-applications:"Приложения для T-FLEX CAD 17" + t-flex-cad17-resources:"Обучающие материалы T-FLEX CAD 17" + ) + + _describe 'packages' packages +} + +_get_installed_list () { + installed=( + ${(f)"$(grep -h 'Exec=env' ~/.local/share/winehelper/*.desktop 2>/dev/null | + awk -F'/' '{print $NF}' | + awk -F'"' '{print $1}')"} + ) + + if ((! ${#installed[@]} == 0 )); then + _values 'installed apps' "${installed[@]}" + fi +} + +compdef _winehelper winehelper