Commit ddd1c558 authored by nimrod's avatar nimrod
Browse files

More CLI tooling.

- Vendored rabbitmqadmin, Bash completion.
- Use gsutil from PyPI, vendored Bash completion.
- Use gcloud from Snap, remove Docker aliases (it just for Linux
anyway).
- on-change, cw, mysqldump-loader Golang apps.
- importlab, remarshal Python apps.
parent e5995b9e
Loading
Loading
Loading
Loading
+82 −0
Original line number Diff line number Diff line
_python_argcomplete() {
    local IFS=''
    local prefix=
    typeset -i n
    (( lastw=${#COMP_WORDS[@]} -1))
    if [[ ${COMP_WORDS[lastw]} == --*=* ]]; then
        # for bash version 3.2
        flag=${COMP_WORDS[lastw]%%=*}
        set -- "$1" "$2" '='
    elif [[ $3 == '=' ]]; then
      flag=${COMP_WORDS[-3]}
    fi
    if [[ $3 == ssh  && $2 == *@* ]] ;then
        # handle ssh user@instance specially
        prefix=${2%@*}@
        COMP_LINE=${COMP_LINE%$2}"${2#*@}"
    elif [[ $3 == '=' ]] ; then
        # handle --flag=value
        prefix=$flag=$2
        line=${COMP_LINE%$prefix};
        COMP_LINE=$line${prefix/=/ };
        prefix=
    fi
    if [[ $2 == *,* ]]; then
          # handle , separated list
          prefix=${2%,*},
          set -- "$1" "${2#$prefix}" "$3"
          COMP_LINE==${COMP_LINE%$prefix*}$2
    fi
    # Treat --flag=<TAB> as --flag <TAB> to work around bash 4.x bug
    if [[ ${COMP_LINE} == *=  && ${COMP_WORDS[-2]} == --* ]]; then
        COMP_LINE=${COMP_LINE%=}' '
    fi
    COMPREPLY=( $(IFS="$IFS"                   COMP_LINE="$COMP_LINE"                   COMP_POINT="$COMP_POINT"                   _ARGCOMPLETE_COMP_WORDBREAKS="$COMP_WORDBREAKS"                   _ARGCOMPLETE=1                   "$1" 8>&1 9>&2 1>/dev/null 2>/dev/null) )
    if [[ $? != 0 ]]; then
        unset COMPREPLY
        return
    fi
    if [[ $prefix != '' ]]; then
        for ((n=0; n < ${#COMPREPLY[@]}; n++)); do
            COMPREPLY[$n]=$prefix${COMPREPLY[$n]}
        done
    fi
    for ((n=0; n < ${#COMPREPLY[@]}; n++)); do
        match=${COMPREPLY[$n]%' '}
        if [[ $match != '' ]]; then
            COMPREPLY[$n]=${match//? /' '}' '
        fi
    done
    # if flags argument has a single completion and ends in  '= ', delete ' '
    if [[ ${#COMPREPLY[@]} == 1 && ${COMPREPLY[0]} == -* &&
          ${COMPREPLY[0]} == *'= ' ]]; then
        COMPREPLY[0]=${COMPREPLY[0]%' '}
    fi
}
complete -o nospace -F _python_argcomplete "gcloud"

_completer() {
    command=$1
    name=$2
    eval '[[ "$'"${name}"'_COMMANDS" ]] || '"${name}"'_COMMANDS="$('"${command}"')"'
    set -- $COMP_LINE
    shift
    while [[ $1 == -* ]]; do
          shift
    done
    [[ $2 ]] && return
    grep -q "${name}\s*$" <<< $COMP_LINE &&
        eval 'COMPREPLY=($'"${name}"'_COMMANDS)' &&
        return
    [[ "$COMP_LINE" == *" " ]] && return
    [[ $1 ]] &&
        eval 'COMPREPLY=($(echo "$'"${name}"'_COMMANDS" | grep ^'"$1"'))'
}

unset bq_COMMANDS
_bq_completer() {
    _completer "CLOUDSDK_COMPONENT_MANAGER_DISABLE_UPDATE_CHECK=1 bq help | grep '^[^ ][^ ]*  ' | sed 's/ .*//'" bq
}

complete -F _bq_completer bq
complete -o nospace -F _python_argcomplete gsutil
+0 −3
Original line number Diff line number Diff line
@@ -108,9 +108,6 @@ alias torrent_off='ssh xbmc.shore.co.il sudo systemctl stop transmission-{rss,da
alias torrent_on='ssh xbmc.shore.co.il sudo systemctl start transmission-{daemon,rss}.service'
alias bell="printf '\\a'"
command -v notify-send > /dev/null || alias notify-send='bell'
alias __gcloud='docker run --rm -it -v "$HOME/.config/gcloud:/tmp/.config/gcloud" -e "HOME=/tmp" -u "$(id -u):$(id -g)" google/cloud-sdk:alpine'
alias gcloud='__gcloud gcloud'
alias gsutil='__gcloud gsutil'
alias detectproxy='w3m http://detectportal.firefox.com/success.txt'
alias color='less --raw-control-chars -p'
alias pip2='python2 -m pip'
+4 −0
Original line number Diff line number Diff line
@@ -5,9 +5,13 @@ echo Installing Golang apps >> /dev/stderr
go get github.com/giantswarm/semver-bump || true
go get github.com/nishanths/license || true
go get github.com/jmespath/jp || true
go get github.com/spelufo/on-change || true
go get github.com/kaorimatz/mysqldump-loader || true
go get github.com/lucagrulla/cw || true
go get sigs.k8s.io/kind || true
echo Installing Python apps >> /dev/stderr
python3 -m pip install --user --requirement requirements.txt
python2 -m pip install --user gsutil
echo Downloading binary and vendored files, creating generated files >> /dev/stderr
git clean -fX .bash_completion.d/
make all
+1 −1
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ repos:
    -   id: detect-private-key
    -   id: trailing-whitespace
    -   id: flake8
        exclude: pythonrc.py
        exclude: pythonrc.py|rabbitmqadmin
-   repo: https://www.shore.co.il/git/shell-pre-commit/
    rev: v0.6.0
    hooks:
+1150 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading