psoxizsh/zshrc

280 lines
9.0 KiB
Bash
Raw Permalink Normal View History

2018-04-25 17:13:25 +00:00
# If you come from bash you might have to change your $PATH.
2017-12-13 13:08:26 +00:00
# export PATH=$HOME/bin:/usr/local/bin:$PATH
2019-11-27 15:34:54 +00:00
2018-01-25 14:49:11 +00:00
[[ "$LANGUAGE" == "" ]] && export LANGUAGE=en_US.UTF-8
[[ "$LANG" == "" ]] && export LANG=en_US.UTF-8
[[ "$LC_ALL" == "" ]] && export LC_ALL=en_US.UTF-8
2017-12-13 13:08:26 +00:00
2018-05-02 10:23:02 +00:00
[[ -d /etc/psoxizsh ]] && export PSOXIZSH=/etc/psoxizsh
[[ -d ~/.psoxizsh ]] && export PSOXIZSH=~/.psoxizsh
[[ "$TERM" == "linux" ]] && export TERM=vte-256color
2017-12-13 13:08:26 +00:00
# remove duplicates
2018-05-14 10:45:17 +00:00
typeset -U PATH path fpath
2018-01-21 20:54:11 +00:00
path=( /bin /sbin /usr/bin /usr/sbin $path )
[[ -d ~/bin ]] && path=( ~/bin $path )
2017-12-13 13:08:26 +00:00
2021-11-04 15:11:58 +00:00
# sdkman support
2019-10-03 11:09:40 +00:00
[[ -f ~/.sdkman/bin/sdkman-init.sh ]] && source ~/.sdkman/bin/sdkman-init.sh
2021-11-04 15:11:58 +00:00
# nvm
2020-06-14 15:11:35 +00:00
[[ -f /usr/share/nvm/init-nvm.sh ]] && source /usr/share/nvm/init-nvm.sh
2019-11-27 15:34:54 +00:00
# jaesve support
2020-07-11 14:59:08 +00:00
( which jaesve &>/dev/null ) && (
2019-11-27 15:34:54 +00:00
[[ -d ~/.local/share/zsh/functions ]] || mkdir -vp ~/.local/share/zsh/functions
[[ $(which jaesve) -nt ~/.local/share/zsh/functions/_jaesve ]] || (
jaesve completions -- zsh > ~/.local/share/zsh/functions/_jaesve
)
)
2018-05-14 10:45:17 +00:00
# Set funtion paths
2018-05-17 13:48:05 +00:00
foreach local p in ~/.local/share/zsh/functions ~/.config/zsh/functions $extra_fpath
2021-12-22 14:17:52 +00:00
[[ -d "$p" ]] && fpath=( "$p" $fpath )
2018-05-14 10:54:28 +00:00
end
2018-05-14 10:45:17 +00:00
2018-03-08 12:13:45 +00:00
[[ "$OS" != "Windows_NT" ]] && [[ -f /etc/profile ]] && source /etc/profile
2017-12-13 13:08:26 +00:00
if [[ -z "$GOPATH" ]]
then
if [[ -d /cygdrive/s/develop/go ]]
then
export GOPATH=$(echo /cygdrive/s/develop/go)
2018-01-06 11:44:44 +00:00
elif [[ -d ~/Develop/go ]]
then
export GOPATH=$(echo ~/Develop/go)
elif [[ -d ~/develop/go ]]
then
export GOPATH=$(echo ~/develop/go)
2017-12-13 13:08:26 +00:00
else
export GOPATH=$(echo ~/go)
fi
fi
path+=( $GOPATH/bin ${GOROOT+${GOROOT}/bin} )
# check for starship
if which starship &>/dev/null && [[ ! -e ~/.no-starship ]]
then
export _STARSHIP_Y_="yes"
fi
2017-12-13 13:08:26 +00:00
# Path to your oh-my-zsh installation.
2018-05-02 10:23:02 +00:00
export ZSH=$PSOXIZSH/oh-my-zsh
2018-01-18 14:59:51 +00:00
export ZSH_CACHE_DIR=~/.cache/zsh
2018-02-14 15:47:57 +00:00
[[ ! -d $ZSH_CACHE_DIR ]] && mkdir -p $ZSH_CACHE_DIR
2017-12-13 13:08:26 +00:00
[[ -z "$ZSH_THEME" ]] && [[ -z "$_STARSHIP_Y_" ]] && export ZSH_THEME="stemmet"
2017-12-13 13:08:26 +00:00
DISABLE_AUTO_UPDATE="true"
COMPLETION_WAITING_DOTS="true"
DISABLE_UNTRACKED_FILES_DIRTY="true"
HIST_STAMPS="yyyy-mm-dd"
2017-12-13 17:59:10 +00:00
ZSH_CUSTOM=$(dirname $ZSH)/zsh-custom
2017-12-13 13:08:26 +00:00
2021-11-01 10:42:23 +00:00
plugins=(
$pre_plugins
gnu-utils
common-aliases
colored-man-pages
2018-02-14 10:56:32 +00:00
)
2022-09-16 11:02:52 +00:00
( which git &>/dev/null ) &&
plugins+=( git git-extras git-flow-avh ) &&
[[ "$ZSH_THEME" == "stemmet" ]] &&
[ -z "$_STARSHIP_Y_" ] &&
plugins+=( git-prompt )
2020-07-11 14:59:08 +00:00
( which perl &>/dev/null ) && plugins+=( perl )
( which go &>/dev/null ) && plugins+=( golang )
( which oc &>/dev/null ) && plugins+=( oc )
( which rsync &>/dev/null ) && plugins+=( rsync )
( which aws &>/dev/null ) && plugins+=( aws )
2022-04-05 13:28:18 +00:00
( which cargo &>/dev/null ) && plugins+=( rust )
2020-07-11 14:59:08 +00:00
( which jq &>/dev/null ) && plugins+=( jsontools )
( which encode64 &>/dev/null ) && plugins+=( encode64 )
( which docker-compose &>/dev/null ) && plugins+=( docker-compose )
( which docker &>/dev/null ) && plugins+=( docker )
( which mosh &>/dev/null ) && plugins+=( mosh )
( which systemd &>/dev/null ) && plugins+=( systemd )
( which python &>/dev/null ) && plugins+=( python )
( which pip &>/dev/null ) && plugins+=( pip )
( which sudo &>/dev/null ) && plugins+=( sudo )
( which tmux &>/dev/null ) && plugins+=( tmux )
( which yum &>/dev/null ) && plugins+=( yum )
( which code &>/dev/null ) && plugins+=( vscode )
( which strfile &>/dev/null ) && plugins+=( chucknorris )
( which kubectl &>/dev/null ) && plugins+=( kubectl )
2022-04-05 13:28:18 +00:00
( which kubectx &>/dev/null ) && plugins+=( kubectx )
( which chroma &>/dev/null ) && plugins+=( colorize )
( which kate &>/dev/null ) && plugins+=( kate )
2022-05-17 09:22:41 +00:00
( which zoxide &>/dev/null ) && plugins+=( zoxide )
2018-02-12 17:44:56 +00:00
( [[ -e /etc/arch-release ]] ) && plugins+=( archlinux )
2022-04-05 13:28:18 +00:00
( [[ -e /etc/ubuntu-release ]] ) && plugins+=( ubuntu )
( [[ -e /etc/debian-release ]] ) && plugins+=( debian )
2018-02-12 17:44:56 +00:00
( [[ -e /etc/suse-release ]] ) && plugins+=( suse )
2022-04-05 13:28:18 +00:00
( [[ "$(uname)" == "Darwin" ]] ) && plugins+=( macos )
( which vim &>/dev/null ) && plugins+=( vim-interaction )
2020-07-11 14:59:08 +00:00
( which ssh &>/dev/null ) && [[ -d ~/.ssh ]] && plugins+=( ssh-agent )
2021-12-22 14:17:52 +00:00
plugins+=(
2018-02-14 10:56:32 +00:00
zsh-completions
2020-07-11 14:59:08 +00:00
zsh-autosuggestions
zsh-navigation-tools
$( which fzf &>/dev/null && echo 'fzf' )
zsh-syntax-highlighting
2018-02-14 10:56:32 +00:00
$post_plugins
)
2017-12-13 13:08:26 +00:00
if [[ "$OSTYPE" =~ "linux*" || "$OSTYPE" =~ "darwin*" || "$OSTYPE" == "cygwin" ]]
2017-12-13 13:08:26 +00:00
then
2020-11-02 16:35:23 +00:00
export VIMINIT='source $MYVIMRC'
export VIMHOME=~/.vim
# Feature flag lua based Neovim config, until this is tested
2022-09-16 10:41:33 +00:00
# (and we figure out how to detect if we are running nvim or vim)
if [[ -n ${PSOXIZSH_EXPERIMENTAL_NEOVIM_LUA} ]]
then
export MYVIMRC=$PSOXIZSH/init.lua
else
export MYVIMRC=$PSOXIZSH/vimrc
cmp $PSOXIZSH/vim/autoload/plug.vim $VIMHOME/autoload/plug.vim 2>/dev/null || (
mkdir -vp $VIMHOME/autoload/
cp -av $PSOXIZSH/vim/autoload/plug.vim $VIMHOME/autoload/plug.vim
)
fi
2017-12-13 13:08:26 +00:00
fi
2019-06-30 15:39:49 +00:00
if [[ -d ~/.ssh ]]
then
zstyle :omz:plugins:ssh-agent lifetime 36h
zstyle :omz:plugins:ssh-agent agent-forwarding on
2022-09-13 19:05:51 +00:00
if [[ -e ~/.ssh/autoload ]]
2019-06-30 15:39:49 +00:00
then
zstyle :omz:plugins:ssh-agent identities $( cat ~/.ssh/autoload )
fi
fi
2018-05-02 10:23:02 +00:00
[[ -d $ZSH ]] && source $ZSH/oh-my-zsh.sh
2017-12-13 13:08:26 +00:00
# Dynamic Completion
foreach cmd in kubectl kubeadm
2020-07-11 14:59:08 +00:00
( which $cmd &>/dev/null ) && source <($cmd completion zsh)
2018-02-14 15:42:25 +00:00
end
2019-02-19 11:14:46 +00:00
source $PSOXIZSH/zsh-custom/zshnip/zshnip.zsh
2020-07-11 14:59:08 +00:00
( which lxc &>/dev/null ) && source $PSOXIZSH/zsh-custom/lxd-completion-zsh/_lxc
2019-02-19 11:14:46 +00:00
2020-07-11 14:59:08 +00:00
( which vi &>/dev/null ) && export EDITOR='vi'
( which vim &>/dev/null ) && export EDITOR='vim'
( which nvim &>/dev/null ) && export EDITOR='nvim'
2017-12-13 13:08:26 +00:00
# Set zsh tmux config path
2021-11-04 15:11:58 +00:00
if which tmux &>/dev/null
then
[ -z "$TMUX_PATH" ] && TMUX_PATH=~/.config/tmux
2022-09-16 10:41:33 +00:00
# Bootstrap the users plugin directory, if required
2022-09-16 11:02:52 +00:00
[ -d "$TMUX_PATH/plugins" ] || {
mkdir -vp "$TMUX_PATH/plugins" &&
cp -r "$PSOXIZSH/tmux/plugins" "$TMUX_PATH/plugins"
}
2021-11-04 15:11:58 +00:00
# Both tmux and TPM are very opininated about where configs must live,
# and TPM will only expand one layer of source-file directives, so we
2022-09-16 10:41:33 +00:00
# symlink the base config to the user local config file, if it does not
2021-11-04 15:11:58 +00:00
# exist.
2021-11-04 15:59:05 +00:00
[[ ! -f $TMUX_PATH/tmux.conf ]] && cp -r "$PSOXIZSH/tmux/tmux.conf" "$TMUX_PATH/tmux.conf"
[[ ! -f ~/.tmux.conf ]] && ln -s $PSOXIZSH/tmux/tmux.conf ~/.tmux.conf
[[ ! -f "$TMUX_PATH/plugins.conf" ]] && ln -vs "$PSOXIZSH/tmux/fragment/plugins.conf" "$TMUX_PATH/plugins.conf"
2021-11-06 13:25:44 +00:00
[[ "$USER" == "astemmet" ]] && [[ ! -f $TMUX_PATH/keys.conf ]] && {
cp -v "$PSOXIZSH/tmux/fragment/ctrl-alt-movement.conf" "$TMUX_PATH/keys.conf"
}
2021-11-04 15:11:58 +00:00
export TMUX_PATH=$TMUX_PATH TMUX_PLUGINS="$TMUX_PATH/plugins" TMUX_CONFIG=~/.tmux.conf
fi
2021-11-04 15:11:58 +00:00
if which fzf &>/dev/null
then
2020-07-11 14:59:08 +00:00
# Press ? inside a C-r search to get a preview window, useful for long commands
export FZF_CTRL_R_OPTS="--preview 'echo {}' --preview-window down:3:hidden:wrap --bind '?:toggle-preview'"
which tmux &> /dev/null && export FZF_TMUX=1
fi
2021-07-07 09:41:36 +00:00
alias zshconfig="vim $PSOXIZSH/zshrc"
alias ohmyzsh="vim $PSOXIZSH/oh-my-zsh"
2019-02-19 11:14:46 +00:00
alias curlj="curl -H 'Content-Type: application/json' "
2021-07-07 09:41:36 +00:00
which nvim >/dev/null 2>&1 && alias vim="$(which nvim)"
alias v=vim
[[ -x /usr/bin/yay ]] && [[ "$(whoami)" != "pacman" ]] && alias yay='sudo -iupacman /usr/bin/yay'
2022-08-02 09:21:42 +00:00
[[ -x /usr/bin/paru ]] && [[ "$(whoami)" != "pacman" ]] && alias yay='sudo -iupacman /usr/bin/paru'
2021-11-29 15:34:10 +00:00
[[ -x /usr/bin/paru ]] && [[ "$(whoami)" != "pacman" ]] && alias paru='sudo -iupacman /usr/bin/paru'
2021-12-22 14:17:52 +00:00
[[ -x /usr/bin/bat ]] && export MANPAGER="sh -c 'col -bx | bat -l man -p'"
2017-12-13 13:08:26 +00:00
typeset -A key
# setup key accordingly
bindkey -- "^[[1~" beginning-of-line
bindkey -- "^[[4~" end-of-line
bindkey -- "^[[2~" overwrite-mode
bindkey -- "^H" backward-delete-char
bindkey -- "^[[3~" delete-char
bindkey -- "^[OD" backward-char
bindkey -- "^[OC" forward-char
bindkey -- "^[OA" up-line-or-history
bindkey -- "^[OB" down-line-or-history
2018-03-28 10:12:53 +00:00
#bindkey -- "^[[1;5A" history-substring-search-up
#bindkey -- "^[[1;5B" history-substring-search-down
2017-12-13 13:08:26 +00:00
2019-02-19 11:14:46 +00:00
bindkey '\ej' zshnip-expand-or-edit # Alt-J
bindkey '\ee' zshnip-edit-and-expand # Alt-E
2017-12-13 13:08:26 +00:00
# cutomize options
setopt no_bang_hist cdable_vars auto_name_dirs
2017-12-13 13:08:26 +00:00
# Finally, make sure the terminal is in application mode, when zle is
# active. Only then are the values from $terminfo valid.
2021-11-04 15:11:58 +00:00
if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} ))
then
2017-12-13 13:08:26 +00:00
function zle-line-init () {
echoti smkx
}
function zle-line-finish () {
echoti rmkx
}
zle -N zle-line-init
zle -N zle-line-finish
fi
[[ -d /cygdrive/c/qemu/ ]] && path+=( /cygdrive/c/qemu/ )
2021-07-08 15:37:58 +00:00
( which xhost &>/dev/null ) && [[ -n "$DISPLAY" ]] && xhost +LOCAL:
2017-12-13 13:08:26 +00:00
2018-06-14 09:48:29 +00:00
# Set Time Variables
precmd() {
export _DATE_=$(date -u +%Y%m%d)
export _TIME_=$(date -u +%H%M%S)
export _DTTS_="${_DATE_}T${_TIME_}Z"
if [[ -n "$KUBECONFIG" && -z "$_STARSHIP_Y_" ]]
2018-06-14 10:16:47 +00:00
then
2018-07-02 10:27:01 +00:00
export KUBE_VARS=$(basename $KUBECONFIG)/$(kubectl config current-context)
2018-06-14 12:38:32 +00:00
else
unset KUBE_VARS
2018-06-14 10:16:47 +00:00
fi
2018-06-14 09:48:29 +00:00
}
if [[ -n "$_STARSHIP_Y_" ]]
then
[[ ! -e ~/.config/starship.toml ]] && install -v -D $PSOXIZSH/starship.toml ~/.config/starship.toml
source <(starship init zsh --print-full-init)
fi
2020-10-29 11:46:05 +00:00
2021-11-01 10:42:23 +00:00
# alias reload
alias src='omz reload'
# Remove unwanted aliases
2022-09-16 10:41:33 +00:00
( where fd | grep -qE '/s?bin/fd' ) && alias fd &>/dev/null && unalias fd
2020-10-29 11:46:05 +00:00
# Clean up global aliases
source <(alias -g | awk -F= '/^[A-Za-z]+/{print $1}' | xargs -I{} -n1 echo unalias "'{}'")
2017-12-13 13:08:26 +00:00
# vim: sw=2 ts=8 si relativenumber number