Skip to content
Snippets Groups Projects
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
Branches
No related tags found
No related merge requests found
_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
......@@ -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'
......
......@@ -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
......
......@@ -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:
......
This diff is collapsed.
......@@ -10,8 +10,8 @@ curl = curl --location --silent --fail
download = $(curl) --output $@
all: binaries vendored generated
vendored: .config/pythonrc.py .bash_completion.d/aws .bash_completion.d/docker-compose .bash_completion.d/docker-machine.bash .bash_completion.d/docker-machine.bash .travis/travis.sh .bash_completion.d/molecule
generated: .ssh/config .bash_completion.d/helm .bash_completion.d/kops .bash_completion.d/kubectl .bash_completion.d/kompose .bash_completion.d/minikube .bash_completion.d/pipenv .bash_completion.d/pandoc .bash_completion.d/skaffold
vendored: .config/pythonrc.py .bash_completion.d/aws .bash_completion.d/docker-compose .bash_completion.d/docker-machine.bash .bash_completion.d/docker-machine.bash .travis/travis.sh .bash_completion.d/molecule Documents/bin/rabbitmqadmin .bash_completion.d/google-cloud-sdk
generated: .ssh/config .bash_completion.d/helm .bash_completion.d/kops .bash_completion.d/kubectl .bash_completion.d/kompose .bash_completion.d/minikube .bash_completion.d/pipenv .bash_completion.d/pandoc .bash_completion.d/skaffold .bash_completion.d/rabbitmqadmin
binaries: $(DESTDIR)/share/bfg/bfg.jar $(DESTDIR)/bin/rke $(DESTDIR)/bin/docker-machine $(DESTDIR)/bin/packer $(DESTDIR)/bin/terraform $(DESTDIR)/bin/vault $(DESTDIR)/bin/kubectl $(DESTDIR)/bin/kops $(DESTDIR)/bin/kompose $(DESTDIR)/bin/minikube $(DESTDIR)/bin/docker-machine-driver-kvm2 $(DESTDIR)/bin/kustomize $(DESTDIR)/bin/pack $(DESTDIR)/bin/skaffold
......@@ -125,6 +125,15 @@ $(DESTDIR)/bin/skaffold:
mkdir -p $$(dirname $@)
$(download) https://raw.githubusercontent.com/ansible/molecule/1.25.1/asset/bash_completion/molecule.bash-completion.sh
Documents/bin/rabbitmqadmin:
mkdir -p $$(dirname $@)
$(download) https://raw.githubusercontent.com/rabbitmq/rabbitmq-management/master/bin/rabbitmqadmin
chmod +x $@
.bash_completion.d/google-cloud-sdk:
mkdir -p $$(dirname $@)
$(download) https://raw.githubusercontent.com/google-cloud-sdk/google-cloud-sdk/master/completion.bash.inc
## Generated files
......@@ -163,3 +172,7 @@ $(DESTDIR)/bin/skaffold:
.bash_completion.d/pandoc:
mkdir -p $$(dirname $@)
-pandoc --bash-completion > $@
.bash_completion.d/rabbitmqadmin: Documents/bin/rabbitmqadmin
mkdir -p $$(dirname $@)
Documents/bin/rabbitmqadmin --bash-completion > $@
......@@ -11,9 +11,11 @@ dnspython
docker-compose
docker-py
Glances
gsutil
gunicorn
httpbin
httpie
importlab
khal
khard
mycli
......@@ -30,6 +32,7 @@ pygments
pymongo
PyMySQL
pyopenssl
remarshal
requests
sh
template
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment