Box

Allgemein

Profil

Zsh for kubernetes okd » Historie » Zyklus 6

Peter Pfläging, 10.02.2023 09:18

1 3 Peter Pfläging
# Zsh for kubernetes okd
2 1 Peter Pfläging
3 2 Peter Pfläging
It's fine to see the actual kube oder oc env, the git status of the actual dir in the prompt:
4 3 Peter Pfläging
5 5 Peter Pfläging
![](zsh-prompt.png)
6 2 Peter Pfläging
7 5 Peter Pfläging
After the installation you can turn the prompt On or Off with `kubeon` or `kubeoff`
8 4 Peter Pfläging
9 2 Peter Pfläging
*   install `zsh`
10
    *   MacOS (it's there and OK)
11
    *   CentOS, RHEL, fedora: `sudo install -y zsh`
12
    *   Debian, Ubuntu, raspbian: `sudo apt install -y zsh`
13
    *   Windows? =Y You're kidding, use WSL2
14
*   change your login shell like: `usermod -s /bin/zsh $USER`
15
*   install ohmyz.sh: `sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"`
16
*   create a `~/.zshrc` with the following content:
17
    
18
    ~~~
19
    ZSH_DISABLE_COMPFIX=true
20
    export ZSH="$HOME/.oh-my-zsh"
21
    ZSH_THEME="agnoster"
22
    export KUBE_PS1_BINARY=oc
23
    export KUBE_PS1_SYMBOL_USE_IMG=true
24
    export KUBE_PS1_BG_COLOR=black
25
    export KUBE_PS1_SYMBOL_COLOR=red
26
    export KUBE_PS1_CTX_COLOR=blue
27 6 Peter Pfläging
28 1 Peter Pfläging
    function get_cluster_short() {
29 6 Peter Pfläging
     echo "$1" | sed 's&.*/api-\([^-]*\)-.*:6443/\(.*\)&\1/\2&'
30 2 Peter Pfläging
    }
31 1 Peter Pfläging
    KUBE_PS1_CLUSTER_FUNCTION=get_cluster_short
32
    if [[ -n $TERM_PROGRAM ]]; then
33 6 Peter Pfläging
      #we're on a macos
34
      plugins=(ansible bundler django docker docker-compose git iterm2 kubectl oc python ruby tmux rails themes kube-ps1 chezmoi)
35 1 Peter Pfläging
    else
36 6 Peter Pfläging
      # we're everywhere else
37
      plugins=(ansible bundler git kubectl oc python ruby tmux themes kube-ps1)
38 1 Peter Pfläging
    fi
39
    source $ZSH/oh-my-zsh.sh
40 2 Peter Pfläging
    if [[ -n $SSH_CONNECTION ]]; then
41 6 Peter Pfläging
      export EDITOR='emacs -nw'
42 1 Peter Pfläging
    else
43 6 Peter Pfläging
      export EDITOR='emacs -nw'
44 2 Peter Pfläging
    fi
45
    if [[ -d /Library ]]; then
46 6 Peter Pfläging
      #we're on a macos
47
      export JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-15.jdk/Contents/Home/
48 2 Peter Pfläging
    else
49 6 Peter Pfläging
      # we're everywhere else
50
      export EDITOR=vi
51 2 Peter Pfläging
    fi
52
    if command -v emacs &> /dev/null
53
    then
54 6 Peter Pfläging
      export EDITOR='emacs -nw'
55
      alias emacs='emacs -nw'
56 2 Peter Pfläging
    else
57 6 Peter Pfläging
      export EDITOR='vi'
58 2 Peter Pfläging
    fi
59
    export PATH=$PATH:$HOME/go/bin
60
    test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh"
61
    test -e "${HOME}/.zshrc_local" && source "${HOME}/.zshrc_local"
62
    export PROMPT='$(kube_ps1)'$PROMPT
63
    ~~~
64
    
65
*   for local mods, put them in `$HOME/.zshrc_local`
66
    
67
*   install `kubectl` and `oc`