Skip to content

Instantly share code, notes, and snippets.

@naviat
Last active January 15, 2024 19:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save naviat/f868df1890f568ddabc24af7e9c662fe to your computer and use it in GitHub Desktop.
Save naviat/f868df1890f568ddabc24af7e9c662fe to your computer and use it in GitHub Desktop.
Dotfile for zsh
$ git clone https://github.com/awslabs/awscli-aliases.git
$ mkdir -p ~/.aws/cli
$ cp awscli-aliases/alias ~/.aws/cli/alias

Step by step

For AWS CLI ALIAS

  • Install aws cli
  • Copy file alias to ~/.aws/cli/ and use the alias: aws
git clone https://github.com/denysdovhan/spaceship-prompt.git "$ZSH_CUSTOM/themes/spaceship-prompt"
ln -s "$ZSH_CUSTOM/themes/spaceship-prompt/spaceship.zsh-theme" "$ZSH_CUSTOM/themes/spaceship.zsh-theme"

Utilities application

  • Ubuntu: python, ruby, golang, cowsay, fortune, figlet, bash-complete, tree, sublime-text, vscode, wget, curl, net-tools, gnupg, jq, kubectl, helm, terraform, zsh-syntax-highlighting zsh-autosuggestions, docker, docker-compose

Will update shell script for automation later.

  1. Install plug in
git clone https://github.com/zsh-users/zsh-completions ${ZSH_CUSTOM:=~/.oh-my-zsh/custom}/plugins/zsh-completions
git clone https://github.com/zsh-users/zsh-history-substring-search ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-history-substring-search
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git

# warhol
cd ~/.oh-my-zsh/custom/plugins/
git clone https://github.com/unixorn/warhol.plugin.zsh.git warhol
# brew
sudo apt-get install build-essential curl file git
git clone https://github.com/Homebrew/brew ~/.linuxbrew/Homebrew
mkdir ~/.linuxbrew/bin
ln -s ~/.linuxbrew/Homebrew/bin/brew ~/.linuxbrew/bin
eval $(~/.linuxbrew/bin/brew shellenv)

brew install peco
brew install stern


## TEMPLATE TO USE THEME ##
export ZSH=$HOME/.oh-my-zsh
TERM=xterm-256color
DISABLE_MAGIC_FUNCTIONS=true
ZSH_AUTOSUGGEST_MANUAL_REBIND=1
COMPLETION_WAITING_DOTS=true
DISABLE_UNTRACKED_FILES_DIRTY=true
DISABLE_AUTO_UPDATE=true
ZSH_THEME="spaceship"
plugins=(
git
yarn
git-extras
bundler
sudo
sublime
history
last-working-dir
compleat
zsh-completions
zsh-history-substring-search
zsh-autosuggestions
zsh-syntax-highlighting
warhol
python
colored-man-pages
pip
docker
docker-compose
docker-machine
emoji-clock
kube-ps1
npm
)
autoload -U compinit && compinit -d ~/.cache/zsh/zcompdump-$ZSH_VERSION
source $ZSH/oh-my-zsh.sh
bindkey '\e[A' history-beginning-search-backward
bindkey '\e[B' history-beginning-search-forward
source /home/hp/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
#Homebrew
export PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"
export PATH=$PATH:/usr/local/go/bin:${HOME}/go/bin
# Gem without sudo
# export GEM_HOME="$HOME/.gem"
PATH=$(ruby -e 'puts Gem.bindir'):$PATH
source $(dirname $(gem which colorls))/tab_complete.sh
#KUBE-PS1
source ~/kube-ps1.sh
PROMPT='$fg[cyan]%}$USER@%{$fg[blue]%}%m$(kube_ps1)'$PROMPT
function get_namespace_upper() {
echo "$1" | tr '[:lower:]' '[:upper:]'
}
export KUBE_PS1_NAMESPACE_FUNCTION=get_namespace_upper
## fzf config with ripgrep to preview file in search panel
#export FZF_BASE="/usr/local/bin"
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
export FZF_DEFAULT_OPTS='--height=70% --preview="bat {}" --preview-window=right:60%:wrap'
#export FZF_DEFAULT_COMMAND='rg --files'
#export FZF_CTRL_T_COMMAND='$FZF_DEFAULT_COMMAND'
### PECO configurartion for crt + r ####
function peco-select-history() {
local tac
if which tac > /dev/null; then
tac="tac"
else
tac="tail -r"
fi
BUFFER=$(\history -n 1 | \
eval $tac | \
awk '!_[$0]++' | \
peco --query "$LBUFFER")
CURSOR=$#BUFFER
zle clear-screen
}
zle -N peco-select-history
bindkey '^r' peco-select-history
# LANG
export LANG="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
alias git='LANG=en_GB git'
alias -g B='`git branch -a | peco --prompt "GIT BRANCH>" | head -n 1 | sed -e "s/^\*\s*//g"`'
alias -g R='`git reflog | peco | cut -d" " -f1`'
alias -g C='`git log --oneline | peco | cut -d" " -f1`'
#####################################
### Kubernetes ######################
#####################################
export KUBECTX_CURRENT_FGCOLOR=$(tput setaf 1) # Red text
export KUBECTX_CURRENT_BGCOLOR=$(tput setab 2) # Green background
export KUBE_EDITOR="nano"
alias k='kubectl'
alias kctx='kubectl ctx'
alias kns='kubectl ns'
alias kt='kubectl top'
alias ktn='kubectl top nodes'
alias ktp='kubectl top pods | sort --reverse --key=3 --numeric-sort'
alias kpac='kubectl-resource_capacity'
alias ktail='kubetail'
alias rbaclp='rbac-lookup'
alias kevent='kubectl get events --sort-by .metadata.creationTimestamp -w'
alias knodeIP="kubectl get no -o json | jq -r '.items[].status.addresses[] | select(.type=="InternalIP") | .address'"
alias knodeRs="kubectl get po --all-namespaces -o 'custom-columns=NAME:.metadata.name,IP:.status.hostIP,RES:.spec.containers[0].resources.requests' --sort-by .status.hostIP"
alias kpod="kubectl get po -o 'custom-columns=NAME:.metadata.name,HOSTIP:.status.hostIP,IP:.status.podIP,STATUS:.status.phase,NODE:.spec.nodeName' --sort-by .metadata.name"
function decode_kubernetes_secret {
kubectl get secret $@ -o json | jq '.data | map_values(@base64d)'
}
alias ds="decode_kubernetes_secret"
function getCIRD {
kubectl get nodes $1 -o go-template --template='{{range .spec.podCIDRs}}{{printf "%s\n" .}}{{end}}'
}
source <(kubectl completion zsh)
#Stern autocomplete
source <(stern --completion=zsh)
### PYTHON Configuration ###
alias python='python3'
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
if command -v pyenv 1>/dev/null 2>&1; then
\eval "$(pyenv init -)"
fi
### Terraform alias ###
alias tf='terraform'
# Clean out your Docker container/image
alias docker-clean-unused='docker system prune --all --force --volumes'
alias docker-clean-all='docker stop $(docker container ls -a -q) && docker system prune -a -f --volumes'
alias docker-clean-containers='docker container stop $(docker container ls -a -q) && docker container rm $(docker container ls -a -q)'
# View Docker Service status, usage: [command] <service name>
alias docker-service-ps="docker service ps --format 'table {{.ID}}\t{{.Name}}\t{{.Node}}\t{{.CurrentState}}'"
# View Network inspect for all container
alias docker-network-inspect="docker container inspect --format '{{json .NetworkSettings.Networks}}' $(docker container ls -lq) | jq '.'"
# View task running in swarm node, usage: [command] <node name>
alias docker-node-task="docker node ps --format 'table {{.ID}}\t{{.Name}}\t{{.Node}}\t{{.CurrentState}}'"
### TMUX ###
set -g status-position bottom
set -g status-bg colour237
set -g status-fg colour137
set -g status-attr dim
set -g status-left '#[fg=colour197]#(~/bin/internet_info.sh) #{tasks_status} '
set -g status-right '#[fg=colour81]♪ #(~/bin/now_playing.sh) #(~/bin/battery.sh) #[fg=colour255,bg=colour241,bold] %a %m-%d #[fg=colour255,bg=colour241,bold] %H:%M:%S #[fg=colour165]#[bg=default] #H '
set -g status-right-length 100
set -g status-left-length 70
### Alias
alias update="source ~/.zshrc"
alias c=clear
alias dbpp="docker build --progress=plain"
alias dia="docker images -a"
alias dps="docker ps -a"
# Krew for K8s
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
#### WELCOME ###
# Cow-spoken fortunes every time you open a terminal
# git clone https://github.com/bkendzior/cowfiles.git ~/.cowsay
function cowsayfortune {
NUMOFCOWS=`cowsay -l | tail -n +2 | wc -w`
WHICHCOW=$((RANDOM%$NUMOFCOWS+1))
THISCOW=`cowsay -l | tail -n +2 | sed -e 's/\ /\'$'\n/g' | sed $WHICHCOW'q;d'`
fortune | cowsay -f $THISCOW -W 100 | lolcat
}
cowsayfortune
## minikue #####
alias mk="minikube"
function fp() {
### PATH
# mnemonic: [F]ind [P]ath
# list directories in $PATH, press [enter] on an entry to list the executables inside.
# press [escape] to go back to directory listing, [escape] twice to exit completely
local loc=$(echo $PATH | sed -e $'s/:/\\\n/g' | eval "fzf ${FZF_DEFAULT_OPTS} --header='[find:path]'")
if [[ -d $loc ]]; then
echo "$(rg --files $loc | rev | cut -d"/" -f1 | rev)" | eval "fzf ${FZF_DEFAULT_OPTS} --header='[find:exe] => ${loc}' >/dev/null"
fp
fi
}
# Default to TMUX config
#
# This might be too clever. But it allows me to have multiple
# sessions opened and it will use the same windows. This really
# makes TMUX work like SCREEN.
if [ -z "$TMUX" ] && [ -z "$DISPLAY" ] && [ -z "$TERM_PROGRAM" ]; then
base_session="${USER}_session"
# Create a new session if it doesn't exist
tmux has-session -t $base_session || tmux new-session -d -s $base_session
client_cnt=$(tmux list-clients | wc -l)
# Are there any clients connected already?
if [ $client_cnt -ge 1 ]; then
client_id=0
session_name=$base_session"-"$client_id
while [ $(tmux has-session -t $session_name 2>& /dev/null; echo $?) -ne 1 ]; do
client_id=$((client_id+1))
session_name=$base_session"-"$client_id
done
tmux new-session -d -t $base_session -s $session_name
tmux -2 attach-session -t $session_name \; set-option destroy-unattached
else
tmux -2 attach-session -t $base_session
fi
fi
# File search functions
function f() { find . -iname "*$1*" ${@:2} }
function r() { grep "$1" ${@:2} -R . }
# Create a folder and move into it in one command
function mkcd() { mkdir -p "$@" && cd "$_"; }
# Enable the go modules feature
export GO111MODULE="on"
# Set the GOPROXY environment variable
export GOPROXY="https://goproxy.io,direct"
##########################################
alias pbcopy="xclip -sel clip"
alias o="nautilus"
alias lc='colorls -lA --sd'
alias l='ls -lahG'
alias go-vpn='nmcli con up id Linagora'
alias bye-vpn='nmcli con down id Linagora'
alias open='xdg-open'
export NVM_DIR="/home/hp/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
timezsh() {
shell=${1-$SHELL}
for i in $(seq 1 10); do /usr/bin/time $shell -i -c exit; done
}
## TEMPLATE TO USE THEME ##
export ZSH=$HOME/.oh-my-zsh
export DEFAULT_USER='haidv'
TERM=xterm-256color
DISABLE_MAGIC_FUNCTIONS=true
ZSH_AUTOSUGGEST_MANUAL_REBIND=1
COMPLETION_WAITING_DOTS=true
DISABLE_UNTRACKED_FILES_DIRTY=true
# Set name of the theme to load. Optionally, if you set this to "random"
# it'll load a random theme each time that oh-my-zsh is loaded.
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="powerlevel10k/powerlevel10k"
############ POWERLEVEL THEME SETTINGS ##############
POWERLEVEL9K_MODE='awesome-fontconfig'
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir vcs nvm)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(disk_usage time)
POWERLEVEL9K_PROMPT_ADD_NEWLINE=true
POWERLEVEL9K_PROMPT_ON_NEWLINE=true
POWERLEVEL9K_SHOW_RULER=true
POWERLEVEL9K_RULER_CHAR='─'
POWERLEVEL9K_RULER_BACKGROUND=none
POWERLEVEL9K_RULER_FOREGROUND=237
POWERLEVEL9K_LEFT_SEGMENT_END_SEPARATOR=
POWERLEVEL9K_LEFT_SEGMENT_SEPARATOR=
POWERLEVEL9K_LEFT_SUBSEGMENT_SEPARATOR=' '
POWERLEVEL9K_RIGHT_SEGMENT_END_SEPARATOR=
POWERLEVEL9K_RIGHT_SEGMENT_SEPARATOR=
POWERLEVEL9K_RIGHT_SUBSEGMENT_SEPARATOR=
POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS=
POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
POWERLEVEL9K_SHORTEN_STRATEGY="truncate_middle"
POWERLEVEL9K_DIR_SHOW_WRITABLE=true
POWERLEVEL9K_DISK_USAGE_NORMAL_BACKGROUND=none
POWERLEVEL9K_DISK_USAGE_WARNING_BACKGROUND=magenta
POWERLEVEL9K_DISK_USAGE_CRITICAL_BACKGROUND=red
POWERLEVEL9K_TIME_BACKGROUND=none
POWERLEVEL9K_TIME_FOREGROUND=white
POWERLEVEL9K_DIR_HOME_BACKGROUND=none
POWERLEVEL9K_DIR_HOME_SUBFOLDER_BACKGROUND=none
POWERLEVEL9K_DIR_ETC_BACKGROUND=none
POWERLEVEL9K_DIR_DEFAULT_BACKGROUND=none
POWERLEVEL9K_DIR_NOT_WRITABLE_BACKGROUND=none
POWERLEVEL9K_DIR_HOME_FOREGROUND=blue
POWERLEVEL9K_DIR_HOME_SUBFOLDER_FOREGROUND=blue
POWERLEVEL9K_DIR_ETC_FOREGROUND=blue
POWERLEVEL9K_DIR_DEFAULT_FOREGROUND=blue
POWERLEVEL9K_DIR_NOT_WRITABLE_FOREGROUND=red
POWERLEVEL9K_OS_ICON_BACKGROUND="white"
POWERLEVEL9K_OS_ICON_FOREGROUND="blue"
POWERLEVEL9K_VCS_GIT_ICON='%fon %F{040}\uf1d3 '
POWERLEVEL9K_VCS_GIT_GITHUB_ICON='%fon %F{040}\uf09b '
POWERLEVEL9K_VCS_GIT_BITBUCKET_ICON='%fon %F{040}\uf171 '
POWERLEVEL9K_VCS_GIT_GIT_GITLAB_ICON='%fon %F{040}\uf296 '
POWERLEVEL9K_VCS_CLEAN_BACKGROUND=none
POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND=none
POWERLEVEL9K_VCS_MODIFIED_BACKGROUND=none
POWERLEVEL9K_VCS_LOADING_BACKGROUND=none
POWERLEVEL9K_VCS_CLEAN_FOREGROUND="040"
POWERLEVEL9K_VCS_UNTRACKED_FOREGROUND="red"
POWERLEVEL9K_VCS_MODIFIED_FOREGROUND="yellow"
POWERLEVEL9K_VCS_LOADING_FOREGROUND="grey"
POWERLEVEL9K_VCS_UNTRACKED_ICON=$'%{\b?%}'
POWERLEVEL9K_VCS_UNSTAGED_ICON=$'%{\b!%}'
POWERLEVEL9K_VCS_STAGED_ICON=$'%{\b+%}'
POWERLEVEL9K_DIR_NOT_WRITABLE_VISUAL_IDENTIFIER_COLOR=red
POWERLEVEL9K_LOCK_ICON=$'\uf023'
POWERLEVEL9K_MULTILINE_FIRST_PROMPT_PREFIX=''
local p='%F{%(?.green.red)}${${${KEYMAP:-0}:#vicmd}:+❯}${${$((!${#${KEYMAP:-0}:#vicmd})):#0}:+❮}%f '
POWERLEVEL9K_MULTILINE_LAST_PROMPT_PREFIX="$p"
POWERLEVEL9K_NVM_BACKGROUND=none
POWERLEVEL9K_NVM_FOREGROUND=green
POWERLEVEL9K_NODE_ICON='%fvia %F{green}⬢'
############ END- POWERLEVEL THEME SETTINGS ##############
ENABLE_CORRECTION="false"
HIST_STAMPS="mm/dd/yyyy"
plugins=(
poetry
git
yarn
git-extras
bundler
osx
ruby
rvm
sudo
sublime
history
history-substring-search
last-working-dir
compleat zsh-completions
zsh-history-substring-search
zsh-autosuggestions
zsh-syntax-highlighting
zsh-syntax-highlighting-filetypes
warhol
zsh-kubernetes
nano
vagrant
python
colored-man
colorize
pip
docker
docker-compose
docker-machine
emoji-clock
vim
xcode
kube-ps1
npm
minikube
)
autoload -U compinit && compinit -d ~/.cache/zsh/zcompdump-$ZSH_VERSION
source $ZSH/oh-my-zsh.sh
PROMPT=$PROMPT'$(kube_ps1) '
bindkey '\e[A' history-beginning-search-backward
bindkey '\e[B' history-beginning-search-forward
export CLICOLOR=1
export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx
source '/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/path.zsh.inc'
source '/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/completion.zsh.inc'
### zsh highlight ###
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
### PECO configurartion for crt + r ####
function peco-select-history() {
local tac
if which tac > /dev/null; then
tac="tac"
else
tac="tail -r"
fi
BUFFER=$(\history -n 1 | \
eval $tac | \
peco --query "$LBUFFER")
CURSOR=$#BUFFER
zle clear-screen
}
zle -N peco-select-history
bindkey '^r' peco-select-history
### Set Git language to English ###
#alias git='LANG=en_US git'
alias git='LANG=en_GB git'
alias -g B='`git branch -a | peco --prompt "GIT BRANCH>" | head -n 1 | sed -e "s/^\*\s*//g"`'
alias -g R='`git reflog | peco | cut -d" " -f1`'
alias -g C='`git log --oneline | peco | cut -d" " -f1`'
alias -g o='open'
test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh"
### alias for make and make install gcc ###
# Usage: `mgcc make && mgcc make install`
alias -g mgcc='`CXX="g++ -Wno-unused-local-typedefs"`'
### Language for shell when start ###
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
### GOLANG Configuration ###
export GOPATH=$HOME/go
export PATH=$PATH:/User/haidv/go/bin
export PATH="/usr/local/sbin:$PATH"
export PATH=$PATH:$(go env GOPATH)/bin
export PATH=/usr/local/bin:$PATH
export GOPROXY=https://goproxy.io
#####################################
### Kubernetes ######################
#####################################
alias kctx='kubectx'
alias kns='kubens'
alias kt='kubectl top'
alias ktn='kubectl top nodes'
alias ktp='kubectl top pods'
### PYTHON Configuration ###
alias python='python3'
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
if command -v pyenv 1>/dev/null 2>&1; then
\eval "$(pyenv init -)"
fi
### Terraform alias ###
alias tf='terraform'
# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
export PATH=/usr/local/gcc-8.2/bin:$PATH
# Add Vault
export PATH="$PATH:/Applications"
autoload -U +X bashcompinit && bashcompinit
complete -o nospace -C /Applications/vault vault
# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
export PATH="$PATH:$HOME/.rvm/bin"
export PATH="/usr/local/sbin:$PATH"
# Clean out your Docker container/image
alias docker-clean-unused='docker system prune --all --force --volumes'
alias docker-clean-all='docker stop $(docker container ls -a -q) && docker system prune -a -f --volumes'
alias docker-clean-containers='docker container stop $(docker container ls -a -q) && docker container rm $(docker container ls -a -q)'
# View Docker Service status, usage: [command] <service name>
alias docker-service-ps="docker service ps --format 'table {{.ID}}\t{{.Name}}\t{{.Node}}\t{{.CurrentState}}'"
# View Network inspect for all container
alias docker-network-inspect="docker container inspect --format '{{json .NetworkSettings.Networks}}' $(docker container ls -lq) | jq '.'"
# View task running in swarm node, usage: [command] <node name>
alias docker-node-task="docker node ps --format 'table {{.ID}}\t{{.Name}}\t{{.Node}}\t{{.CurrentState}}'"
### TMUX ###
set -g status-position bottom
set -g status-bg colour237
set -g status-fg colour137
set -g status-attr dim
set -g status-left '#[fg=colour197]#(~/bin/internet_info.sh) #{tasks_status} '
set -g status-right '#[fg=colour81]♪ #(~/bin/now_playing.sh) #(~/bin/battery.sh) #[fg=colour255,bg=colour241,bold] %a %m-%d #[fg=colour255,bg=colour241,bold] %H:%M:%S #[fg=colour165]#[bg=default] #H '
set -g status-right-length 100
set -g status-left-length 70
#################
###### NANO ####
alias nano='/usr/local/Cellar/nano/4.8/bin/nano --tabstospaces'
############ AWS
export AWS_DEFAULT_PROFILE=haidv
export AWS_SDK_LOAD_CONFIG=true
### Alias
alias update="source ~/.zshrc"
alias c=clear
### Colorise the top Tabs of Iterm2 with the same color as background
echo -e "\033]6;1;bg;red;brightness;18\a"
echo -e "\033]6;1;bg;green;brightness;26\a"
echo -e "\033]6;1;bg;blue;brightness;33\a"
# Add this at the BOTTOM
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
# Load RVM into a shell session *as a function*
## Lazydocker
alias lzd='lazydocker'
export PATH="$PYENV_ROOT/versions/anaconda3-2019.03/bin/:$PATH"
alias dbpp="docker build --progress=plain"
alias dia="docker images -a"
alias dps="docker ps -a"
## GCLOUD
CLOUD_SDK_HOME=/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk
source "${CLOUD_SDK_HOME}/completion.zsh.inc"
# added by Anaconda3 5.3.0 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
\eval "$__conda_setup"
else
if [ -f "/anaconda3/etc/profile.d/conda.sh" ]; then
# . "/anaconda3/etc/profile.d/conda.sh" # commented out by conda initialize
CONDA_CHANGEPS1=false conda activate base
else
\export PATH="/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda init <<<
# added by Anaconda3 5.3.0 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/Users/haidv/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
\eval "$__conda_setup"
else
if [ -f "/Users/haidv/anaconda3/etc/profile.d/conda.sh" ]; then
# . "/Users/haidv/anaconda3/etc/profile.d/conda.sh" # commented out by conda initialize
CONDA_CHANGEPS1=false conda activate base
else
\export PATH="/Users/haidv/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda init <<<
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/Users/haidv/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/Users/haidv/anaconda3/etc/profile.d/conda.sh" ]; then
. "/Users/haidv/anaconda3/etc/profile.d/conda.sh"
else
export PATH="/Users/haidv/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
export PATH="/usr/local/sbin:$PATH"
export PATH="$HOME/.poetry/bin:$PATH"
function get_cluster_short() {
echo "$1" | cut -d . -f1
}
KUBE_PS1_CLUSTER_FUNCTION=get_cluster_short
function get_namespace_upper() {
echo "$1" | tr '[:lower:]' '[:upper:]'
}
export KUBE_PS1_NAMESPACE_FUNCTION=get_namespace_upper
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
## fzf config with ripgrep to preview file in search panel
export FZF_BASE="/usr/local/bin"
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
export FZF_DEFAULT_OPTS='--height=70% --preview="cat {}" --preview-window=right:60%:wrap'
#### WELCOME ###
# Cow-spoken fortunes every time you open a terminal
# git clone https://github.com/bkendzior/cowfiles.git ~/.cowsay
function cowsayfortune {
NUMOFCOWS=`cowsay -l | tail -n +2 | wc -w`
WHICHCOW=$((RANDOM%$NUMOFCOWS+1))
THISCOW=`cowsay -l | tail -n +2 | sed -e 's/\ /\'$'\n/g' | sed $WHICHCOW'q;d'`
#echo "Selected cow: ${THISCOW}, from ${WHICHCOW}"
fortune | cowsay -f $THISCOW -W 100 | lolcat
}
cowsayfortune
# fortune | cowsay -f daragon_and_cow | lolcat
################
## minikue #####
alias mk="minikube"
## TEMPLATE TO USE THEME ##
export ZSH=$HOME/.oh-my-zsh
SOBOLE_DEFAULT_USER='haidv'
TERM=xterm-256color
DISABLE_MAGIC_FUNCTIONS=true
ZSH_AUTOSUGGEST_MANUAL_REBIND=1
COMPLETION_WAITING_DOTS=true
DISABLE_UNTRACKED_FILES_DIRTY=true
ZSH_THEME="spaceship"
plugins=(
poetry
git
yarn
git-extras
bundler
osx
ruby
sudo
sublime
history
last-working-dir
compleat
zsh-completions
zsh-history-substring-search
zsh-autosuggestions
zsh-syntax-highlighting
warhol
zsh-kubernetes
vagrant
python
colored-man-pages
pip
docker
docker-compose
docker-machine
emoji-clock
xcode
kube-ps1
npm
)
autoload -U compinit && compinit -d ~/.cache/zsh/zcompdump-$ZSH_VERSION
source $ZSH/oh-my-zsh.sh
bindkey '\e[A' history-beginning-search-backward
bindkey '\e[B' history-beginning-search-forward
#export CLICOLOR=1
#export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx
source '/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/path.zsh.inc'
source '/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/completion.zsh.inc'
source /usr/local/Cellar/kube-ps1/0.7.0/share/kube-ps1.sh
PROMPT='$fg[cyan]%}$USER@%{$fg[blue]%}%m$(kube_ps1)'$PROMPT
function get_namespace_upper() {
echo "$1" | tr '[:lower:]' '[:upper:]'
}
export KUBE_PS1_NAMESPACE_FUNCTION=get_namespace_upper
### zsh highlight ###
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
## fzf config with ripgrep to preview file in search panel
#export FZF_BASE="/usr/local/bin"
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
#export FZF_DEFAULT_OPTS='--height=70% --preview="cat {}" --preview-window=right:60%:wrap'
#export FZF_DEFAULT_COMMAND='rg --files --no-ignore --hidden --follow --glob "!.git/*"'
### PECO configurartion for crt + r ####
function peco-select-history() {
local tac
if which tac > /dev/null; then
tac="tac"
else
tac="tail -r"
fi
BUFFER=$(\history -n 1 | \
eval $tac | \
awk '!_[$0]++' | \
peco --query "$LBUFFER")
CURSOR=$#BUFFER
zle clear-screen
}
zle -N peco-select-history
bindkey '^r' peco-select-history
### Set Git language to English ###
#alias git='LANG=en_US git'
alias git='LANG=en_GB git'
alias -g B='`git branch -a | peco --prompt "GIT BRANCH>" | head -n 1 | sed -e "s/^\*\s*//g"`'
alias -g R='`git reflog | peco | cut -d" " -f1`'
alias -g C='`git log --oneline | peco | cut -d" " -f1`'
alias -g o='open'
test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh"
### alias for make and make install gcc ###
# Usage: `mgcc make && mgcc make install`
alias -g mgcc='`CXX="g++ -Wno-unused-local-typedefs"`'
### Language for shell when start ###
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
### GOLANG Configuration ###
export GOPATH=$HOME/go
export PATH=$PATH:/User/haidv/go/bin
export PATH="/usr/local/sbin:$PATH"
export PATH=$PATH:$(go env GOPATH)/bin
export PATH=/usr/local/bin:$PATH
export GOPROXY=https://goproxy.io
#####################################
### Kubernetes ######################
#####################################
export KUBECTX_CURRENT_FGCOLOR=$(tput setaf 1) # Red text
export KUBECTX_CURRENT_BGCOLOR=$(tput setab 2) # Green background
export KUBE_EDITOR="nano"
alias kctx='kubectx'
alias kns='kubens'
alias kt='kubectl top'
alias ktn='kubectl top nodes'
alias ktp='kubectl top pods'
alias ktail='kubetail'
alias rbaclp='rbac-lookup'
alias kpac='kube-capacity'
alias kevent='kubectl get events --sort-by .metadata.creationTimestamp -w'
alias knodeIP="kubectl get no -o json | jq -r '.items[].status.addresses[] | select(.type=="InternalIP") | .address'"
alias knodeRs="kubectl get po --all-namespaces -o 'custom-columns=NAME:.metadata.name,IP:.status.hostIP,RES:.spec.containers[0].resources.requests' --sort-by .status.hostIP"
alias kpod="kubectl get po -o 'custom-columns=NAME:.metadata.name,HOSTIP:.status.hostIP,IP:.status.podIP,STATUS:.status.phase,NODE:.spec.nodeName' --sort-by .metadata.name"
function decode_kubernetes_secret {
kubectl get secret $@ -o json | jq '.data | map_values(@base64d)'
}
alias ds="decode_kubernetes_secret"
#Stern autocomplete
source <(stern --completion=zsh)
### PYTHON Configuration ###
alias python='python3'
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
if command -v pyenv 1>/dev/null 2>&1; then
\eval "$(pyenv init -)"
fi
### Terraform alias ###
alias tf='terraform'
# Add Vault
export PATH="$PATH:/Applications"
autoload -U +X bashcompinit && bashcompinit
complete -o nospace -C /Applications/vault vault
# Clean out your Docker container/image
alias docker-clean-unused='docker system prune --all --force --volumes'
alias docker-clean-all='docker stop $(docker container ls -a -q) && docker system prune -a -f --volumes'
alias docker-clean-containers='docker container stop $(docker container ls -a -q) && docker container rm $(docker container ls -a -q)'
# View Docker Service status, usage: [command] <service name>
alias docker-service-ps="docker service ps --format 'table {{.ID}}\t{{.Name}}\t{{.Node}}\t{{.CurrentState}}'"
# View Network inspect for all container
alias docker-network-inspect="docker container inspect --format '{{json .NetworkSettings.Networks}}' $(docker container ls -lq) | jq '.'"
# View task running in swarm node, usage: [command] <node name>
alias docker-node-task="docker node ps --format 'table {{.ID}}\t{{.Name}}\t{{.Node}}\t{{.CurrentState}}'"
### TMUX ###
set -g status-position bottom
set -g status-bg colour237
set -g status-fg colour137
set -g status-attr dim
set -g status-left '#[fg=colour197]#(~/bin/internet_info.sh) #{tasks_status} '
set -g status-right '#[fg=colour81]♪ #(~/bin/now_playing.sh) #(~/bin/battery.sh) #[fg=colour255,bg=colour241,bold] %a %m-%d #[fg=colour255,bg=colour241,bold] %H:%M:%S #[fg=colour165]#[bg=default] #H '
set -g status-right-length 100
set -g status-left-length 70
#################
###### NANO ####
#alias nano='/usr/local/Cellar/nano/4.9/bin/nano --tabstospaces'
############ AWS
# export AWS_DEFAULT_PROFILE=haidv
# export AWS_SDK_LOAD_CONFIG=true
### Alias
alias update="source ~/.zshrc"
alias c=clear
## Lazydocker
alias lzd='lazydocker'
alias dbpp="docker build --progress=plain"
alias dia="docker images -a"
alias dps="docker ps -a"
## GCLOUD
CLOUD_SDK_HOME=/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk
source "${CLOUD_SDK_HOME}/completion.zsh.inc"
export PATH="/usr/local/sbin:$PATH"
export PATH="$HOME/.poetry/bin:$PATH"
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
#### WELCOME ###
# Cow-spoken fortunes every time you open a terminal
# git clone https://github.com/bkendzior/cowfiles.git ~/.cowsay
function cowsayfortune {
NUMOFCOWS=`cowsay -l | tail -n +2 | wc -w`
WHICHCOW=$((RANDOM%$NUMOFCOWS+1))
THISCOW=`cowsay -l | tail -n +2 | sed -e 's/\ /\'$'\n/g' | sed $WHICHCOW'q;d'`
#echo "Selected cow: ${THISCOW}, from ${WHICHCOW}"
fortune | cowsay -f $THISCOW -W 100 | lolcat
}
cowsayfortune
## minikue #####
alias mk="minikube"
function fp() {
### PATH
# mnemonic: [F]ind [P]ath
# list directories in $PATH, press [enter] on an entry to list the executables inside.
# press [escape] to go back to directory listing, [escape] twice to exit completely
local loc=$(echo $PATH | sed -e $'s/:/\\\n/g' | eval "fzf ${FZF_DEFAULT_OPTS} --header='[find:path]'")
if [[ -d $loc ]]; then
echo "$(rg --files $loc | rev | cut -d"/" -f1 | rev)" | eval "fzf ${FZF_DEFAULT_OPTS} --header='[find:exe] => ${loc}' >/dev/null"
fp
fi
}
function tmuxify() {
### TMUX
# if installed:
# if not connected to an existing session, attach to it.
# if no session exists, create it and attach to it.
if hash tmux &> /dev/null; then
case $- in *i*)
[ -z "$TMUX" ] && tmux new -A -s $(whoami)
esac
else
fi
}
# File search functions
function f() { find . -iname "*$1*" ${@:2} }
function r() { grep "$1" ${@:2} -R . }
# Create a folder and move into it in one command
function mkcd() { mkdir -p "$@" && cd "$_"; }
# Bat with preview local folder
function seenow() {fzf --preview 'bat --style=numbers --color=always {} | head -500'}
# VMware Fusion command-line utils
export PATH=$PATH:"/Applications/VMware Fusion.app/Contents/Library"
## PUSH IT THE END OF FILE
export PATH="/usr/local/opt/ruby@2.7/bin:$PATH"
export PATH="$HOME/.cargo/bin:$PATH"
# Gem without sudo
export GEM_HOME="$HOME/.gem"
source $(dirname $(gem which colorls))/tab_complete.sh
alias lc='colorls -lA --sd'
alias l='ls -lahG'
#PATH=$(ruby -e 'puts Gem.bindir'):$PATH
# NVM to PATH and completion
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/Users/haidv/opt/anaconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/Users/haidv/opt/anaconda3/etc/profile.d/conda.sh" ]; then
. "/Users/haidv/opt/anaconda3/etc/profile.d/conda.sh"
else
export PATH="/Users/haidv/opt/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
conda config --set changeps1 False
export ZSH="/home/hp/.oh-my-zsh"
export DEFAULT_USER='haidv'
# export KUBECONFIG="~/.kube/config"
#ZSH_THEME="agnoster"
ZSH_THEME="powerlevel10k/powerlevel10k"
DISABLE_AUTO_UPDATE=true
plugins=(git docker docker-compose zsh-syntax-highlighting zsh-autosuggestions emoji-clock npm pip colorize colored-man-pages kubectl helm minikube kubetail)
source $ZSH/oh-my-zsh.sh
alias mk="minikube"
alias pbcopy="xclip -sel clip"
alias update="source ~/.zshrc"
alias c="clear"
alias o="nautilus"
alias tf='terraform'
# LANG
export LANG="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
# fzf
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
# PECO
function peco-select-history() {
local tac
if which tac > /dev/null; then
tac="tac"
else
tac="tail -r"
fi
BUFFER=$(\history -n 1 | \
eval $tac | \
awk '!_[$0]++' | \
peco --query "$LBUFFER")
CURSOR=$#BUFFER
zle clear-screen
}
zle -N peco-select-history
bindkey '^r' peco-select-history
# PECO alias
alias -g C='`git log --oneline | peco | cut -d" " -f1`'
alias -g R='`git reflog | peco | cut -d" " -f1`'
alias -g B='`git branch -a | peco --prompt "GIT BRANCH>" | head -n 1 | sed -e "s/^\*\s*//g"`'
## Docker alias ##
alias dia="docker images -a"
alias dps="docker ps -a"
alias docker-clean-unused='docker system prune --all --force --volumes'
alias docker-clean-all='docker stop $(docker container ls -a -q) && docker system prune -a -f --volumes'
alias docker-clean-containers='docker container stop $(docker container ls -a -q) && docker container rm $(docker container ls -a -q)'
alias docker-list-all-ip="docker ps -q | xargs -n 1 docker inspect --format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}} {{ .Name }}' | sed 's/ \// /'"
# View Docker Service status, usage: [command] <service name>
alias docker-service-ps="docker service ps --format 'table {{.ID}}\t{{.Name}}\t{{.Node}}\t{{.CurrentState}}'"
# View Network inspect for all container
alias docker-network-inspect="docker container inspect --format '{{json .NetworkSettings.Networks}}' $(docker container ls -lq) | jq '.'"
# View task running in swarm node, usage: [command] <node name>
alias docker-node-task="docker node ps --format 'table {{.ID}}\t{{.Name}}\t{{.Node}}\t{{.CurrentState}}'"
function dip() {
if [ -z $1 ]; then
docker ps -a --format "{{.ID}}" | while read -r line ; do
echo $line $(docker inspect --format "{{ .Name }} {{ .NetworkSettings.Networks.bridge.IPAddress }}" $line | sed 's/\///'):$(docker port "$line" | grep -o "0.0.0.0:.*" | cut -f2 -d:)
done
else
echo $(docker inspect --format "{{.ID }} {{ .Name }} {{ .NetworkSettings.Networks.bridge.IPAddress }}" $1 | sed 's/\///'):$(docker port "$1" | grep -o "0.0.0.0:.*" | cut -f2 -d:)
fi
}
# plugin
source /home/hp/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
### Kubernetes ######################
alias kctx='kubectl ctx'
alias kns='kubectl ns'
alias kt='kubectl top'
alias ktn='kubectl top nodes'
alias ktp='kubectl top pods'
alias kpac='kubectl-resource_capacity'
alias ktail='kubetail'
## Alias list all ec2
alias list_ec2='for region in `aws ec2 describe-regions --region us-east-1 --output text | cut -f3`
do
echo -e "\nListing Instances in region:'$region'..."
aws ec2 describe-instances --region $region
done'
### PYTHON Configuration ###
alias python='python3'
### Preview file
export FZF_DEFAULT_OPTS='--height=70% --preview="bat {}" --preview-window=right:60%:wrap'
#export FZF_DEFAULT_COMMAND='rg --files'
#export FZF_CTRL_T_COMMAND='$FZF_DEFAULT_COMMAND'
# fd - Find any directory and cd to selected directory
fd() {
local dir
dir=$(find ${1:-.} -path '*/\.*' -prune -o -type d \
-print 2> /dev/null | fzf +m) &&
cd "$dir"
}
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
# Git update
function gitupdate(){
git checkout master && git pull && git checkout - && git rebase master
}
# Krew for K8s
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
COWPATH="$COWPATH:$HOME/.cowsay"
# Cow-spoken fortunes every time you open a terminal
function cowsayfortune {
NUMOFCOWS=`cowsay -l | tail -n +2 | wc -w`
WHICHCOW=$((RANDOM%$NUMOFCOWS+1))
THISCOW=`cowsay -l | tail -n +2 | sed -e 's/\ /\'$'\n/g' | sed $WHICHCOW'q;d'`
#echo "Selected cow: ${THISCOW}, from ${WHICHCOW}"
fortune | cowsay -f $THISCOW -W 100 | lolcat
}
cowsayfortune
#Homebrew
export PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"
export PATH=$PATH:/usr/local/go/bin:${HOME}/go/bin
# Enable the go modules feature
export GO111MODULE="on"
# Set the GOPROXY environment variable
export GOPROXY="https://goproxy.io,direct"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment