From 9f76dc077736a1d86dce6f19d32258182fbfbd22 Mon Sep 17 00:00:00 2001 From: Werner Fink Date: Thu, 19 Dec 2013 15:38:45 +0100 Subject: [PATCH 1/2] Do not strip colon from COMP_WORDBREAKS (bnc#915037) Work around the libreadline colon trouble if COMP_WORDBREAKS includes the colon as regular word break. Side effect is that user now do not see the full project name anymore but only the subprojects. Signed-off-by: Werner Fink --- dist/complete.sh | 1 - dist/osc.complete | 27 ++++++++++++++++----------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/dist/complete.sh b/dist/complete.sh index 77156add..6148b40e 100644 --- a/dist/complete.sh +++ b/dist/complete.sh @@ -1,7 +1,6 @@ test -z "$BASH_VERSION" && return complete -o default _nullcommand >/dev/null 2>&1 || return complete -r _nullcommand >/dev/null 2>&1 || return -COMP_WORDBREAKS="${COMP_WORDBREAKS//:}" test -s /usr/share/osc/complete && complete -o default -C /usr/share/osc/complete osc test -s /usr/lib64/osc/complete && complete -o default -C /usr/lib64/osc/complete osc test -s /usr/lib/osc/complete && complete -o default -C /usr/lib/osc/complete osc diff --git a/dist/osc.complete b/dist/osc.complete index 173699fc..6c53b6b7 100644 --- a/dist/osc.complete +++ b/dist/osc.complete @@ -6,7 +6,6 @@ # # usage with bash # -# COMP_WORDBREAKS="${COMP_WORDBREAKS//:}" # complete -C osc.complete osc # # Author: Werner Fink @@ -35,8 +34,10 @@ if test "/proc/$PPID/exe" -ef /bin/tcsh ; then let colon=0 else COMMAND_LINE="${COMP_LINE:0:$COMP_POINT}" -# let colon=1 let colon=0 + case "$COMP_WORDBREAKS" in + *:*) let colon=1 + esac [[ $COMMAND_LINE =~ \\: ]] && COMMAND_LINE="${COMMAND_LINE//\\:/:}" fi IFS="${IFS}=" @@ -104,7 +105,7 @@ projects () local -a list local -a argv local -i argc=0 - local arg + local arg cur for arg; do if test $arg == "--" ; then let argc++ @@ -113,15 +114,18 @@ projects () argv[argc++]=$arg done shift $argc - if test -n "$1" ; then - list=($(command grep -E "^$1" ~/.osc.projects)) + cur="$1" + if test -n "${cur}" ; then + list=($(command grep -E "^${cur}" ~/.osc.projects)) else list=($(command cat ~/.osc.projects)) fi if ((colon)) ; then - builtin compgen -W "${list[*]}" "$1"|sed -r 's@([^\\]):@\1\\:@g' + local colon_word + colon_word=${cur%${cur##*:}} + builtin compgen -W "${list[*]}" -- "${cur}" | sed -r "s@^${colon_word}@@g" else - builtin compgen -W "${list[*]}" -- ${1+"$@"} + builtin compgen -W "${list[*]}" -- "${cur}" fi } @@ -130,7 +134,7 @@ packages () local -a list local -a argv local -i argc=0 - local arg + local arg cur for arg; do if test $arg == "--" ; then let argc++ @@ -139,12 +143,13 @@ packages () argv[argc++]=$arg done shift $argc - if test -n "$1" ; then - list=($(command osc ls ${argv[@]}|command grep -E "^$1")) + cur="$1" + if test -n "${cur}" ; then + list=($(command osc ls ${argv[@]}|command grep -E "^${cur}")) else list=($(command osc ls ${argv[@]})) fi - builtin compgen -W "${list[*]}" -- ${1+"$@"} + builtin compgen -W "${list[*]}" -- "${cur}" } repositories () From e2699d9fc3e517b536149a69ff02a2258e7c3c18 Mon Sep 17 00:00:00 2001 From: Werner Fink Date: Tue, 5 May 2015 13:47:08 +0200 Subject: [PATCH 2/2] Allow osc to be called as isc and iosc Signed-off-by: Werner Fink --- dist/osc.complete | 84 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 63 insertions(+), 21 deletions(-) mode change 100644 => 100755 dist/osc.complete diff --git a/dist/osc.complete b/dist/osc.complete old mode 100644 new mode 100755 index 6c53b6b7..903d7c54 --- a/dist/osc.complete +++ b/dist/osc.complete @@ -43,7 +43,10 @@ fi IFS="${IFS}=" cmdline=($COMMAND_LINE) IFS="$OIFS" -test "${cmdline[0]}" != "osc" && exit 1 +case "${cmdline[0]}" in +iosc|isc|osc) ;; +*) exit 1 +esac let last=${#COMMAND_LINE} let last-- @@ -80,24 +83,64 @@ oscprj="" oscpkg="" lnkprj="" lnkpkg="" +apiurl="" +alias="" test -s ${PWD}/.osc/_project && read -t 1 oscprj < ${PWD}/.osc/_project test -s ${PWD}/.osc/_package && read -t 1 oscpkg < ${PWD}/.osc/_package if test -s ${PWD}/.osc/_files ; then lnkprj=$(command sed -rn '/ /dev/null) +fi +if test "${cmdline[0]}" = isc ; then + alias=internal +fi -if test -s ~/.osc.projects ; then - typeset -i ctime=$(command date -d "$(command stat -c '%z' ~/.osc.projects)" +'%s') +projects=~/.osc.projects +command=osc + +case "${cmdline[1]}" in +-A|--apiurl) + if test -n "${cmdline[2]}" -a -s ~/.oscrc ; then + hints=($(sed -rn '/^(aliases=|\[http)/{s/,/ /g;s/(aliases=|\[|\])//gp}' < ~/.oscrc 2> /dev/null)) + for h in ${hints[@]} ; do + case "$h" in + http*) + tmp=$(sed -rn '\@^\['${h}'@,\@=@{\@^aliases=@{s@[^=]+=([^,]+),.*@\1@p};}' < ~/.oscrc 2> /dev/null) + if test "${cmdline[2]}" = "$h" ; then + alias=$tmp + break + fi + ;; + *) + if test "${cmdline[2]}" = "$h" ; then + alias=$h + break + fi + esac + done + fi +esac + +if test -n "$alias" ; then + projects="${projects}.${alias}" + command="$command -A $alias" +fi + +if test -s "${projects}" ; then + typeset -i ctime=$(command date -d "$(command stat -c '%z' ${projects})" +'%s') typeset -i now=$(command date -d now +'%s') if ((now - ctime > 86400)) ; then - if tmp=$(mktemp ~/.osc.projects.XXXXXX) ; then - command osc ls / >| $tmp - mv -uf $tmp ~/.osc.projects + if tmp=$(mktemp ${projects}.XXXXXX) ; then + command ${command} ls / >| $tmp + mv -uf $tmp ${projects} fi fi else - command osc ls / >| ~/.osc.projects + command ${command} ls / >| "${projects}" fi projects () @@ -116,9 +159,9 @@ projects () shift $argc cur="$1" if test -n "${cur}" ; then - list=($(command grep -E "^${cur}" ~/.osc.projects)) + list=($(command grep -E "^${cur}" ${projects})) else - list=($(command cat ~/.osc.projects)) + list=($(command cat ${projects})) fi if ((colon)) ; then local colon_word @@ -145,9 +188,9 @@ packages () shift $argc cur="$1" if test -n "${cur}" ; then - list=($(command osc ls ${argv[@]}|command grep -E "^${cur}")) + list=($(command ${command} ls ${argv[@]}|command grep -E "^${cur}")) else - list=($(command osc ls ${argv[@]})) + list=($(command ${command} ls ${argv[@]})) fi builtin compgen -W "${list[*]}" -- "${cur}" } @@ -167,11 +210,11 @@ repositories () done shift $argc if test -n "$1" ; then - list=($(command osc meta prj ${argv[@]}|\ + list=($(command ${command} meta prj ${argv[@]}|\ command sed -rn '//{s@^\s*(.*)@\1@p}'|\ command sort -u|command grep -E "^$1")) else - list=($(command osc meta prj ${argv[@]}|\ + list=($(command ${command} meta prj ${argv[@]}|\ command sed -rn '//{s@^\s*(.*)@\1@p}'|\ command sort -u)) fi @@ -228,8 +271,8 @@ targets () users () { - if test -s ~/.osc.projects ; then - command sed -rn "/^home:$1/{ s/^home:([^:]*):.*/\1/p}" ~/.osc.projects|command sort -u + if test -s ${projects} ; then + command sed -rn "/^home:$1/{ s/^home:([^:]*):.*/\1/p}" ${projects}|command sort -u elif test -s ~/.oscrc; then command sed -rn '/^(user=)/{s/(user=)//p}' ~/.oscrc|command sort -u else @@ -355,7 +398,7 @@ add|addremove|ar) fi ;; build) - opts=(--help --oldpackages --disable-cpio-bulk-download --download-api-only --release --baselibs + opts=(--help --oldpackages --disable-cpio-bulk-download --release --baselibs --disable-debuginfo --debuginfo --alternative-project --vm-type --linksources --local-package --build-uid --userootforbuild --define --without --with --ccache --icecream --jobs --root --extra-pkgs --keep-pkgs --prefer-pkgs @@ -442,9 +485,8 @@ build) done fi if ((count == 2)) ; then - specs=($(command ls *.spec 2>/dev/null)) - images=($(command ls *.kiwi 2>/dev/null)) - builtin compgen -W "${opts[*]} ${specs[*]} ${images[*]}" -- "${cmdline[count]}" + specs=($(command ls *.spec)) + builtin compgen -W "${opts[*]} ${specs[*]}" -- "${cmdline[count]}" fi ;; branch|getpac|bco|branchco)