rc/zshrc

499 lines
15 KiB
Bash
Raw Normal View History

2015-11-07 17:03:36 +00:00
# zshrc inspiré de celui de la formation debian de VIA
2015-06-03 21:39:41 +00:00
# modifié par David_5_1
# http://formation-debian.via.ecp.fr/
# Ajouts depuis le wiki de archlinux http://wiki.archlinux.fr/Zsh
# et depuis http://doc.ubuntu-fr.org/zsh
# et depuis http://zsh.sourceforge.net/Guide/zshguide.html
# utilisation de https://github.com/zsh-users/zsh-syntax-highlighting
2015-10-08 09:30:48 +00:00
# adapté et amélioré par lhark
2015-06-03 21:39:41 +00:00
# Ajout de */sbin au PATH (pour ifconfig en particulier)
export PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin:~/bin
2015-11-07 17:05:17 +00:00
2015-11-08 18:09:05 +00:00
# Get rc dir path
2015-11-09 13:57:47 +00:00
RC_PATH=$(dirname "$(readlink -f ${(%):-%x})")
2015-11-08 18:09:05 +00:00
2015-06-06 22:27:38 +00:00
# Mise à jour automatique à partir du repo distant
2015-11-07 17:05:17 +00:00
2015-11-08 18:09:05 +00:00
CUR_PWD=`pwd`
cd $RC_PATH
2015-11-07 17:05:17 +00:00
2015-06-09 09:41:02 +00:00
# In case the network is down, don't lock the terminal
2015-06-09 10:49:03 +00:00
timeout 3 git fetch > /dev/null 2>&1
2015-11-07 17:05:17 +00:00
#
# Timeout returns 124 on timeout
2015-06-09 10:49:03 +00:00
if [ "$?" -ge "124" ]; then
echo "Unable to reach $(git remote -v | grep "fetch")"
2015-06-09 09:49:53 +00:00
fi
2015-11-07 17:05:17 +00:00
# Check if the repo is clean
git_st=$(command git status --porcelain -b 2> /dev/null)
if $(echo "$git_st" | grep '^## .*ahead' &> /dev/null); then
2015-08-09 10:47:54 +00:00
echo "You have unpushed business in $HOME/rc"
elif $(echo "$git_st" | grep '^## .*behind' &> /dev/null); then
2015-06-06 22:24:41 +00:00
echo "Type Y to update .zshrc: \c"
read line
if [ "$line" = Y ] || [ "$line" = y ]; then
git pull --rebase --stat origin master && source $HOME/.zshrc && cd $CUR_PWD
2015-12-17 14:02:08 +00:00
return
2015-06-06 22:24:41 +00:00
fi
fi
2015-11-07 17:05:17 +00:00
2015-11-08 18:09:05 +00:00
cd $CUR_PWD
2015-06-06 22:24:41 +00:00
2015-11-07 17:05:17 +00:00
2015-06-03 21:39:41 +00:00
# Configuration for virtualenv
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh > /dev/null 2>&1
2015-11-07 17:05:17 +00:00
2015-10-06 16:55:04 +00:00
# Configuration pour wine
alias steam-wine='WINEDEBUG=-all wine ~/.wine/drive_c/Program\ Files/Steam/Steam.exe -no-dwrite >/dev/null 2>&1 &'
2015-11-07 17:05:17 +00:00
2015-10-10 12:54:22 +00:00
# Configuration pour minecraft
alias minecraft="java -jar $HOME/.minecraft/launcher.jar"
2015-11-07 17:05:17 +00:00
2016-03-17 14:58:53 +00:00
# Easy dwm recompile on arch
alias redwm='cd ~/abs/dwm; updpkgsums; makepkg -fi --noconfirm; killall dwm'
2015-06-03 21:39:41 +00:00
# Aliases
2015-08-20 13:05:02 +00:00
alias acs='apt-cache search'
2015-06-03 21:39:41 +00:00
alias ls='ls --classify --tabsize=0 --literal --color=auto --show-control-chars -h'
alias ll='ls -lha'
# alias la='ls -A'
# alias lla='ls -la'
# alias less='less --quiet'
alias df='df --human-readable'
alias du='du --human-readable'
# alias mutt='mutt -y'
alias upgrade='sudo apt-get update && sudo apt-get -dy dist-upgrade && sudo apt-get dist-upgrade'
# alias -g GP='|grep '
alias grep="grep --color"
alias ssh='ssh -A'
# alias -s txt=cat
alias rm='rm -I'
alias ipa='ip route && echo && ip address'
alias ipr='ip address && echo && ip route'
alias which='which -a'
alias gg='git log --oneline --abbrev-commit --all --graph --decorate --color'
# À tester un jour :)
2015-06-06 22:24:41 +00:00
# alias -s ps=gv
# Le fameux cd ...etc
2015-06-09 12:04:40 +00:00
alias -g ...='../..'
alias -g ....='../../..'
alias -g .....='../../../..'
alias -g ......='../../../../..'
alias -g .......='../../../../../..'
alias -g ........='../../../../../../..'
2015-06-03 21:39:41 +00:00
2015-11-07 17:05:17 +00:00
2016-03-30 15:27:36 +00:00
# Term specific hacks
case $TERM in
xterm*)
preexec () {
print -Pn "\e]0;$1 -- ${USER}@${HOST}\a"
}
;;
# Fix broken ssh with st
st*)
alias ssh='TERM=xterm ssh'
;;
esac
2015-06-03 21:39:41 +00:00
# Demande confirmation pour 'rm *' -> ou
unsetopt rm_star_silent
2015-11-07 17:05:17 +00:00
2015-06-03 21:39:41 +00:00
# Si on utilise des jokers dans une liste d'arguments, retire les jokers
# qui ne correspondent à rien au lieu de donner une erreur
setopt null_glob
2015-11-07 17:05:17 +00:00
2015-06-03 21:39:41 +00:00
# Autocomplétion ?
unsetopt list_ambiguous
2015-11-07 17:05:17 +00:00
2015-06-03 21:39:41 +00:00
setopt auto_remove_slash
unsetopt glob_dots
autoload -U compinit promptinit colors
compinit
promptinit
colors
autoload -Uz vcs_info
zstyle ':vcs_info:*' enable git cvs svn
setopt auto_cd
zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}'
zstyle ':completion:*' max-errors 3 numeric
zstyle ':completion:*' use-compctl false
2015-11-07 17:05:17 +00:00
2015-06-03 21:39:41 +00:00
# Traite les liens symboliques comme il faut
setopt chase_links
2015-11-07 17:05:17 +00:00
2015-06-03 21:39:41 +00:00
# !! n'est pas exécuté directement
setopt hist_verify
2015-11-07 17:05:17 +00:00
2015-06-03 21:39:41 +00:00
# Afficher le temps pris pour exécuter les commandes
EXPORTTIME=0
2015-11-07 17:05:17 +00:00
2015-06-03 21:39:41 +00:00
# Points rouges pendant l'autocomplétion
COMPLETION_WAITING_DOTS="true"
2015-11-07 17:05:17 +00:00
2015-06-03 21:39:41 +00:00
################################################################################
# Utility functions for the prompt #
################################################################################
2015-11-07 17:05:17 +00:00
2015-06-03 21:39:41 +00:00
# Background changes depending on solarized theme
case ${SOLARIZED_THEME:-dark} in
light) local bkg=white;;
*) local bkg=black;;
esac
local ZSH_THEME_GIT_PROMPT_PREFIX="%{%K{${bkg}}$fg_bold[green]%}[%{$fg_bold[blue]%}"
2015-11-24 20:33:49 +00:00
local ZSH_THEME_GIT_PROMPT_SUFFIX="%{$fg_bold[green]%}]"
local ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg_no_bold[green]%}✓"
local ZSH_THEME_GIT_PROMPT_AHEAD="%{$fg_no_bold[cyan]%}▴"
local ZSH_THEME_GIT_PROMPT_BEHIND="%{$fg_no_bold[magenta]%}▾"
local ZSH_THEME_GIT_PROMPT_STAGED="%{$fg_no_bold[green]%}●"
local ZSH_THEME_GIT_PROMPT_UNSTAGED="%{$fg_no_bold[yellow]%}●"
local ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg_no_bold[red]%}●"
2015-06-03 21:39:41 +00:00
local ZSH_THEME_VIRTUALENV_PREFIX=" %{$fg_bold[green]%}(%{%b%K{${bkg}}$fg[green]%}"
local ZSH_THEME_VIRTUALENV_SUFFIX="%{$reset_color%K{${bkg}}$fg_bold[green]%})%{$reset_color%K{${bkg}}%}"
# Depending if root or not, displays the right prompt char
# and changes the color of the username
if [[ $EUID -eq 0 ]]; then
local _USERNAME="%{$fg_bold[red]%}%n"
local _LIBERTY="%{$fg_no_bold[red]%}#"
else
local _USERNAME="%{$fg_bold[green]%}%n"
local _LIBERTY="%{$fg_no_bold[green]%}$"
fi
_LIBERTY="$_LIBERTY%{$reset_color%}"
function virtualenv_prompt_info(){
[[ -n ${VIRTUAL_ENV} ]] || return
echo "${ZSH_THEME_VIRTUALENV_PREFIX:=[}${VIRTUAL_ENV:t}${ZSH_THEME_VIRTUALENV_SUFFIX:=]}"
}
# disables prompt mangling in virtual_env/bin/activate
export VIRTUAL_ENV_DISABLE_PROMPT=1
function _prompt_chars() {
if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then
local _GIT_CHAR="%{$fg_no_bold[blue]%}±%{$reset_color%}"
else
local _GIT_CHAR=' '
fi
local _VENV_PROMPT="%{%K{${bkg}}%}$(virtualenv_prompt_info)"
echo "$_GIT_CHAR$_VENV_PROMPT $_LIBERTY"
}
function charge_batterie {
local BATTERY=/sys/class/power_supply/BAT0
local REM_CAP=`cat $BATTERY/charge_now`
local FULL_CAP=`cat $BATTERY/charge_full`
local BATSTATE=`cat $BATTERY/status`
local CHARGE=$(( $REM_CAP * 100 / $FULL_CAP ))
local Batterie=""
case $BATSTATE in
'Full')
Batterie="~";;
'Charging')
Batterie="+";;
'Discharging')
Batterie="-";;
esac
# Maximum à 100%
if [ $CHARGE -gt "99" ]
then
CHARGE=100
fi
local Couleur="magenta"
if [ $CHARGE -gt "15" ]
then
Couleur="yellow"
fi
if [ $CHARGE -gt "30" ]
then
Couleur="green"
fi
echo %{$fg[${Couleur}]%B%}${Batterie}%{%b$fg[${Couleur_batt}]%}$CHARGE%%%{$reset_color%}
}
space_sh_git_branch () {
local ref=$(command git symbolic-ref HEAD 2> /dev/null) || \
ref=$(command git rev-parse --short HEAD 2> /dev/null) || return
echo "${ref#refs/heads/}"
}
space_sh_git_status () {
_INDEX=$(command git status --porcelain -b 2> /dev/null)
local _STATUS=""
if $(echo "$_INDEX" | grep '^[AMRD]. ' &> /dev/null); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_STAGED"
fi
if $(echo "$_INDEX" | grep '^.[MTD] ' &> /dev/null); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNSTAGED"
fi
if $(echo "$_INDEX" | command grep -E '^\?\? ' &> /dev/null); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNTRACKED"
fi
if $(echo "$_INDEX" | grep '^UU ' &> /dev/null); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNMERGED"
fi
if $(command git rev-parse --verify refs/stash >/dev/null 2>&1); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_STASHED"
fi
if $(echo "$_INDEX" | grep '^## .*ahead' &> /dev/null); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_AHEAD"
elif $(echo "$_INDEX" | grep '^## .*behind' &> /dev/null); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_BEHIND"
fi
if $(echo "$_INDEX" | grep '^## .*diverged' &> /dev/null); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_DIVERGED"
fi
echo $_STATUS
}
space_sh_git_prompt () {
local _branch=$(space_sh_git_branch)
local _result=""
if [[ "${_branch}x" != "x" ]]; then
local _status=$(space_sh_git_status)
_result="$ZSH_THEME_GIT_PROMPT_PREFIX$_branch"
if [[ "${_status}x" != "x" ]]; then
_result="$_result $_status"
fi
_result="$_result$ZSH_THEME_GIT_PROMPT_SUFFIX"
fi
echo $_result
}
# Host coloring, specific to Rezometz
local couleur_hote=""
case $HOST in
TwelveYearsAndStillGoingStrong|lharkinateur|BecauseROSThatSWhy)
couleur_hote=cyan;;
chimay|orval)
couleur_hote=magenta;;
babel|taima|era|vidar|okami)
couleur_hote=red;;
loki|skadi)
couleur_hote=blue;;
*)
couleur_hote=white;;
esac
#Heure="%(!,%{%B$fg[red]%}%D{%a %d/%m} %T%{$reset_color%}%b,%D{%a %d/%m} %T)"
# Pour recalculer les variables du prompt
# Il faut que le signe $ soit échappé ou entre guillemets simples
setopt promptsubst
################################################################################
# Prompt display #
################################################################################
2015-11-24 20:33:49 +00:00
# Carriage return to give the prompt some air
2015-06-03 21:39:41 +00:00
PROMPT="%{$reset_color%}
"
2015-11-24 20:33:49 +00:00
# Username, red when logged as root
2015-10-08 09:30:48 +00:00
PROMPT+="%{%K{${bkg}}%}"'$_USERNAME'
2015-11-24 20:33:49 +00:00
# @ symbol
2015-06-03 21:39:41 +00:00
PROMPT+="%{$fg_bold[blue]%}@"
2015-11-24 20:33:49 +00:00
# Hostname, colors defined just above
2015-06-03 21:39:41 +00:00
PROMPT+="%{$fg_bold[$couleur_hote]%}"'%m'
2015-11-24 20:33:49 +00:00
# White space to separate host from pwd
2015-06-03 21:39:41 +00:00
PROMPT+=" %{$reset_color%K{${bkg}}%}"
2015-11-24 20:33:49 +00:00
# Current working directory, use ~ when needed
2015-06-03 21:39:41 +00:00
PROMPT+="%{$fg[yellow]%}"'%~'
2015-11-24 20:33:49 +00:00
# Change the background for the whole line and line feed
2015-06-03 21:39:41 +00:00
PROMPT+="%{$fg_bold[green]%} %E
"
2015-11-24 20:33:49 +00:00
# Prompt characters for virtualenv, git and zsh
2015-11-30 21:08:13 +00:00
PROMPT+="%{%K{${bkg}}%}"'$(_prompt_chars)'" %{$reset_color%}"
2015-06-03 21:39:41 +00:00
2015-11-24 20:33:49 +00:00
# Right prompt with current repo informations
2015-11-30 21:08:13 +00:00
RPROMPT='$(space_sh_git_prompt)'"%E%{$reset_color%}"
2015-06-03 21:39:41 +00:00
#PROMPT="$Heure $Utilisateur@$Machine %{$fg_no_bold[yellow]%}%~
#%{$reset_color%}%# "
#RPROMPT="\$(charge_batterie) %(!,%B[%?]%b,[%?])"
#RPROMPT="${vcs_info_msg_0_} \$(charge_batterie) %(!,%B[%?]%b,[%?])"
#RPROMPT=" %(!,%B[%?]%b,[%?])"
# %{ %} pas d'affichage, à utiliser pour ne pas fausser le calcul de RPROMPT
# $fg[color], $fg_(no_)bold[color], $reset_color
# black red green yellow blue magenta cyan white
# Raccourcis claviers à la VIM
bindkey -v
# ou à la emacs
# bindkey -e
# Réglages de l'historique
2015-11-07 17:06:45 +00:00
HISTSIZE=100000
SAVEHIST=100000
2015-06-03 21:39:41 +00:00
HISTFILE=~/.history
HISTTIMEFORMAT="%d/%m %H:%M:%S "
setopt hist_ignore_all_dups sharehistory hist_ignore_space
# >| doit être utilisés pour pouvoir écraser un fichier déjà existant ;
# # le fichier ne sera pas écrasé avec '>'
# unsetopt clobber
# Afficher «zsh: exit ERREUR» en cas d'erreur ≠ 0
2015-11-07 17:07:29 +00:00
setopt print_exit_value
zstyle ':completion:*' auto-description 'specify: %d'
zstyle ':completion:*' completer _expand _complete _correct _approximate
zstyle ':completion:*' format 'Completing %d'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' menu select=2
eval "$(dircolors -b)"
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*'
zstyle ':completion:*' menu select=long
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle ':completion:*' use-compctl false
zstyle ':completion:*' verbose true
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'
2015-06-03 21:39:41 +00:00
# Gestion des touches spéciales pour mon clavier
# Pour connaître le code d'une touche, exécuter «cat»
typeset -A key
# CTRL + flèches
bindkey ";5D" beginning-of-line
bindkey ";5C" end-of-line
bindkey ";5A" up-line-or-history
bindkey ";5B" down-line-or-history
bindkey "^[[1;5D" beginning-of-line
bindkey "^[[1;5C" end-of-line
bindkey "^[[1;5A" history-incremental-search-backward
bindkey "^[[1;5B" history-incremental-search-forward
# Page Up/Down
bindkey "^[[5~" history-beginning-search-backward
bindkey "^[[6~" history-beginning-search-forward
# CTRL + Page UP/Down
bindkey "^[[5;5~" beginning-of-buffer-or-history
bindkey "^[[6;5~" end-of-buffer-or-history
# Origine / Fin (pavé numérique)
bindkey "^[[1~" beginning-of-line
bindkey "^[[4~" end-of-line
# Origine / Fin
bindkey "^[OH" beginning-of-line
bindkey "^[OF" end-of-line
2015-10-22 09:58:49 +00:00
# Delete
bindkey "[3~" delete-char
2015-11-24 17:58:10 +00:00
# Shift-Tab
bindkey "^[[Z" reverse-menu-complete
2015-06-03 21:39:41 +00:00
# Finally, make sure the terminal is in application mode, when zle is
# active. Only then are the values from $terminfo valid.
if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then
function zle-line-init () {
printf '%s' "${terminfo[smkx]}"
}
function zle-line-finish () {
printf '%s' "${terminfo[rmkx]}"
}
zle -N zle-line-init
zle -N zle-line-finish
fi
# # Stockage des dossiers visités (cd -NUM et dir -v)
# DIRSTACKFILE="$HOME/.cache/zsh/dirs"
# if [[ -f $DIRSTACKFILE ]] && [[ $#dirstack -eq 0 ]]; then
# dirstack=( ${(f)"$(< $DIRSTACKFILE)"} )
# [[ -d $dirstack[1] ]] && cd $dirstack[1]
# fi
# chpwd() {
# print -l $PWD ${(u)dirstack} >>$DIRSTACKFILE
# }
DIRSTACKSIZE=20
setopt autopushd pushdsilent pushdtohome
# Remove duplicate entries
setopt pushdignoredups
# This reverts the +/- operators.
setopt pushdminus
autoload -U zsh-mime-setup
autoload -U zsh-mime-handler
zsh-mime-setup
zstyle ':mime:*' mailcap /etc/mailcap
# video/*; /usr/bin/mplayer '%s';
# text/*; less '%s';
# audio/*; /usr/bin/mplayer '%s';
export EDITOR=/usr/bin/vim
# Crée un cache des complétion possibles
# très utile pour les complétion qui demandent beaucoup de temps
# comme la recherche d'un paquet aptitude install moz<tab>
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path ~/.zs
# Des couleurs pour la complétion cf kill -9 <tab><tab>
zmodload zsh/complist
setopt extendedglob
zstyle ':completion:*:*:kill:*:processes' list-colors "=(#b) #([0-9]#)*=36=31"
setopt correct
# Syntax coloration for man
man() {
env \
2015-10-22 09:59:01 +00:00
LESS_TERMCAP_mb=$(printf "$fg_bold[red]") \
LESS_TERMCAP_md=$(printf "$fg_bold[red]") \
LESS_TERMCAP_me=$(printf "$reset_color") \
LESS_TERMCAP_se=$(printf "$reset_color") \
LESS_TERMCAP_so=$(printf "$bg[black]$fg[yellow]") \
LESS_TERMCAP_ue=$(printf "$reset_color") \
LESS_TERMCAP_us=$(printf "$fg_bold[blue]") \
2015-06-03 21:39:41 +00:00
man "$@"
}
# source ~/.zs/zsh-syntax-highlighting.zsh
# exec 2>>(while read line; do
# print '\e[91m'${(q)line}'\e[0m' > /dev/tty; print -n $'\0'; done &)
# Totalement indispensable mais tellemnent chiant que je l'ai viré au bout de 2
# heures :)
# if [ $HOST != "sinquin" ]; then
# (play -q -n synth sine F2 sine C3 remix - fade 0 4 .1 norm -4 bend
# 0.5,2399,2 fade 0 4.0 0.5 &)
# fi
2015-11-07 17:08:13 +00:00
# ZSH syntax highlighting : /!\ keep at the bottom !
2015-11-08 18:09:05 +00:00
source ${RC_PATH}/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh