From dc5eae0a0992f4166efd09ef820e6442b2a0073a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Bidar?= Date: Sun, 16 Jul 2023 03:24:47 +0300 Subject: [PATCH 01/10] Import zsh completition made by Holger Macht MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Right now the zsh completition is packaged inside the zsh package on OpenSUSE. Several distributions either package it or the user has to import it themselves. It is better if it is stored here so any can pick it up in there zsh package and put fixes in here. The file was imported from the OpenSUSE zsh package plus a few spelling fixes. Signed-off-by: Björn Bidar --- contrib/osc.zsh | 149 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 contrib/osc.zsh diff --git a/contrib/osc.zsh b/contrib/osc.zsh new file mode 100644 index 0000000000..d043d2f335 --- /dev/null +++ b/contrib/osc.zsh @@ -0,0 +1,149 @@ +#compdef osc +# +# Copyright (C) 2009,2010 Holger Macht +# +# This file is released under the GPLv2. +# +# Based on the zsh guide from http://zsh.dotsrc.org/Guide/zshguide06.html +# +# Toggle verbose completions: zstyle ':completion:*:osc:*' verbose no +# zstyle ':completion:*:osc-subcommand:*' verbose no +# +# Use the variables $ZSH_OSC_BUILD_TARGETS_EXTRA and $ZSH_OSC_PROJECTS_EXTRA to +# extend the list of possible completions in your ~/.zshrc like that: +# export OSC_PROJECTS_EXTRA="Base:System Base:shells" +# +# version 0.2 +# + +OSC_BUILD_TARGETS="openSUSE_13.1 openSUSE_13.2 openSUSE_Tumbleweed openSUSE_Factory SLE_11_SP3 SLE_12" +OSC_PROJECTS="openSUSE:Factory openSUSE:Tumbleweed openSUSE:13.2 openSUSE:13.1" + +# user defined variables $OSC_BUILD_TARGETS_EXTRA and +# $OSC_PROJECTS_EXTRA can add to the project/build target list +OSC_BUILD_TARGETS="$OSC_BUILD_TARGETS $ZSH_OSC_BUILD_TARGETS_EXTRA" +OSC_PROJECTS="$OSC_PROJECTS $ZSH_OSC_PROJECTS_EXTRA" + +# Main dispatcher + +_osc() { + if (( CURRENT > 2 )) && [[ ${words[2]} != "help" ]]; then + # Remember the subcommand name + local cmd=${words[2]} + # Set the context for the subcommand. + curcontext="${curcontext%:*:*}:osc-subcommand" + # Narrow the range of words we are looking at to exclude `osc' + (( CURRENT-- )) + shift words + # Run the completion for the subcommand + if [ "$cmd" = "submitreq" -o "$cmd" = "sr" ]; then + _osc_cmd_submitreq + elif [ "$cmd" = "getbinaries" ]; then + _osc_cmd_getbinaries + elif [ "$cmd" = "checkout" -o "$cmd" = "co" -o "$cmd" = "branch" ]; then + _osc_cmd_checkout + elif [ "$cmd" = "buildlog" -o "$cmd" = "buildinfo" -o "$cmd" = "bl" ]; then + _osc_cmd_buildlog + else + _osc_cmd_do $cmd + fi + else + local hline + local -a cmdlist + local tag=0 + _call_program help-commands osc help | while read -A hline; do + # start parsing with "commands:" + [[ $hline[1] = "commands:" ]] && tag=1 + # stop parsing at the line starting with "For" + [[ $hline[1] = "For" ]] && tag=0 + [[ $tag = 0 ]] && continue + # all commands have to start with lower case letters + [[ $hline[1] =~ ^[A-Z] ]] && continue + (( ${#hline} < 2 )) && continue + + # ${hline[1]%,} truncates the last ',' + cmdlist=($cmdlist "${hline[1]%,}:${hline[2,-1]}") + done + _describe -t osc-commands 'osc command' cmdlist + fi +} + +_osc_cmd_getbinaries() { + _arguments \ + '1:PROJECT:( `echo $OSC_PROJECTS` )' \ + '2:PACKAGE:(PACKAGE)' \ + '3:REPOSITORY:( `echo $OSC_BUILD_TARGETS` )' \ + '4:ARCHITECTURE:(i586 x86_64)' +} + +_osc_cmd_checkout() { + _arguments \ + '1:PROJECT:( `echo $OSC_PROJECTS` )' \ + '2:PACKAGE:(PACKAGE)' +} + +_osc_cmd_buildlog() { + _arguments \ + '1:REPOSITORY:( `echo $OSC_BUILD_TARGETS` )' \ + '2:ARCHITECTURE:(i586 x86_64)' +} + +_osc_cmd_submitreq() { + local hline + local -a cmdlist + local tag=0 + _call_program help-commands osc help $cmd | while read -A hline; do + # start parsing from "usage:" + [[ $hline[1] = "usage:" ]] && tag=1 + [[ $tag = 0 ]] && continue + + if [[ $hline[1] =~ ^osc ]]; then + shift hline; shift hline + elif ! [[ $hline[1] =~ ^- ]]; then + # Option has to start with a '-' or 'osc submitrequest' + continue + fi + + (( ${#hline} < 2 )) && continue + + cmdlist=($cmdlist "${hline[1]%,}:${hline[2,-1]}") + + done + + _describe -t osc-commands 'osc command' cmdlist +} + + +_osc_cmd_do() { + local hline + local -a cmdlist + local tag=0 + + # only start completion if there's some '-' on the line + if ! [ "$words[2]" = "-" ]; then + _complete + return + fi + + _call_program help-commands osc help $cmd | while read -A hline; do + # start parsing from "Options:" + [[ $hline[1] = "Options:" ]] && tag=1 + [[ $tag = 0 ]] && continue + # Option has to start with a '-' + [[ $hline[1] =~ ^- ]] || continue + (( ${#hline} < 2 )) && continue + + cmdlist=($cmdlist "${hline[1]%,}:${hline[2,-1]}") + done + + if [ -n "$cmdlist" ]; then + _describe -t osc-commands 'osc command' cmdlist + else + _complete + fi +} + +# Code to make sure _osc is run when we load it +_osc "$@" + + From b1d106947434d34dd497ad0e880bf04790ccab7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Bidar?= Date: Thu, 20 Jul 2023 15:17:06 +0300 Subject: [PATCH 02/10] Fetch project list in zsh completition at runtime MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Similar to the bash/tcsh completition fetch the project list at runtime. Includes basic completion for alias/api-url as project list cache is separated per instance. Signed-off-by: Björn Bidar --- contrib/osc.zsh | 88 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 84 insertions(+), 4 deletions(-) diff --git a/contrib/osc.zsh b/contrib/osc.zsh index d043d2f335..1d7c43e00c 100644 --- a/contrib/osc.zsh +++ b/contrib/osc.zsh @@ -1,6 +1,7 @@ #compdef osc # # Copyright (C) 2009,2010 Holger Macht +# Copyright (C) 2023 Björn Bidar # # This file is released under the GPLv2. # @@ -17,16 +18,25 @@ # OSC_BUILD_TARGETS="openSUSE_13.1 openSUSE_13.2 openSUSE_Tumbleweed openSUSE_Factory SLE_11_SP3 SLE_12" -OSC_PROJECTS="openSUSE:Factory openSUSE:Tumbleweed openSUSE:13.2 openSUSE:13.1" # user defined variables $OSC_BUILD_TARGETS_EXTRA and # $OSC_PROJECTS_EXTRA can add to the project/build target list OSC_BUILD_TARGETS="$OSC_BUILD_TARGETS $ZSH_OSC_BUILD_TARGETS_EXTRA" -OSC_PROJECTS="$OSC_PROJECTS $ZSH_OSC_PROJECTS_EXTRA" # Main dispatcher _osc() { + # Variables shared by all internal functions + local osc_projects osc_rc osc_cmd osc_alias + _osc_complete_prepare + osc_projects="${XDG_CACHE_HOME}/osc.projects" + osc_rc="${XDG_CONFIG_HOME}/osc/oscrc" + osc_cmd=osc + + if [[ "${words[0]}" = "isc" ]] ; then + osc_alias=internal + fi + if (( CURRENT > 2 )) && [[ ${words[2]} != "help" ]]; then # Remember the subcommand name local cmd=${words[2]} @@ -36,6 +46,40 @@ _osc() { (( CURRENT-- )) shift words # Run the completion for the subcommand + if [ $cmd = -A -o $cmd = --apiurl ] ; then + if [[ -s "${osc_rc}" ]] ; then + local hints=($(sed -rn '/^(aliases=|\[http)/{s/,/ /g;s/(aliases=|\[|\])//gp}' < "${osc_rc}" 2> /dev/null)) + if [[ -n "${words[2]}" ]]; then + for h in ${hints[@]} ; do + case "$h" in + http*) + local tmp=$(sed -rn '\@^\['${h}'@,\@=@{\@^aliases=@{s@[^=]+=([^,]+),.*@\1@p};}' < "${osc_rc}" 2> /dev/null) + if [[ "${words[2]}" = "$h" ]]; then + osc_alias=$tmp + break + fi + ;; + *) + if [[ "${words[2]}" = "$h" ]]; then + osc_alias=$h + break + fi + esac + done + else + _arguments '1:ALIAS:( `echo $hints`)' + return + fi + fi + fi + + if [[ -n "$osc_alias" ]] ; then + osc_projects="${osc_projects}.${osc_alias}" + osc_command="$osc_command -A $osc_alias" + fi + + _osc_update_project_list + if [ "$cmd" = "submitreq" -o "$cmd" = "sr" ]; then _osc_cmd_submitreq elif [ "$cmd" = "getbinaries" ]; then @@ -68,9 +112,45 @@ _osc() { fi } +_osc_call_me_maybe() +{ + typeset -i ctime=$(command date -d "$(command stat -c '%z' ${1})" +'%s') + typeset -i now=$(command date -d now +'%s') + if ((now - ctime < 86400)) ; then + return 1 + fi + return 0 +} + +_osc_complete_prepare() { + local xdg_dir + for xdg_dir in "${XDG_CACHE_HOME:=$HOME/.cache}" "${XDG_CONFIG_HOME:=$HOME/.config}"; do + if [[ ! -d "${xdg_dir}" ]]; then + mkdir -p "${xdg_dir}" + fi + done + + if [[ -f ~/.osc.projects ]]; then + rm ~/.osc.projects -f + fi +} + +_osc_update_project_list() { + if [[ -s "${osc_projects}" ]] ; then + if _osc_call_me_maybe "$osc_projects" ; then + if tmp=$(mktemp ${osc_projects}.XXXXXX) ; then + command ${osc_cmd} ls / >| $tmp + mv -uf $tmp ${osc_projects} + fi + fi + else + command ${osc_cmd} ls / >| "${osc_projects}" + fi +} + _osc_cmd_getbinaries() { _arguments \ - '1:PROJECT:( `echo $OSC_PROJECTS` )' \ + '1:PROJECT:( `cat $osc_projects` )' \ '2:PACKAGE:(PACKAGE)' \ '3:REPOSITORY:( `echo $OSC_BUILD_TARGETS` )' \ '4:ARCHITECTURE:(i586 x86_64)' @@ -78,7 +158,7 @@ _osc_cmd_getbinaries() { _osc_cmd_checkout() { _arguments \ - '1:PROJECT:( `echo $OSC_PROJECTS` )' \ + '1:PROJECT:( `cat $osc_projects` )' \ '2:PACKAGE:(PACKAGE)' } From 09bfa0a9b512f94ffab11c0fc968f038cb8b0de0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Bidar?= Date: Thu, 20 Jul 2023 15:34:43 +0300 Subject: [PATCH 03/10] Parse pwd's apiurl in zsh completion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Björn Bidar --- contrib/osc.zsh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/contrib/osc.zsh b/contrib/osc.zsh index 1d7c43e00c..8c1148ffac 100644 --- a/contrib/osc.zsh +++ b/contrib/osc.zsh @@ -37,6 +37,18 @@ _osc() { osc_alias=internal fi + if [ -s "${PWD}/.osc/_apiurl" -a -s "${osc_rc}" ]; then + local osc_apiurl + read osc_apiurl < "${PWD}/.osc/_apiurl" + # We prefer to match an apiurl with an alias so that the project list + # cache would match also when -A was passed with said alias. + # If there's no alias for that api url match to use the plain apiurl instead. + osc_alias=$(sed -rn '\@^\['${apiurl}'@,\@=@{\@^aliases=@{s@[^=]+=([^,]+),.*@\1@p};}' < "${osc_rc}" 2> /dev/null) + if [ -z $osc_alias ] ; then + osc_alias=${osc_apiurl} + fi + fi + if (( CURRENT > 2 )) && [[ ${words[2]} != "help" ]]; then # Remember the subcommand name local cmd=${words[2]} @@ -74,8 +86,8 @@ _osc() { fi if [[ -n "$osc_alias" ]] ; then - osc_projects="${osc_projects}.${osc_alias}" - osc_command="$osc_command -A $osc_alias" + osc_projects="${osc_projects}.${osc_alias//\//_}" + osc_command="$osc_command -A ${osc_alias}" fi _osc_update_project_list From cb47bed4c3eff336b6cc8462c771a22353ab8223 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Bidar?= Date: Fri, 21 Jul 2023 17:57:18 +0300 Subject: [PATCH 04/10] Fetch project repositories list for zsh completion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Björn Bidar --- contrib/osc.zsh | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/contrib/osc.zsh b/contrib/osc.zsh index 8c1148ffac..67afbc2f89 100644 --- a/contrib/osc.zsh +++ b/contrib/osc.zsh @@ -9,20 +9,10 @@ # # Toggle verbose completions: zstyle ':completion:*:osc:*' verbose no # zstyle ':completion:*:osc-subcommand:*' verbose no -# -# Use the variables $ZSH_OSC_BUILD_TARGETS_EXTRA and $ZSH_OSC_PROJECTS_EXTRA to -# extend the list of possible completions in your ~/.zshrc like that: -# export OSC_PROJECTS_EXTRA="Base:System Base:shells" # # version 0.2 # -OSC_BUILD_TARGETS="openSUSE_13.1 openSUSE_13.2 openSUSE_Tumbleweed openSUSE_Factory SLE_11_SP3 SLE_12" - -# user defined variables $OSC_BUILD_TARGETS_EXTRA and -# $OSC_PROJECTS_EXTRA can add to the project/build target list -OSC_BUILD_TARGETS="$OSC_BUILD_TARGETS $ZSH_OSC_BUILD_TARGETS_EXTRA" - # Main dispatcher _osc() { @@ -160,11 +150,25 @@ _osc_update_project_list() { fi } +_osc_project_repositories() { + if [ ! -s $PWD/.osc/_build_repositories ] || \ + _osc_call_me_maybe $PWD/.osc/_build_repositories ; then + osc repositories > /dev/null + fi + # Just check if file exist in case the call to the api failed + if [ -s $PWD/.osc/_build_repositories ] ; then + cat $PWD/.osc/_build_repositories | while read build_repository ; do + # Only output first word of each line + echo ${build_repository%\ *} + done | sort -u + fi +} + _osc_cmd_getbinaries() { _arguments \ '1:PROJECT:( `cat $osc_projects` )' \ '2:PACKAGE:(PACKAGE)' \ - '3:REPOSITORY:( `echo $OSC_BUILD_TARGETS` )' \ + '3:REPOSITORY:( `_osc_project_repositories`' \ '4:ARCHITECTURE:(i586 x86_64)' } @@ -176,7 +180,7 @@ _osc_cmd_checkout() { _osc_cmd_buildlog() { _arguments \ - '1:REPOSITORY:( `echo $OSC_BUILD_TARGETS` )' \ + '1:REPOSITORY:( `_osc_project_repositories` )' \ '2:ARCHITECTURE:(i586 x86_64)' } From 3082605144da12cfd37809626bc60c512de2bc40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Bidar?= Date: Fri, 21 Jul 2023 21:50:05 +0300 Subject: [PATCH 05/10] Match more command aliases in the zsh completion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Björn Bidar --- contrib/osc.zsh | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/contrib/osc.zsh b/contrib/osc.zsh index 67afbc2f89..244a23556e 100644 --- a/contrib/osc.zsh +++ b/contrib/osc.zsh @@ -82,17 +82,13 @@ _osc() { _osc_update_project_list - if [ "$cmd" = "submitreq" -o "$cmd" = "sr" ]; then - _osc_cmd_submitreq - elif [ "$cmd" = "getbinaries" ]; then - _osc_cmd_getbinaries - elif [ "$cmd" = "checkout" -o "$cmd" = "co" -o "$cmd" = "branch" ]; then - _osc_cmd_checkout - elif [ "$cmd" = "buildlog" -o "$cmd" = "buildinfo" -o "$cmd" = "bl" ]; then - _osc_cmd_buildlog - else - _osc_cmd_do $cmd - fi + case $cmd in + submitrequest|submitreq|sr) _osc_cmd_submitreq ;; + getbinaries) _osc_cmd_getbinaries ;; + checkout|co|branch|getpac|bco|branchco) _osc_cmd_checkout ;; + buildlog|buildinfo|bl|blt|buildlogtail) _osc_cmd_buildlog ;; + *) _osc_cmd_do $cmd + esac else local hline local -a cmdlist From 2ec50ad939faa20f163ac0e53ded186ade6e2e7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Bidar?= Date: Fri, 21 Jul 2023 23:09:51 +0300 Subject: [PATCH 06/10] Refactor help text generation in zsh completition so it can be reused MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Björn Bidar --- contrib/osc.zsh | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/contrib/osc.zsh b/contrib/osc.zsh index 244a23556e..f6e1978c2a 100644 --- a/contrib/osc.zsh +++ b/contrib/osc.zsh @@ -181,12 +181,16 @@ _osc_cmd_buildlog() { } _osc_cmd_submitreq() { + _osc_complete_help_commands 'options' 'option' +} + +_osc_complete_help_commands() { local hline local -a cmdlist local tag=0 _call_program help-commands osc help $cmd | while read -A hline; do # start parsing from "usage:" - [[ $hline[1] = "usage:" ]] && tag=1 + [[ $hline[1] = "${1}:" ]] && tag=1 [[ $tag = 0 ]] && continue if [[ $hline[1] =~ ^osc ]]; then @@ -198,40 +202,26 @@ _osc_cmd_submitreq() { (( ${#hline} < 2 )) && continue - cmdlist=($cmdlist "${hline[1]%,}:${hline[2,-1]}") + cmdlist=($cmdlist "${hline[1]%,}:${hline[2,-1]}") done - - _describe -t osc-commands 'osc command' cmdlist -} + if [ -n "$cmdlist" ] ; then + _describe -t osc-commands "osc $2" cmdlist + else + return 1 + fi +} _osc_cmd_do() { - local hline - local -a cmdlist - local tag=0 - # only start completion if there's some '-' on the line if ! [ "$words[2]" = "-" ]; then - _complete - return + _complete + return fi - _call_program help-commands osc help $cmd | while read -A hline; do - # start parsing from "Options:" - [[ $hline[1] = "Options:" ]] && tag=1 - [[ $tag = 0 ]] && continue - # Option has to start with a '-' - [[ $hline[1] =~ ^- ]] || continue - (( ${#hline} < 2 )) && continue - - cmdlist=($cmdlist "${hline[1]%,}:${hline[2,-1]}") - done - - if [ -n "$cmdlist" ]; then - _describe -t osc-commands 'osc command' cmdlist - else - _complete + if ! _osc_complete_help_commands 'options' 'option'; then + _complete fi } From 18bdf2e9b4ef82cb967d9a465fdec9e5668f575c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Bidar?= Date: Fri, 21 Jul 2023 23:20:23 +0300 Subject: [PATCH 07/10] Complete help text for options that have separate handlers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Björn Bidar --- contrib/osc.zsh | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/contrib/osc.zsh b/contrib/osc.zsh index f6e1978c2a..8ac714c88a 100644 --- a/contrib/osc.zsh +++ b/contrib/osc.zsh @@ -161,23 +161,38 @@ _osc_project_repositories() { } _osc_cmd_getbinaries() { - _arguments \ - '1:PROJECT:( `cat $osc_projects` )' \ - '2:PACKAGE:(PACKAGE)' \ - '3:REPOSITORY:( `_osc_project_repositories`' \ - '4:ARCHITECTURE:(i586 x86_64)' + if [ "$words[2]" = "-" ]; then + _osc_complete_help_commands 'options' 'option' + return + else + _arguments \ + '1:PROJECT:( `cat $osc_projects` )' \ + '2:PACKAGE:(PACKAGE)' \ + '3:REPOSITORY:( `_osc_project_repositories`' \ + '4:ARCHITECTURE:(i586 x86_64)' + fi } _osc_cmd_checkout() { - _arguments \ - '1:PROJECT:( `cat $osc_projects` )' \ - '2:PACKAGE:(PACKAGE)' + if [ "$words[2]" = "-" ]; then + _osc_complete_help_commands 'options' 'option' + return + else + _arguments \ + '1:PROJECT:( `cat $osc_projects` )' \ + '2:PACKAGE:(PACKAGE)' + fi } _osc_cmd_buildlog() { - _arguments \ - '1:REPOSITORY:( `_osc_project_repositories` )' \ - '2:ARCHITECTURE:(i586 x86_64)' + if [ "$words[2]" = "-" ]; then + _osc_complete_help_commands 'options' 'option' + return + else + _arguments \ + '1:REPOSITORY:( `_osc_project_repositories` )' \ + '2:ARCHITECTURE:(i586 x86_64)' + fi } _osc_cmd_submitreq() { From 513fd3664fdaee848ff9a01c2bf654677025a580 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Bidar?= Date: Fri, 21 Jul 2023 23:45:45 +0300 Subject: [PATCH 08/10] Fetch repository architectures in zsh completition MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Björn Bidar --- contrib/osc.zsh | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/contrib/osc.zsh b/contrib/osc.zsh index 8ac714c88a..7d495a1c37 100644 --- a/contrib/osc.zsh +++ b/contrib/osc.zsh @@ -160,16 +160,35 @@ _osc_project_repositories() { fi } +_osc_project_repositories_arches() { + if [ ! -s $PWD/.osc/_build_repositories ] || \ + _osc_call_me_maybe $PWD/.osc/_build_repositories ; then + osc repositories > /dev/null + fi + # Just check if file exist in case the call to the api failed + if [ -s $PWD/.osc/_build_repositories ] ; then + grep -- $1 $PWD/.osc/_build_repositories | while read build_repository ; do + # Only output second word of each line + echo ${build_repository#*\ } + done | sort -u + fi +} + + _osc_cmd_getbinaries() { if [ "$words[2]" = "-" ]; then _osc_complete_help_commands 'options' 'option' return else + if [ -n "$words[2]" ] ; then + local osc_project_repository_arch=$(_osc_project_repositories_arches \ + "${words[2]}") + fi _arguments \ '1:PROJECT:( `cat $osc_projects` )' \ '2:PACKAGE:(PACKAGE)' \ '3:REPOSITORY:( `_osc_project_repositories`' \ - '4:ARCHITECTURE:(i586 x86_64)' + '4:ARCHITECTURE:(`echo $osc_project_repository_arch`)' fi } @@ -189,9 +208,13 @@ _osc_cmd_buildlog() { _osc_complete_help_commands 'options' 'option' return else + if [ -n "$words[2]" ] ; then + local osc_project_repository_arch=$(_osc_project_repositories_arches \ + "${words[2]}") + fi _arguments \ '1:REPOSITORY:( `_osc_project_repositories` )' \ - '2:ARCHITECTURE:(i586 x86_64)' + '2:ARCHITECTURE:(`echo $osc_project_repository_arch`)' fi } From a1396e62be40127803c27f8b7a0b2ff89df936b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Bidar?= Date: Sat, 22 Jul 2023 00:54:39 +0300 Subject: [PATCH 09/10] Add zsh completion for build command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Björn Bidar --- contrib/osc.zsh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/contrib/osc.zsh b/contrib/osc.zsh index 7d495a1c37..10bfc32e89 100644 --- a/contrib/osc.zsh +++ b/contrib/osc.zsh @@ -85,6 +85,7 @@ _osc() { case $cmd in submitrequest|submitreq|sr) _osc_cmd_submitreq ;; getbinaries) _osc_cmd_getbinaries ;; + build) _osc_cmd_build ;; checkout|co|branch|getpac|bco|branchco) _osc_cmd_checkout ;; buildlog|buildinfo|bl|blt|buildlogtail) _osc_cmd_buildlog ;; *) _osc_cmd_do $cmd @@ -218,6 +219,22 @@ _osc_cmd_buildlog() { fi } +_osc_cmd_build() { + if [ "$words[2]" = "-" ]; then + _osc_complete_help_commands 'options' 'option' + return + else + if [ -n "$words[2]" ] ; then + local osc_project_repository_arch=$(_osc_project_repositories_arches \ + "${words[2]}") + fi + _arguments \ + '1:REPOSITORY:( `_osc_project_repositories` )' \ + '2:ARCHITECTURE:(`echo $osc_project_repository_arch`)' \ + '3:Build Description:_files' + fi +} + _osc_cmd_submitreq() { _osc_complete_help_commands 'options' 'option' } From ba075d0012d040593bef16c15a933de3c0efe176 Mon Sep 17 00:00:00 2001 From: Daniel Mach Date: Tue, 25 Jul 2023 08:07:10 +0200 Subject: [PATCH 10/10] spec: Install zsh completion --- contrib/osc.spec | 3 +++ 1 file changed, 3 insertions(+) diff --git a/contrib/osc.spec b/contrib/osc.spec index 18569a258f..78596e99e6 100644 --- a/contrib/osc.spec +++ b/contrib/osc.spec @@ -10,6 +10,7 @@ %define completion_dir_bash %{_datadir}/bash-completion/completions %define completion_dir_csh %{_sysconfdir}/profile.d %define completion_dir_fish %{_datadir}/fish/vendor_completions.d +%define completion_dir_zsh %{_datadir}/zsh/functions/Completion %define osc_plugin_dir %{_prefix}/lib/osc-plugins # need to override python_sitelib because it is not set as we would expect on many distros %define python_sitelib %(RPM_BUILD_ROOT= %{use_python} -Ic "import sysconfig; print(sysconfig.get_path('purelib'))") @@ -150,6 +151,7 @@ install -Dm0755 contrib/osc.complete %{buildroot}%{_datadir}/osc/complete install -Dm0644 contrib/complete.csh %{buildroot}%{completion_dir_csh}/osc.csh install -Dm0644 contrib/complete.sh %{buildroot}%{completion_dir_bash}/osc.sh install -Dm0644 contrib/osc.fish %{buildroot}%{completion_dir_fish}/osc.fish +install -Dm0644 contrib/osc.zsh %{buildroot}%{completion_dir_zsh}/osc.zsh # install rpm macros install -Dm0644 macros.osc %{buildroot}%{_rpmmacrodir}/macros.osc @@ -191,6 +193,7 @@ install -Dm0644 osc.1 %{buildroot}%{_mandir}/man1/osc.1 %{completion_dir_bash}/* %{completion_dir_csh}/* %{completion_dir_fish}/* +%{completion_dir_zsh}/* # osc owns the dirs to avoid the "directories not owned by a package" build error %dir %{_datadir}/fish