dotfiles/zsh/.zshrc

189 lines
5.2 KiB
Bash
Raw Normal View History

#!/bin/zsh
autoload -U colors && colors
autoload -Uz vcs_info
autoload -z edit-command-line
zle -N edit-command-line
#-----------------#
# Auto-completion #
#-----------------#
# https://github.com/zsh-users/zsh-completions
[ -d "$HOME/.config/zsh/zsh-completions/src" ] && fpath=($HOME/.config/zsh/zsh-completions/src $fpath)
2019-04-08 18:26:37 +02:00
autoload -Uz compinit && compinit -d $ZCOMPDUMP
autoload -U bashcompinit
bashcompinit
2021-10-29 09:30:53 +02:00
[ -f "$HOME/.config/tea/autocomplete.zsh" ] && PROG=tea _CLI_ZSH_AUTOCOMPLETE_HACK=1 source $HOME/.config/tea/autocomplete.zsh
# Display a message when no match
#zstyle ':completion:*:warnings' format 'No matches for: %d'
2019-04-25 13:10:26 +02:00
# Try first simple completion and, if that generates no matches, case-insensitive completion
zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}'
# Ignore completion functions for commands you don't have:
zstyle ':completion:*:functions' ignored-patterns '_*'
# Use a cache for slow functions (_dpkg, _apt, ...)
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path $XDG_CACHE_HOME/zsh
# Ignore filenames already on the command line
zstyle ':completion:*:rm:*' ignore-line yes
# cd will never select the parent directory (e.g.: cd ../<TAB>):
zstyle ':completion:*:cd:*' ignore-parents parent pwd
# If you end up using a directory as argument, this will remove the trailing slash (usefull in ln)
zstyle ':completion:*' squeeze-slashes true
# Completing process IDs with menu selection
zstyle ':completion:*:*:killall:*' menu yes select
zstyle ':completion:*:killall:*' force-list always
zstyle ':completion:*:*:kill:*' menu yes select
zstyle ':completion:*:kill:*' force-list always
#---------------------#
# VCS infos in prompt #
#---------------------#
zstyle ':vcs_info:*' enable git svn hg
zstyle ':vcs_info:git*' formats " (%s.%b) "
zstyle ':vcs_info:hg*' formats " (%s.%b) "
#----------------------------------------------#
# Options activation #
# http://www.cs.elte.hu/zsh-manual/zsh_16.html #
#----------------------------------------------#
setopt hist_ignore_all_dups
setopt hist_ignore_space
setopt INC_APPEND_HISTORY
setopt extended_history
setopt complete_in_word
# move cursor to end of line when completing in the middle
setopt always_to_end
# spelling correction of commands
setopt correct
setopt hist_verify
setopt interactive_comments
setopt extendedglob
setopt autocd
setopt nobeep
setopt prompt_subst
setopt nullglob
setopt autopushd
#----------#
# VIM mode #
#----------#
bindkey -v
bindkey -M vicmd v edit-command-line
# Affiche le mode (normal ou insert) dans le prompt de droite
function zle-line-init zle-keymap-select
{
RPS1="${${KEYMAP/vicmd/-N-}/(main|viins)/-I-}"
RPS2=$RPS1
zle reset-prompt
}
zle -N zle-line-init
zle -N zle-keymap-select
if [ $(whoami) = "root" ]
then
COLOR="red"
else
colors=(blue green cyan magenta yellow)
color_index=$(($(hostname | sum | cut -f1 -d" ") % $#colors + 1))
COLOR=$colors[$color_index]
fi
export PS1='%m%{$fg[$COLOR]%}:%{$reset_color%}%~${vcs_info_msg_0_}%{$fg[$COLOR]%}%#%{$reset_color%} '
export PS2="%_> "
export LESS_TERMCAP_mb=$'\E[01;31m' # begin blinking
export LESS_TERMCAP_md=$'\E[01;31m' # begin bold
export LESS_TERMCAP_me=$'\E[0m' # end mode
export LESS_TERMCAP_so=$'\E[01;44;33m' # begin standout-mode
export LESS_TERMCAP_se=$'\E[0m' # end standout-mode
export LESS_TERMCAP_us=$'\E[01;32m' # begin underline
export LESS_TERMCAP_ue=$'\E[0m' # end underline
precmd() {
vcs_info
}
preexec() { }
#-------#
# Alias #
#-------#
alias vi='vim'
alias mv='mv -i'
alias tmux="tmux -2 -f $XDG_CONFIG_HOME/tmux/tmux.conf"
alias mv_p='rsync --progress --remove-source-files -h'
2019-04-15 14:01:24 +02:00
alias rsync-to-ntfs='rsync -rltDuv --modify-window=1'
alias ls='ls --color=auto'
2019-04-15 14:01:24 +02:00
alias poweroff='sudo poweroff'
2012-12-21 18:52:23 +01:00
alias xephyr-dualscreen='Xephyr -ac -br -noreset -screen 800x600 -screen 800x600 :1& sleep 3; DISPLAY=:1; setxkbmap fr bepo'
alias xephyr-onescreen='Xephyr -ac -br -noreset -screen 800x600 :1& sleep 3; DISPLAY=:1; setxkbmap fr bepo'
alias be='bundle exec'
alias git-count="gawk '{ add += \$1 ; subs += \$2 ; loc += \$1 - \$2 } END { printf \"added lines: %s, removed lines : %s, total lines : %s\n\", add, subs, loc }\' -"
2019-04-15 14:01:24 +02:00
alias subdl="subdl --output={m}.{L}.{S}"
2018-09-03 10:00:49 +02:00
## Docker ##
alias dcb='docker-compose build'
alias dcu='docker-compose up'
alias dcr='docker-compose run app'
alias dcrestart='docker-compose restart app'
alias -s pdf=zathura
alias -s ps=gv
alias -s dvi=xdvi
alias -s avi=mpv
alias -s mkv=mpv
alias -s mp4=mpv
alias -s webm=mpv
alias -s mp3=mpv
alias -s png=feh
alias -s jpg=feh
alias -s gif=feh
#-----------------#
# Other functions #
#-----------------#
function rpass() {
cat /dev/urandom | tr -cd '[:graph:]' | head -c ${1:-12}
echo
}
function utime() {
date -d "1970-01-01 GMT $1 seconds";
}
function confirm() {
echo -n "$1 [Yn]? "; read reply;
case $reply in
N*|n*) false ;;
*) true ;;
esac
}
function send_infocmp() {
REMOTE=$1
infocmp rxvt-unicode-256color | ssh $REMOTE "mkdir -p .terminfo && cat >/tmp/ti && tic /tmp/ti"
}
2017-04-06 14:24:53 +02:00
function fake_git() {
TIME=$1; shift
DATE=$(date +"%a %b %d $TIME:%S %Y %z")
GIT_COMMITTER_DATE=$DATE git commit --date=$DATE "$@"
}
2018-06-07 10:55:25 +02:00
source /usr/share/chruby/chruby.sh
source /usr/share/chruby/auto.sh