From f68d65d32a4fce41f08ac229614b7e46baf5e916 Mon Sep 17 00:00:00 2001 From: Mitchel Humpherys Date: Fri, 11 Jun 2021 21:09:08 -0700 Subject: feat(take): add support to `take' for taking remote urls (#2029) Download, extract, and cd into the resulting directory. Co-authored-by: Mitchel Humpherys --- lib/functions.zsh | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/functions.zsh b/lib/functions.zsh index c4340f16c..9cc735196 100644 --- a/lib/functions.zsh +++ b/lib/functions.zsh @@ -13,7 +13,7 @@ function upgrade_oh_my_zsh() { omz update } -function take() { +function takedir() { mkdir -p $@ && cd ${@:$#} } @@ -37,6 +37,30 @@ function open_command() { ${=open_cmd} "$@" &>/dev/null } +function takeurl() { + data=$(mktemp) + curl -L $1 > $data + tar xf $data + thedir=$(tar tf $data | head -1) + rm $data + cd $thedir +} + +function takegit() { + git clone $1 + cd $(basename ${1%%.git}) +} + +function take() { + if [[ $1 =~ ^(https?|ftp).*\.tar\.(gz|bz2|xz)$ ]]; then + takeurl $1 + elif [[ $1 =~ ^([A-Za-z0-9]\+@|https?|git|ssh|ftps?|rsync).*\.git/?$ ]]; then + takegit $1 + else + takedir $1 + fi +} + # # Get the value of an alias. # -- cgit v1.2.3-70-g09d2 From 5152d381bb828a4ed41fdbb430eb05970a8bb25c Mon Sep 17 00:00:00 2001 From: Stanisław Szydło Date: Sun, 13 Jun 2021 17:23:13 +0200 Subject: feat(kubectx): adding a new plugin for 'kubectx' (#6114) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marc Cornellà Co-authored-by: Robby Russell --- lib/prompt_info_functions.zsh | 1 + plugins/kubectx/README.md | 26 ++++++++++++++++++++++++++ plugins/kubectx/kubectx.plugin.zsh | 14 ++++++++++++++ plugins/kubectx/prod.png | Bin 0 -> 3834 bytes plugins/kubectx/stage.png | Bin 0 -> 3829 bytes 5 files changed, 41 insertions(+) create mode 100644 plugins/kubectx/README.md create mode 100644 plugins/kubectx/kubectx.plugin.zsh create mode 100644 plugins/kubectx/prod.png create mode 100644 plugins/kubectx/stage.png (limited to 'lib') diff --git a/lib/prompt_info_functions.zsh b/lib/prompt_info_functions.zsh index 48f033da6..e29fb27a5 100644 --- a/lib/prompt_info_functions.zsh +++ b/lib/prompt_info_functions.zsh @@ -19,6 +19,7 @@ function chruby_prompt_info \ virtualenv_prompt_info \ jenv_prompt_info \ tf_prompt_info \ + kubectx_prompt_info \ { return 1 } diff --git a/plugins/kubectx/README.md b/plugins/kubectx/README.md new file mode 100644 index 000000000..9a1df2617 --- /dev/null +++ b/plugins/kubectx/README.md @@ -0,0 +1,26 @@ +# kubectx - show active kubectl context + +This plugins adds ```kubectx_prompt_info()``` function. It shows name of the +active kubectl context (```kubectl config current-context```). + +You can use it to customize prompt and know if You are on prod cluster ;) + +_Example_. Add to **.zshrc**: + +``` +RPS1='$(kubectx_prompt_info)' +``` + +### custom ctx names + +One can rename default context name for better readability. + +_Example_. Add to **.zshrc**: +``` +kubectx_mapping[minikube] = "mini" +kubectx_mapping[context_name_from_kubeconfig]="$emoji[wolf_face]" +kubectx_mapping[production_cluster]="%{$fg[yellow]%}prod!%{$reset_color%}" +``` + +![staging](stage.png) +![production](prod.png) diff --git a/plugins/kubectx/kubectx.plugin.zsh b/plugins/kubectx/kubectx.plugin.zsh new file mode 100644 index 000000000..56b7217f1 --- /dev/null +++ b/plugins/kubectx/kubectx.plugin.zsh @@ -0,0 +1,14 @@ +typeset -A kubectx_mapping + +function kubectx_prompt_info() { + if [ $commands[kubectl] ]; then + local current_ctx=`kubectl config current-context` + + #if associative array declared + if [[ -n $kubectx_mapping ]]; then + echo "${kubectx_mapping[$current_ctx]}" + else + echo $current_ctx + fi + fi +} diff --git a/plugins/kubectx/prod.png b/plugins/kubectx/prod.png new file mode 100644 index 000000000..0c194a66d Binary files /dev/null and b/plugins/kubectx/prod.png differ diff --git a/plugins/kubectx/stage.png b/plugins/kubectx/stage.png new file mode 100644 index 000000000..ac15b3929 Binary files /dev/null and b/plugins/kubectx/stage.png differ -- cgit v1.2.3-70-g09d2 From e32d4b1e195f4c7777844beea97af42bd93434eb Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Thu, 17 Jun 2021 18:54:52 +0200 Subject: fix(lib): remove `kubectx` stub prompt function from lib Fixes #9974 --- lib/prompt_info_functions.zsh | 1 - 1 file changed, 1 deletion(-) (limited to 'lib') diff --git a/lib/prompt_info_functions.zsh b/lib/prompt_info_functions.zsh index e29fb27a5..48f033da6 100644 --- a/lib/prompt_info_functions.zsh +++ b/lib/prompt_info_functions.zsh @@ -19,7 +19,6 @@ function chruby_prompt_info \ virtualenv_prompt_info \ jenv_prompt_info \ tf_prompt_info \ - kubectx_prompt_info \ { return 1 } -- cgit v1.2.3-70-g09d2