This commit is contained in:
Sinkerine 2018-03-24 11:58:43 -04:00
commit 2aa7c82de3
9 changed files with 241 additions and 12 deletions

View file

@ -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).

View file

@ -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).'

View file

@ -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.]:<varname>=<value>: " \
'--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 "<project name>.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]' \

View file

@ -21,3 +21,5 @@ 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'
alias dcstart='docker-compose start'

View file

@ -21,6 +21,7 @@ jira new # opens a new issue
jira dashboard # opens your JIRA dashboard
jira reported [username] # queries for issues reported by a user
jira assigned [username] # queries for issues assigned to a user
jira branch # opens an existing issue matching the current branch name
jira ABC-123 # opens an existing issue
jira ABC-123 m # opens an existing issue for adding a comment
```

View file

@ -60,7 +60,7 @@ function jira() {
else
# Anything that doesn't match a special action is considered an issue name
# but `branch` is a special case that will parse the current git branch
if [[ "$action" == "br" ]]; then
if [[ "$action" == "branch" ]]; then
local issue_arg=$(git rev-parse --abbrev-ref HEAD)
local issue="${jira_prefix}${issue_arg}"
else

View file

@ -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:
```
(<logo>|<cluster>:<namespace>)
```
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

View file

@ -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}"
}

View file

@ -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'
@ -20,7 +23,6 @@ alias kccc='k config current-context'
# Pod management.
alias kgp='k get pods'
alias klp='k logs pods'
alias kep='k edit pods'
alias kdp='k describe pods'
alias kdelp='k delete pods'
@ -48,3 +50,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'