summaryrefslogtreecommitdiff
path: root/public/zsh/.zshrc
blob: 0a0074ab50930c35f350ff75d90cb6cf42cf8097 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# ft=shell
#zmodload zsh/zprof

source /etc/zsh/antigen.zsh
antigen init $HOME/.antigenrc

autoload -U compinit promptinit
compinit

if [ "$(uname -s)" = "Linux" ] && [ -f "/etc/gentoo-release" ]; then
    # Gentoo specific auto-completion
    promptinit; prompt gentoo
fi

HISTFILE="${HOME}/.zsh_history"
HISTSIZE=1000
SAVEHIST=1000
setopt EXTENDED_HISTORY          # Write the history file in the ":start:elapsed;command" format.
setopt INC_APPEND_HISTORY        # Write to the history file immediately, not when the shell exits.
setopt SHARE_HISTORY             # Share history between all sessions.
setopt HIST_EXPIRE_DUPS_FIRST    # Expire duplicate entries first when trimming history.
setopt HIST_IGNORE_DUPS          # Don't record an entry that was just recorded again.
setopt HIST_IGNORE_ALL_DUPS      # Delete old recorded entry if new entry is a duplicate.
setopt HIST_FIND_NO_DUPS         # Do not display a line previously found.
setopt HIST_IGNORE_SPACE         # Don't record an entry starting with a space.
setopt HIST_SAVE_NO_DUPS         # Don't write duplicate entries in the history file.
setopt HIST_REDUCE_BLANKS        # Remove superfluous blanks before recording entry.
setopt HIST_VERIFY               # Don't execute immediately upon history expansion.

CASE_SENSITIVE="true"

DISABLE_UPDATE_PROMPT="true"
export UPDATE_ZSH_DAYS=7

# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS="true"

# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"

# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"

# Uncomment the following line to enable command auto-correction.
ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for completion.
COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"
plugins=(git fzf zsh-autosuggestions zsh-kubectl-prompt vi-mode)

# neovim
export EDITOR="nvim"

# kube prompt
zstyle ':zsh-kubectl-prompt:' namespace true # show namespace
function kube_prompt_info() {
  if ! [[ "$ZSH_KUBECTL_PROMPT" == *"current-context is not set"* ]]; then
    # remove all the aws junk
    cluster_ns=$(echo ${ZSH_KUBECTL_PROMPT} | sed 's/^arn.*:cluster\///')
    echo -n "%{$fg[cyan]%}(⎈ ${cluster_ns})%{$reset_color%}"
  fi
}
KUBE_RPROMPT="\$(kube_prompt_info)"

# aws prompt
function aws_prompt_info() {
  if ! [ -z "$AWS_PROFILE" ]; then
    echo -n "%{$fg[yellow]%}(☁️ ${AWS_PROFILE})%{$reset_color%}"
  fi
}
AWS_RPROMPT="\$(aws_prompt_info)"

# vi mode
# only if not in vim
if ! [ -n "$VIMRUNTIME" ]; then
  bindkey -v
  VI_MODE_SET_CURSOR=true
  VI_MODE_RESET_PROMPT_ON_MODE_CHANGE=true
  VI_MODE_RPROMPT="\$(vi_mode_prompt_info)"
  # map jk to escape
  bindkey jk vi-cmd-mode
  MODE_INDICATOR="%F{red}(V)%f"
else
  VI_MODE_RPROMPT=""
fi

# Set RPROMPT with my plugins and stuff
RPROMPT="${AWS_RPROMPT}${KUBE_RPROMPT}${VI_MODE_RPROMPT}"

# User configuration
ZSH_AUTOSUGGEST_USE_ASYNC=true

ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=8"

# Disable bracketed-paste-magic among other things
# https://github.com/ohmyzsh/ohmyzsh/issues/5569
DISABLE_MAGIC_FUNCTIONS=true

# FZF
#source "${HOMEBREW_PREFIX}/opt/fzf/shell/completion.zsh"
#source "${HOMEBREW_PREFIX}/opt/fzf/shell/key-bindings.zsh"
export FZF_TMUX_OPTS='-d 40%'
bindkey "ç" fzf-cd-widget


# gcloud completion
if [ -f "${HOMEBREW_PREFIX}/share/google-cloud-sdk/path.zsh.inc" ]; then
    source "${HOMEBREW_PREFIX}/share/google-cloud-sdk/path.zsh.inc"
fi
if [ -f "${HOMEBREW_PREFIX}/share/google-cloud-sdk/completion.zsh.inc" ]; then
    source "${HOMEBREW_PREFIX}/share/google-cloud-sdk/completion.zsh.inc"
fi

# Hack to prevent tmux starting on some terminal emulators
# NO_TMUX is a hash of value=variable pairs, when the variable matches the value,
# tmux will not be started.
#typeset -A NO_TMUX
#NO_TMUX[JetBrains-JediTerm]="TERMINAL_EMULATOR" # Intellij
#NO_TMUX[com.apple.Terminal]="__CFBundleIdentifier"
#NO_TMUX[screen]="TERM"

#TMUX_DEFAULT_SESSION=main
#RUN_TMUX=true
#for k v in ${(@kv)NO_TMUX}; do
  #if [ "${(P)v}" = "${k}" ]; then
    #RUN_TMUX=false
  #fi
#done

#if [ "$RUN_TMUX" = true ]; then
    #[ -z "$TMUX" ] && tmux new-session -As ${TMUX_DEFAULT_SESSION}
#fi