From 2ff9560ad3fc6a3da256d34d0ba804b01d222293 Mon Sep 17 00:00:00 2001 From: Robby Russell Date: Fri, 23 Feb 2018 12:58:12 -0800 Subject: [PATCH 1/9] Adding link to our other open source projects page --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 541f48d40..a6d74cbd2 100644 --- a/README.md +++ b/README.md @@ -248,4 +248,4 @@ Oh My Zsh is released under the [MIT license](LICENSE.txt). ![Planet Argon](https://pa-github-assets.s3.amazonaws.com/PARGON_logo_digital_COL-small.jpg) -Oh My Zsh was started by the team at [Planet Argon](https://www.planetargon.com/?utm_source=github), a [Ruby on Rails development agency](https://www.planetargon.com/skills/ruby-on-rails-development?utm_source=github). +Oh My Zsh was started by the team at [Planet Argon](https://www.planetargon.com/?utm_source=github), a [Ruby on Rails development agency](https://www.planetargon.com/skills/ruby-on-rails-development?utm_source=github). Check out our [other open source projects](https://www.planetargon.com/open-source?utm_source=github). From 6d75f556e0f1d275d483746c84edb966de546f7e Mon Sep 17 00:00:00 2001 From: vadimkim Date: Fri, 9 Mar 2018 18:11:09 +0200 Subject: [PATCH 2/9] fix "kubectl logs" (#6667) logs doesn't have "pods" parameter --- plugins/kubectl/kubectl.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/kubectl/kubectl.plugin.zsh b/plugins/kubectl/kubectl.plugin.zsh index 88177b5a0..913b65cca 100644 --- a/plugins/kubectl/kubectl.plugin.zsh +++ b/plugins/kubectl/kubectl.plugin.zsh @@ -20,7 +20,7 @@ alias kccc='k config current-context' # Pod management. alias kgp='k get pods' -alias klp='k logs pods' +alias klp='k logs' alias kep='k edit pods' alias kdp='k describe pods' alias kdelp='k delete pods' From 52c4e134cc9e6348ebbcd5ba73501f903b57102b Mon Sep 17 00:00:00 2001 From: Nikolay Panov Date: Fri, 9 Mar 2018 08:11:30 -0800 Subject: [PATCH 3/9] Update django.plugin.zsh (#6634) Added support for 'showmigrations' django command. --- plugins/django/django.plugin.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/django/django.plugin.zsh b/plugins/django/django.plugin.zsh index 35865a692..29a51d29d 100644 --- a/plugins/django/django.plugin.zsh +++ b/plugins/django/django.plugin.zsh @@ -349,6 +349,7 @@ _managepy-commands() { 'runfcgi:Run this project as a fastcgi (or some other protocol supported by flup) application,' 'runserver:Starts a lightweight Web server for development.' 'shell:Runs a Python interactive interpreter.' + 'showmigrations:Shows all available migrations for the current project.' 'sql:Prints the CREATE TABLE SQL statements for the given app name(s).' 'sqlall:Prints the CREATE TABLE, custom SQL and CREATE INDEX SQL statements for the given model module name(s).' 'sqlclear:Prints the DROP TABLE SQL statements for the given app name(s).' From 84e90669847771344ec949c4c2a775882c519624 Mon Sep 17 00:00:00 2001 From: Andrew Matheny Date: Fri, 9 Mar 2018 11:11:52 -0500 Subject: [PATCH 4/9] Update docker-compose autocompletion (#6607) --- plugins/docker-compose/_docker-compose | 38 ++++++++++++++++++++------ 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/plugins/docker-compose/_docker-compose b/plugins/docker-compose/_docker-compose index 2947cef38..c0a54cced 100644 --- a/plugins/docker-compose/_docker-compose +++ b/plugins/docker-compose/_docker-compose @@ -3,11 +3,6 @@ # Description # ----------- # zsh completion for docker-compose -# https://github.com/sdurrheimer/docker-compose-zsh-completion -# ------------------------------------------------------------------------- -# Version -# ------- -# 1.5.0 # ------------------------------------------------------------------------- # Authors # ------- @@ -199,7 +194,9 @@ __docker-compose_subcommand() { (build) _arguments \ $opts_help \ + "*--build-arg=[Set build-time variables for one service.]:=: " \ '--force-rm[Always remove intermediate containers.]' \ + '--memory[Memory limit for the build container.]' \ '--no-cache[Do not use cache when building the image.]' \ '--pull[Always attempt to pull a newer version of the image.]' \ '*:services:__docker-compose_services_from_build' && ret=0 @@ -207,13 +204,16 @@ __docker-compose_subcommand() { (bundle) _arguments \ $opts_help \ + '--push-images[Automatically push images for any services which have a `build` option specified.]' \ '(--output -o)'{--output,-o}'[Path to write the bundle file to. Defaults to ".dab".]:file:_files' && ret=0 ;; (config) _arguments \ $opts_help \ '(--quiet -q)'{--quiet,-q}"[Only validate the configuration, don't print anything.]" \ - '--services[Print the service names, one per line.]' && ret=0 + '--resolve-image-digests[Pin image tags to digests.]' \ + '--services[Print the service names, one per line.]' \ + '--volumes[Print the volume names, one per line.]' && ret=0 ;; (create) _arguments \ @@ -242,7 +242,7 @@ __docker-compose_subcommand() { $opts_help \ '-d[Detached mode: Run command in the background.]' \ '--privileged[Give extended privileges to the process.]' \ - '--user=[Run the command as this user.]:username:_users' \ + '(-u --user)'{-u,--user=}'[Run the command as this user.]:username:_users' \ '-T[Disable pseudo-tty allocation. By default `docker-compose exec` allocates a TTY.]' \ '--index=[Index of the container if there are multiple instances of a service \[default: 1\]]:index: ' \ '(-):running services:__docker-compose_runningservices' \ @@ -252,6 +252,12 @@ __docker-compose_subcommand() { (help) _arguments ':subcommand:__docker-compose_commands' && ret=0 ;; + (images) + _arguments \ + $opts_help \ + '-q[Only display IDs]' \ + '*:services:__docker-compose_services_all' && ret=0 + ;; (kill) _arguments \ $opts_help \ @@ -308,16 +314,17 @@ __docker-compose_subcommand() { (run) _arguments \ $opts_help \ + $opts_no_deps \ '-d[Detached mode: Run container in the background, print new container name.]' \ '*-e[KEY=VAL Set an environment variable (can be used multiple times)]:environment variable KEY=VAL: ' \ '--entrypoint[Overwrite the entrypoint of the image.]:entry point: ' \ '--name=[Assign a name to the container]:name: ' \ - $opts_no_deps \ '(-p --publish)'{-p,--publish=}"[Publish a container's port(s) to the host]" \ '--rm[Remove container after run. Ignored in detached mode.]' \ "--service-ports[Run command with the service's ports enabled and mapped to the host.]" \ '-T[Disable pseudo-tty allocation. By default `docker-compose run` allocates a TTY.]' \ '(-u --user)'{-u,--user=}'[Run as specified username or uid]:username or uid:_users' \ + '(-v --volume)*'{-v,--volume=}'[Bind mount a volume]:volume: ' \ '(-w --workdir)'{-w,--workdir=}'[Working directory inside the container]:workdir: ' \ '(-):services:__docker-compose_services' \ '(-):command: _command_names -e' \ @@ -340,6 +347,11 @@ __docker-compose_subcommand() { $opts_timeout \ '*:running services:__docker-compose_runningservices' && ret=0 ;; + (top) + _arguments \ + $opts_help \ + '*:running services:__docker-compose_runningservices' && ret=0 + ;; (unpause) _arguments \ $opts_help \ @@ -385,9 +397,17 @@ _docker-compose() { integer ret=1 typeset -A opt_args + local file_description + + if [[ -n ${words[(r)-f]} || -n ${words[(r)--file]} ]] ; then + file_description="Specify an override docker-compose file (default: docker-compose.override.yml)" + else + file_description="Specify an alternate docker-compose file (default: docker-compose.yml)" + fi + _arguments -C \ '(- :)'{-h,--help}'[Get help]' \ - '(-f --file)'{-f,--file}'[Specify an alternate docker-compose file (default: docker-compose.yml)]:file:_files -g "*.yml"' \ + '*'{-f,--file}"[${file_description}]:file:_files -g '*.yml'" \ '(-p --project-name)'{-p,--project-name}'[Specify an alternate project name (default: directory name)]:project name:' \ '--verbose[Show more output]' \ '(- :)'{-v,--version}'[Print version and exit]' \ From 7c2028e84ede1ece09fa2dd13b5b6d8ba59ddfd1 Mon Sep 17 00:00:00 2001 From: Luke Date: Fri, 9 Mar 2018 09:12:42 -0700 Subject: [PATCH 5/9] Update/add kubectl logging commands (#6639) --- plugins/kubectl/kubectl.plugin.zsh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/kubectl/kubectl.plugin.zsh b/plugins/kubectl/kubectl.plugin.zsh index 913b65cca..a29773ee9 100644 --- a/plugins/kubectl/kubectl.plugin.zsh +++ b/plugins/kubectl/kubectl.plugin.zsh @@ -20,7 +20,6 @@ alias kccc='k config current-context' # Pod management. alias kgp='k get pods' -alias klp='k logs' alias kep='k edit pods' alias kdp='k describe pods' alias kdelp='k delete pods' @@ -48,3 +47,7 @@ alias krsd='k rollout status deployment' alias kgrs='k get rs' alias krh='k rollout history' alias kru='k rollout undo' + +# Logs +alias kl='k logs' +alias klf='k logs -f' From afad3e1f8d7b50b30493918912cd823c0e458780 Mon Sep 17 00:00:00 2001 From: Andrea Giardini Date: Fri, 9 Mar 2018 17:14:09 +0100 Subject: [PATCH 6/9] Add kubectl alias for apply (#6662) --- plugins/kubectl/kubectl.plugin.zsh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/kubectl/kubectl.plugin.zsh b/plugins/kubectl/kubectl.plugin.zsh index a29773ee9..97e429aac 100644 --- a/plugins/kubectl/kubectl.plugin.zsh +++ b/plugins/kubectl/kubectl.plugin.zsh @@ -9,6 +9,9 @@ fi # This command is used ALOT both below and in daily life alias k=kubectl +# Apply a YML file +alias kaf='k apply -f' + # Drop into an interactive terminal on a container alias keti='k exec -ti' From e6e2b3d42fc7e88d293d380f7861fa87e0856e62 Mon Sep 17 00:00:00 2001 From: Jon Mosco <1970496+jonmosco@users.noreply.github.com> Date: Fri, 9 Mar 2018 11:14:36 -0500 Subject: [PATCH 7/9] kube-ps1 zsh prompt helper (#6507) --- plugins/kube-ps1/README.md | 76 +++++++++++++++++++++ plugins/kube-ps1/kube-ps1.zsh | 123 ++++++++++++++++++++++++++++++++++ 2 files changed, 199 insertions(+) create mode 100644 plugins/kube-ps1/README.md create mode 100644 plugins/kube-ps1/kube-ps1.zsh diff --git a/plugins/kube-ps1/README.md b/plugins/kube-ps1/README.md new file mode 100644 index 000000000..a572773a3 --- /dev/null +++ b/plugins/kube-ps1/README.md @@ -0,0 +1,76 @@ +Kubernetes prompt for zsh +========================= + +A Kubernetes (k8s) zsh prompt that displays the current cluster cluster +and the namespace. + +Inspired by several tools used to simplify usage of kubectl + +NOTE: If you are not using zsh, check out [kube-ps1](https://github.com/jonmosco/kube-ps1) designed for bash +as well as zsh. + +## Requirements + +The default prompt assumes you have the kubectl command line utility installed. It +can be obtained here: + +[Install and Set up kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) + +If using this with OpenShift, the oc tool needs installed. It can be obtained from here: + +[OC Client Tools](https://www.openshift.org/download.html) + +## Helper utilities + +There are several great tools that make using kubectl very enjoyable. + +[kubectx and kubenx](https://github.com/ahmetb/kubectx) are great for +fast switching between clusters and namespaces. + +## Prompt Structure + +The prompt layout is: + +``` +(|:) +``` + +Supported platforms: +* k8s - Kubernetes +* ocp - OpenShift + +## Install + +1. Clone this repository +2. Source the kube-ps1.zsh in your ~./.zshrc + +ZSH: +``` +source path/kube-ps1.sh +PROMPT='$(kube_ps1) ' +``` + +## Colors + +The colors are of my opinion. Blue was used as the prefix to match the Kubernetes +color as closely as possible. Red was chosen as the cluster name to stand out, and cyan +for the namespace. These can of course be changed. + +## Customization + +The default settings can be overridden in ~/.zshrc + +| Variable | Default | Meaning | +| :------- | :-----: | ------- | +| `KUBE_PS1_DEFAULT` | `true` | Default settings for the prompt | +| `KUBE_PS1_PREFIX` | `(` | Prompt opening character | +| `KUBE_PS1_DEFAULT_LABEL` | `⎈ ` | Default prompt symbol | +| `KUBE_PS1_SEPERATOR` | `\|` | Separator between symbol and cluster name | +| `KUBE_PS1_PLATFORM` | `kubectl` | Cluster type and binary to use | +| `KUBE_PS1_DIVIDER` | `:` | Separator between cluster and namespace | +| `KUBE_PS1_SUFFIX` | `)` | Prompt closing character | +| `KUBE_PS1_DEFAULT_LABEL_IMG` | `false` | Use Kubernetes img as the label: ☸️ | + +## Contributors + +Jared Yanovich diff --git a/plugins/kube-ps1/kube-ps1.zsh b/plugins/kube-ps1/kube-ps1.zsh new file mode 100644 index 000000000..e1cb4339d --- /dev/null +++ b/plugins/kube-ps1/kube-ps1.zsh @@ -0,0 +1,123 @@ +#!/bin/zsh + +# Kubernetes prompt helper for bash/zsh +# Displays current context and namespace + +# Copyright 2017 Jon Mosco +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Debug +[[ -n $DEBUG ]] && set -x + +setopt PROMPT_SUBST +add-zsh-hook precmd _kube_ps1_load +zmodload zsh/stat + +# Default values for the prompt +# Override these values in ~/.zshrc or ~/.bashrc +KUBE_PS1_DEFAULT="${KUBE_PS1_DEFAULT:=true}" +KUBE_PS1_PREFIX="(" +KUBE_PS1_DEFAULT_LABEL="${KUBE_PS1_DEFAULT_LABEL:="⎈ "}" +KUBE_PS1_DEFAULT_LABEL_IMG="${KUBE_PS1_DEFAULT_LABEL_IMG:=false}" +KUBE_PS1_SEPERATOR="|" +KUBE_PS1_PLATFORM="${KUBE_PS1_PLATFORM:="kubectl"}" +KUBE_PS1_DIVIDER=":" +KUBE_PS1_SUFFIX=")" +KUBE_PS1_UNAME=$(uname) +KUBE_PS1_LAST_TIME=0 + +kube_ps1_label () { + + [[ "${KUBE_PS1_DEFAULT_LABEL_IMG}" == false ]] && return + + if [[ "${KUBE_PS1_DEFAULT_LABEL_IMG}" == true ]]; then + local KUBE_LABEL="☸️ " + fi + + KUBE_PS1_DEFAULT_LABEL="${KUBE_LABEL}" + +} + +_kube_ps1_split() { + type setopt >/dev/null 2>&1 && setopt SH_WORD_SPLIT + local IFS=$1 + echo $2 +} + +_kube_ps1_file_newer_than() { + + local mtime + local file=$1 + local check_time=$2 + mtime=$(stat +mtime "${file}") + + [ "${mtime}" -gt "${check_time}" ] + +} + +_kube_ps1_load() { + # kubectl will read the environment variable $KUBECONFIG + # otherwise set it to ~/.kube/config + KUBECONFIG="${KUBECONFIG:=$HOME/.kube/config}" + + for conf in $(_kube_ps1_split : "${KUBECONFIG}"); do + # TODO: check existence of $conf + if _kube_ps1_file_newer_than "${conf}" "${KUBE_PS1_LAST_TIME}"; then + _kube_ps1_get_context_ns + return + fi + done +} + +_kube_ps1_get_context_ns() { + + # Set the command time + KUBE_PS1_LAST_TIME=$(date +%s) + + if [[ "${KUBE_PS1_DEFAULT}" == true ]]; then + local KUBE_BINARY="${KUBE_PS1_PLATFORM}" + elif [[ "${KUBE_PS1_DEFAULT}" == false ]] && [[ "${KUBE_PS1_PLATFORM}" == "kubectl" ]];then + local KUBE_BINARY="kubectl" + elif [[ "${KUBE_PS1_PLATFORM}" == "oc" ]]; then + local KUBE_BINARY="oc" + fi + + KUBE_PS1_CONTEXT="$(${KUBE_BINARY} config current-context)" + KUBE_PS1_NAMESPACE="$(${KUBE_BINARY} config view --minify --output 'jsonpath={..namespace}')" + # Set namespace to default if it is not defined + KUBE_PS1_NAMESPACE="${KUBE_PS1_NAMESPACE:-default}" + +} + +# source our symbol +kube_ps1_label + +# Build our prompt +kube_ps1 () { + local reset_color="%f" + local blue="%F{blue}" + local red="%F{red}" + local cyan="%F{cyan}" + + KUBE_PS1="${reset_color}$KUBE_PS1_PREFIX" + KUBE_PS1+="${blue}$KUBE_PS1_DEFAULT_LABEL" + KUBE_PS1+="${reset_color}$KUBE_PS1_SEPERATOR" + KUBE_PS1+="${red}$KUBE_PS1_CONTEXT${reset_color}" + KUBE_PS1+="$KUBE_PS1_DIVIDER" + KUBE_PS1+="${cyan}$KUBE_PS1_NAMESPACE${reset_color}" + KUBE_PS1+="$KUBE_PS1_SUFFIX" + + echo "${KUBE_PS1}" + +} From ce23ef9a2fcd71d2428d886f83af09296537d8ac Mon Sep 17 00:00:00 2001 From: Lauri Lavanti Date: Fri, 9 Mar 2018 18:14:51 +0200 Subject: [PATCH 8/9] Add alias for docker-compose pull (#6665) --- plugins/docker-compose/docker-compose.plugin.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/docker-compose/docker-compose.plugin.zsh b/plugins/docker-compose/docker-compose.plugin.zsh index 4e4ac114a..d69769010 100644 --- a/plugins/docker-compose/docker-compose.plugin.zsh +++ b/plugins/docker-compose/docker-compose.plugin.zsh @@ -21,3 +21,4 @@ alias dcup='docker-compose up' alias dcdn='docker-compose down' alias dcl='docker-compose logs' alias dclf='docker-compose logs -f' +alias dcpull='docker-compose pull' From 7ed82b4df6d381ef26a4dbdf253bf414497adcd1 Mon Sep 17 00:00:00 2001 From: Quentin Revel Date: Sat, 10 Mar 2018 00:16:15 +0800 Subject: [PATCH 9/9] Update _docker-compose to latest version (#6315)