mirror of
https://github.com/tiyn/dotfiles.git
synced 2025-04-19 00:07:47 +02:00
zsh: cleanup zsh config file
This commit is contained in:
parent
1b6be396a6
commit
02f6077bab
@ -1,77 +1,26 @@
|
|||||||
# Disable ctrl-s and ctrl-q.
|
####################
|
||||||
stty -ixon
|
# HELPER FUNCTIONS #
|
||||||
|
####################
|
||||||
|
|
||||||
setopt autocd autopushd
|
|
||||||
|
|
||||||
# Enable colors and change prompt
|
|
||||||
autoload -U colors && colors
|
|
||||||
autoload -Uz vcs_info
|
|
||||||
precmd_vcs_info() { vcs_info }
|
precmd_vcs_info() { vcs_info }
|
||||||
|
|
||||||
precmd_functions+=( precmd_vcs_info )
|
precmd_functions+=( precmd_vcs_info )
|
||||||
zstyle ':vcs_info:*' enable git
|
|
||||||
zstyle ':vcs_info:git*:*' get-revision true
|
|
||||||
zstyle ':vcs_info:git*:*' check-for-changes true
|
|
||||||
zstyle ':vcs_info:git*' formats "(%s) %c%u %b%m"
|
|
||||||
zstyle ':vcs_info:git*' actionformats "(%s|%a) %12.12i %c%u %b%m"
|
|
||||||
setopt prompt_subst
|
|
||||||
|
|
||||||
# Show remote ref name and number of commits ahead-of or behind
|
zle-line-init() {
|
||||||
function +vi-git-st() {
|
zle -K viins
|
||||||
local ahead behind remote
|
echo -ne "\e[5 q"
|
||||||
local -a gitstatus
|
|
||||||
remote=${$(git rev-parse --verify ${hook_com[branch]}@{upstream} \
|
|
||||||
--symbolic-full-name 2>/dev/null)/refs\/remotes\/}
|
|
||||||
if [[ -n ${remote} ]] ; then
|
|
||||||
# for git prior to 1.7
|
|
||||||
# ahead=$(git rev-list origin/${hook_com[branch]}..HEAD | wc -l)
|
|
||||||
ahead=$(git rev-list ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null | wc -l)
|
|
||||||
(( $ahead )) && gitstatus+=( " ${c3}+${ahead}${c2}" )
|
|
||||||
# for git prior to 1.7
|
|
||||||
# behind=$(git rev-list HEAD..origin/${hook_com[branch]} | wc -l)
|
|
||||||
behind=$(git rev-list HEAD..${hook_com[branch]}@{upstream} 2>/dev/null | wc -l)
|
|
||||||
(( $behind )) && gitstatus+=( "${c4}-${behind}${c2}" )
|
|
||||||
hook_com[branch]="${hook_com[branch]} [${remote}${(j:/:)gitstatus}]"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
# Show count of stashed changes
|
|
||||||
function +vi-git-stash() {
|
|
||||||
local -a stashes
|
|
||||||
if [[ -s ${hook_com[base]}/.git/refs/stash ]] ; then
|
|
||||||
stashes=$(git stash list 2>/dev/null | wc -l)
|
|
||||||
hook_com[misc]+=" (${stashes} stashed)"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
zstyle ':vcs_info:git*+set-message:*' hooks git-st git-stash
|
|
||||||
PS1='%B%{$fg[blue]%}[%{$fg[blue]%}%n%{$fg[blue]%}@%{$fg[blue]%}%M %{$fg[blue]%}%~%{$fg[blue]%}]%{$reset_color%}\$%b '
|
|
||||||
RPROMPT='%B%{$fg[blue]%}$vcs_info_msg_0_%{$reset_color%}%b'
|
|
||||||
|
|
||||||
zstyle ':completion:*' menu select
|
preexec() { echo -ne '\e[5 q' ;}
|
||||||
zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*' # Case insensitive completion
|
|
||||||
zmodload zsh/complist
|
|
||||||
_comp_options+=(globdots)
|
|
||||||
|
|
||||||
# disable sort when completing `git checkout`
|
local copy_widgets=(
|
||||||
zstyle ':completion:*:git-checkout:*' sort false
|
vi-yank vi-yank-eol vi-delete vi-backward-kill-word vi-change-whole-line
|
||||||
# set descriptions format to enable group support
|
)
|
||||||
# don't use escape sequences here, fzf-tab will ignore them
|
|
||||||
zstyle ':completion:*:descriptions' format '[%d]'
|
local paste_widgets=(
|
||||||
# set list-colors to enable filename colorizing
|
vi-put-{before,after}
|
||||||
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
|
)
|
||||||
# preview directory's content with eza when completing cd
|
|
||||||
zstyle ':fzf-tab:complete:cd:*' fzf-preview 'eza -1 --color=always $realpath'
|
|
||||||
# switch group using `,` and `.`
|
|
||||||
zstyle ':fzf-tab:*' switch-group ',' '.'
|
|
||||||
|
|
||||||
# Enable vi mode
|
|
||||||
bindkey -v
|
|
||||||
export KEYTIMEOUT=1
|
|
||||||
# Vim bindings in tab mode
|
|
||||||
bindkey -M menuselect 'h' vi-backward-char
|
|
||||||
bindkey -M menuselect 'k' vi-up-line-or-history
|
|
||||||
bindkey -M menuselect 'l' vi-forward-char
|
|
||||||
bindkey -M menuselect 'j' vi-down-line-or-history
|
|
||||||
bindkey -v '^?' backward-delete-char
|
|
||||||
# Vim Cursor shape
|
|
||||||
function zle-keymap-select {
|
function zle-keymap-select {
|
||||||
if [[ ${KEYMAP} == vicmd ]] ||
|
if [[ ${KEYMAP} == vicmd ]] ||
|
||||||
[[ $1 = 'block' ]]; then
|
[[ $1 = 'block' ]]; then
|
||||||
@ -82,16 +31,7 @@ function zle-keymap-select {
|
|||||||
echo -ne '\e[5 q'
|
echo -ne '\e[5 q'
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
zle -N zle-keymap-select
|
|
||||||
zle-line-init() {
|
|
||||||
zle -K viins
|
|
||||||
echo -ne "\e[5 q"
|
|
||||||
}
|
|
||||||
zle -N zle-line-init
|
|
||||||
echo -ne '\e[5 q'
|
|
||||||
preexec() { echo -ne '\e[5 q' ;}
|
|
||||||
|
|
||||||
# Vim copy and paste fix in terminal
|
|
||||||
function x11-clip-wrap-widgets() {
|
function x11-clip-wrap-widgets() {
|
||||||
local copy_or_paste=$1
|
local copy_or_paste=$1
|
||||||
shift
|
shift
|
||||||
@ -115,20 +55,112 @@ function x11-clip-wrap-widgets() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function +vi-git-st() {
|
||||||
|
local ahead behind remote
|
||||||
|
local -a gitstatus
|
||||||
|
remote=${$(git rev-parse --verify ${hook_com[branch]}@{upstream} \
|
||||||
|
--symbolic-full-name 2>/dev/null)/refs\/remotes\/}
|
||||||
|
if [[ -n ${remote} ]] ; then
|
||||||
|
# for git prior to 1.7
|
||||||
|
# ahead=$(git rev-list origin/${hook_com[branch]}..HEAD | wc -l)
|
||||||
|
ahead=$(git rev-list ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null | wc -l)
|
||||||
|
(( $ahead )) && gitstatus+=( " ${c3}+${ahead}${c2}" )
|
||||||
|
# for git prior to 1.7
|
||||||
|
# behind=$(git rev-list HEAD..origin/${hook_com[branch]} | wc -l)
|
||||||
|
behind=$(git rev-list HEAD..${hook_com[branch]}@{upstream} 2>/dev/null | wc -l)
|
||||||
|
(( $behind )) && gitstatus+=( "${c4}-${behind}${c2}" )
|
||||||
|
hook_com[branch]="${hook_com[branch]} [${remote}${(j:/:)gitstatus}]"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
local copy_widgets=(
|
function +vi-git-stash() {
|
||||||
vi-yank vi-yank-eol vi-delete vi-backward-kill-word vi-change-whole-line
|
local -a stashes
|
||||||
)
|
if [[ -s ${hook_com[base]}/.git/refs/stash ]] ; then
|
||||||
local paste_widgets=(
|
stashes=$(git stash list 2>/dev/null | wc -l)
|
||||||
vi-put-{before,after}
|
hook_com[misc]+=" (${stashes} stashed)"
|
||||||
)
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# NB: can atm. only wrap native widgets
|
#########
|
||||||
|
# STYLE #
|
||||||
|
#########
|
||||||
|
|
||||||
|
# Set style for version control
|
||||||
|
zstyle ':vcs_info:*' enable git
|
||||||
|
zstyle ':vcs_info:git*:*' get-revision true
|
||||||
|
zstyle ':vcs_info:git*:*' check-for-changes true
|
||||||
|
zstyle ':vcs_info:git*' formats "(%s) %c%u %b%m"
|
||||||
|
zstyle ':vcs_info:git*' actionformats "(%s|%a) %12.12i %c%u %b%m"
|
||||||
|
# Show remote ref name and number of commits ahead-of or behind
|
||||||
|
# Show count of stashed changes
|
||||||
|
zstyle ':vcs_info:git*+set-message:*' hooks git-st git-stash
|
||||||
|
|
||||||
|
# Set style for completion options
|
||||||
|
zstyle ':completion:*' menu select
|
||||||
|
zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*' # Case insensitive completion
|
||||||
|
zmodload zsh/complist
|
||||||
|
_comp_options+=(globdots)
|
||||||
|
|
||||||
|
# Disable sort when completing `git checkout`
|
||||||
|
zstyle ':completion:*:git-checkout:*' sort false
|
||||||
|
# Set descriptions format to enable group support
|
||||||
|
zstyle ':completion:*:descriptions' format '[%d]'
|
||||||
|
# Set list-colors to enable filename colorizing
|
||||||
|
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
|
||||||
|
# Preview directory's content with eza when completing cd
|
||||||
|
zstyle ':fzf-tab:complete:cd:*' fzf-preview 'eza -1 --color=always $realpath'
|
||||||
|
# Switch group using `,` and `.`
|
||||||
|
zstyle ':fzf-tab:*' switch-group ',' '.'
|
||||||
|
|
||||||
|
# Set default Vim Cursor shape
|
||||||
|
zle -N zle-keymap-select
|
||||||
|
zle -N zle-line-init
|
||||||
|
echo -ne '\e[5 q'
|
||||||
|
|
||||||
|
# Set default prompt
|
||||||
|
PS1='%B%{$fg[blue]%}[%{$fg[blue]%}%n%{$fg[blue]%}@%{$fg[blue]%}%M %{$fg[blue]%}%~%{$fg[blue]%}]%{$reset_color%}\$%b '
|
||||||
|
RPROMPT='%B%{$fg[blue]%}$vcs_info_msg_0_%{$reset_color%}%b'
|
||||||
|
setopt prompt_subst
|
||||||
|
|
||||||
|
# Copy to x11 clipboard
|
||||||
x11-clip-wrap-widgets copy $copy_widgets
|
x11-clip-wrap-widgets copy $copy_widgets
|
||||||
x11-clip-wrap-widgets paste $paste_widgets
|
x11-clip-wrap-widgets paste $paste_widgets
|
||||||
|
|
||||||
|
# Enable colors
|
||||||
|
autoload -U colors && colors
|
||||||
|
|
||||||
|
# Enable git info in prompt
|
||||||
|
autoload -Uz vcs_info
|
||||||
|
|
||||||
|
###############
|
||||||
|
# KEYBINDINGS #
|
||||||
|
###############
|
||||||
|
|
||||||
|
# Enable vi mode
|
||||||
|
bindkey -v
|
||||||
|
export KEYTIMEOUT=1
|
||||||
|
|
||||||
|
# Vim bindings in tab mode
|
||||||
|
bindkey -M menuselect 'h' vi-backward-char
|
||||||
|
bindkey -M menuselect 'k' vi-up-line-or-history
|
||||||
|
bindkey -M menuselect 'l' vi-forward-char
|
||||||
|
bindkey -M menuselect 'j' vi-down-line-or-history
|
||||||
|
bindkey -v '^?' backward-delete-char
|
||||||
|
|
||||||
|
#######################
|
||||||
|
# ADDITIONAL FEATURES #
|
||||||
|
#######################
|
||||||
|
|
||||||
|
# Load alias
|
||||||
[ -f "$HOME/.config/aliasrc" ] && source "$HOME/.config/aliasrc" # Load aliases
|
[ -f "$HOME/.config/aliasrc" ] && source "$HOME/.config/aliasrc" # Load aliases
|
||||||
|
|
||||||
|
# Disable ctrl-s and ctrl-q.
|
||||||
|
stty -ixon
|
||||||
|
|
||||||
|
# Automatically cd if given a directory
|
||||||
|
setopt autocd autopushd
|
||||||
|
|
||||||
|
# Enable compinit
|
||||||
autoload -Uz compinit && compinit
|
autoload -Uz compinit && compinit
|
||||||
|
|
||||||
# Plugin: command not found notice
|
# Plugin: command not found notice
|
||||||
@ -144,14 +176,20 @@ bindkey '^ ' autosuggest-accept
|
|||||||
# Plugin: syntax highlighting
|
# Plugin: syntax highlighting
|
||||||
source /usr/share/zsh/plugins/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh
|
source /usr/share/zsh/plugins/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh
|
||||||
|
|
||||||
|
# Open shell with tmux always
|
||||||
if [[ -n "$PS1" ]] && [[ -z "$TMUX" ]] && [[ -n "$SSH_CONNECTION" ]]; then
|
if [[ -n "$PS1" ]] && [[ -z "$TMUX" ]] && [[ -n "$SSH_CONNECTION" ]]; then
|
||||||
tmux attack-session -t $USER || tmux new-session -s $USER
|
tmux attack-session -t $USER || tmux new-session -s $USER
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# python
|
|
||||||
#eval "$(pyenv init -)"
|
|
||||||
|
|
||||||
# set up thefuck
|
# set up thefuck
|
||||||
eval $(thefuck --alias)
|
eval $(thefuck --alias)
|
||||||
|
|
||||||
|
# python
|
||||||
|
#eval "$(pyenv init -)"
|
||||||
|
|
||||||
|
##########################
|
||||||
|
# COMMANDS BEFORE PROMPT #
|
||||||
|
##########################
|
||||||
|
|
||||||
|
# Display pfetch when starting zsh
|
||||||
pfetch
|
pfetch
|
||||||
|
Loading…
x
Reference in New Issue
Block a user