[zshrc] Switch to builtin vcs_info for the git prompt. Move aliases and prompt to new file

Instead of using hand crafted parsing to get the current git state, we
use the existing vcs_info module, augmented by a few hooks to preserve
previous prompt functionality.

The prompt now also display the vi mode of ZLE on the left of the
username : [I] for insert mode, [N] for normal mode.

A lot of the inspiration for this refactor came from
https://github.com/frioux/dotfiles
For example the tweaks to the keybindings and completion.
This commit is contained in:
lhark 2018-02-26 03:18:40 -05:00
parent 36d5920e5e
commit 83f91a5034
4 changed files with 316 additions and 308 deletions

44
aliases Normal file
View file

@ -0,0 +1,44 @@
###########
# Aliases #
###########
alias acs='apt-cache search'
alias ls='ls --classify --tabsize=0 --literal --color=auto --show-control-chars -h'
alias ll='ls -lha'
alias l='sl'
alias lll='sl'
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 feh='feh --auto-rotate'
# 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'
# Le fameux cd ...etc
alias -g ...='../..'
alias -g ....='../../..'
alias -g .....='../../../..'
alias -g ......='../../../../..'
alias -g .......='../../../../../..'
alias -g ........='../../../../../../..'
# Hackish tweaks
alias steam-wine="WINEDEBUG=-all wine $WINEPREFIX/drive_c/Program\ Files\ \(x86\)/Steam/Steam.exe -no-dwrite -no-cef-sandbox &"
alias pacaur='AURDEST=$HOME/aur pacaur'
alias redwm='cd ~/aur/dwm-git; updpkgsums; makepkg -fi --noconfirm; killall dwm'
alias minecraft='java -jar $HOME/.minecraft/launcher.jar'
alias rot13="tr '[A-Za-z]' '[N-ZA-Mn-za-m]'"
alias shuffle='mpv --shuffle --no-audio-display'
alias steam="LD_PRELOAD='/usr/\$LIB/libstdc++.so.6 /usr/\$LIB/libgcc_s.so.1 /usr/\$LIB/libxcb.so.1 /usr/\$LIB/libgpg-error.so' /usr/bin/steam"
alias surftor='http_proxy=socks5://127.0.0.1:9050/ surf'
alias ytmp3='youtube-dl -x --audio-format mp3 --no-playlist -o "%(title)s.%(ext)s"'
# Fix pour archlinux
alias zbarcam='LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so zbarcam'
# vim: ft=zsh

243
functions
View file

@ -1,240 +1,16 @@
#!/bin/zsh
################################################################################
# Utility functions for the prompt #
# Debugging #
################################################################################
local ZSH_THEME_VIRTUALENV_PREFIX=" %{$fg_bold[green]%}(%{%b$fg[green]%}"
local ZSH_THEME_VIRTUALENV_SUFFIX="%{$reset_color$fg_bold[green]%})%{$reset_color%}"
# Depending if root or not, displays the right prompt char
# and changes the color of the username
color_username () {
if [[ $EUID -eq 0 ]]; then
echo "%{$fg_bold[red]%}%n"
else
echo "%{$fg_bold[green]%}%n"
fi
# Global counter that can be used to diagnose duplicated calls
printf "0" > /dev/shm/debug_counter
debug_counter_inc() {
count="$(cat /dev/shm/debug_counter)"
((count++))
printf "%d" "$count" > /dev/shm/debug_counter
}
color_prompt_char () {
if [[ $EUID -eq 0 ]]; then
echo "%{$fg_no_bold[red]%}#%{$reset_color%}"
else
echo "%{$fg_no_bold[green]%}$%{$reset_color%}"
fi
}
# Host coloring, specific to Rezometz
color_host () {
local couleur_hote=""
case $HOST in
TwelveYearsAndStillGoingStrong|lharkinateur|BecauseROSThatSWhy|lharktop|blieuxor)
couleur_hote=cyan;;
chimay|orval)
couleur_hote=magenta;;
babel|taima|era|vidar|okami|athena)
couleur_hote=red;;
loki|skadi)
couleur_hote=blue;;
*)
couleur_hote=white;;
esac
echo "%{$fg_bold[$couleur_hote]%}%m"
}
function virtualenv_prompt_info(){
[[ -n ${VIRTUAL_ENV} ]] || return
echo "${ZSH_THEME_VIRTUALENV_PREFIX:=[}${VIRTUAL_ENV:t}${ZSH_THEME_VIRTUALENV_SUFFIX:=]}"
}
last_status () {
echo "%(?..%{$fg_no_bold[red]%}[%?])"
}
# 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="%{%}$(virtualenv_prompt_info)"
echo "$_GIT_CHAR$_VENV_PROMPT$(last_status) $(color_prompt_char)"
}
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 () {
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]%}●"
_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 ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[green]%}[%{$fg_bold[blue]%}"
local ZSH_THEME_GIT_PROMPT_SUFFIX="%{$fg_bold[green]%}]"
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
}
prompt_msg () {
# TODO clean up /dev/shm when prompt_msg not in use
# TODO Use unique filename in case multiple people use the same prompt
line=$(tail -1 /dev/shm/prompt_msg) 2> /dev/null
case $line in
update_rc)
msg="Update ready for rc. Run uprc to proceed";;
git_unpushed)
msg="You have unpushed business in $HOME/rc";;
git_network_unreachable)
msg="Can't reach rc git repo";;
update_sys*)
nb_pkg=$(echo $line | grep -o '[0-9]*' | head -n 1)
msg="Update ready for the system. $nb_pkg new package$([ $nb_pkg -gt 1 ] && echo s)";;
*)
msg="";;
esac
# Remove last message from stack before it drives us mad
sed -i '$ d' /dev/shm/prompt_msg 2> /dev/null
echo $msg
}
################################################################################
# Prompt display #
################################################################################
prompt_create () {
# Carriage return to give the prompt some air
PROMPT="%{$reset_color%}"$'\n'
# Username, red when logged as root
PROMPT+='$(color_username)'
# @ symbol
PROMPT+="%{$fg_bold[blue]%}@"
# Hostname, colors defined just above
PROMPT+="$(color_host)"
# White space to separate host from pwd
PROMPT+=" %{$reset_color%}"
# Current working directory, use ~ when needed
PROMPT+="%{$fg[yellow]%}"'%~'
# Display current message
PROMPT+="%{$fg[red]%} "'$(prompt_msg)'
# Change the background for the whole line and line feed
PROMPT+="%{$fg_bold[green]%}%E"$'\n'
# Prompt characters for virtualenv, git and zsh
PROMPT+='$(_prompt_chars)'" %{$reset_color%}"
# Right prompt with current repo informations
RPROMPT='$(space_sh_git_prompt)'"%E%{$reset_color%}"
#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
eval PROMPT='$PROMPT'
eval RPROMPT='$RPROMPT'
debug_counter_print(){
printf "%d" "$(cat /dev/shm/debug_counter)"
}
################################################################################
@ -308,3 +84,4 @@ man() {
man "$@"
}
# vim: ft=zsh

222
prompt Normal file
View file

@ -0,0 +1,222 @@
################################################################################
# Utility functions for the prompt #
################################################################################
# Depending if root or not, displays the right prompt char
# and changes the color of the username
color_username () {
if [[ $EUID -eq 0 ]]; then
echo "%{$fg_bold[red]%}%n"
else
echo "%{$fg_bold[green]%}%n"
fi
}
color_prompt_char () {
if [[ $EUID -eq 0 ]]; then
echo "%{$fg_no_bold[red]%}#%{$reset_color%}"
else
echo "%{$fg_no_bold[green]%}$%{$reset_color%}"
fi
}
# Host coloring, specific to Rezometz
color_host () {
local couleur_hote=""
case $HOST in
TwelveYearsAndStillGoingStrong|lharkinateur|BecauseROSThatSWhy|lharktop|blieuxor)
couleur_hote=cyan;;
chimay|orval)
couleur_hote=magenta;;
babel|taima|era|vidar|okami|athena)
couleur_hote=red;;
loki|skadi)
couleur_hote=blue;;
*)
couleur_hote=white;;
esac
echo "%{$fg_bold[$couleur_hote]%}%m"
}
last_status () {
echo "%(?..%{$fg_no_bold[red]%}[%?])"
}
virtual_env() {
local prefix=" %{$fg_bold[green]%}(%{%b$fg[green]%}"
local suffix="%{$reset_color$fg_bold[green]%})%{$reset_color%}"
[[ -n ${VIRTUAL_ENV} ]] || return
printf "${prefix}${VIRTUAL_ENV:t}${suffix}"
}
prompt_chars() {
local git_char=''
if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then
local git_char="%{$fg_no_bold[blue]%}±%{$reset_color%}"
fi
printf "${_GIT_CHAR}$(last_status) $(color_prompt_char)"
}
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%}
}
prompt_msg () {
# TODO clean up /dev/shm when prompt_msg not in use
# TODO Use unique filename in case multiple people use the same prompt
line=$(tail -1 /dev/shm/prompt_msg) 2> /dev/null
case $line in
update_rc)
msg="Update ready for rc. Run uprc to proceed";;
git_unpushed)
msg="You have unpushed business in $HOME/rc";;
git_network_unreachable)
msg="Can't reach rc git repo";;
update_sys*)
nb_pkg=$(printf "$line" | grep -o '[0-9]*' | head -n 1)
msg="Update ready for the system. $nb_pkg new package$([ $nb_pkg -gt 1 ] && printf "s")";;
*)
msg="";;
esac
# Remove last message from stack before it drives us mad
sed -i '$ d' /dev/shm/prompt_msg 2> /dev/null
echo $msg
}
# Display vim mode while using zle line editing
# https://dougblack.io/words/zsh-vi-mode.html
vim_mode () {
VIM_NORMAL="%{$fg_bold[red]%}[% N]% "
VIM_INSERT="%{$fg_bold[green]%}[% I]% "
VIM_PROMPT="${${KEYMAP/vicmd/$VIM_NORMAL}/(main|viins)/$VIM_INSERT}"
echo "$VIM_PROMPT%{$reset_color%}"
}
# set formats
# %R - repository path
# %S - path in the repository
# %a - action (e.g. rebase-i)
# %b - branchname
# %c - stangedstr (see below)
# %i - The current revision number or identifier.
# %m - Misc. In case of Git, show information about stashes
# %r - The name of the root directory of the repository
# %s - The current version control system, like git or svn
# %u - unstagedstr (see below)
vcs_color='blue'
fmt_branch="%b%{$reset_color%} %u%c%m%{$reset_color%}" # e.g. master¹²
fmt_action="(%{$fg[red]%}%a%{$reset_color%})" # e.g. (rebase-i)
fmt_pre="%{$fg_bold[$vcs_color]%}[%{$reset_color%}%{$fg[$vcs_color]%}"
fmt_post="%{$fg_bold[$vcs_color]%}]%{$reset_color%}"
# check-for-changes can be really slow.
# you should disable it, if you work with large repositories
zstyle ':vcs_info:*' enable git cvs svn
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' unstagedstr "%{$fg_no_bold[yellow]%}●"
zstyle ':vcs_info:*' stagedstr "%{$fg_no_bold[green]%}●"
zstyle ':vcs_info:*' actionformats "${fmt_pre}${fmt_branch}${fmt_action}${fmt_post} "
zstyle ':vcs_info:*' formats "${fmt_pre}${fmt_branch}${fmt_post} "
zstyle ':vcs_info:*' nvcsformats ""
zstyle ':vcs_info:*+*:*' debug false # Set to true to see which hooks are being run
zstyle ':vcs_info:git*+set-message:*' hooks git-st git-untracked
### git: Show marker red (●) if there are untracked files in repository
# Make sure you have added staged to your 'formats': %c
+vi-git-untracked(){
if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == 'true' ]] && \
git status --porcelain | grep '??' &> /dev/null ; then
# This will show the marker if there are any untracked files in repo.
# If instead you want to show the marker only if there are untracked
# files in $PWD, use:
#[[ -n $(git ls-files --others --exclude-standard) ]] ; then
hook_com[unstaged]="%{$fg_no_bold[red]%}●%{$reset_color%}"$hook_com[unstaged]
fi
}
### git: Show ▴/▾ when your local branch is ahead-of or behind remote HEAD.
# Make sure you have added misc to your 'formats': %m
+vi-git-st() {
local ahead behind gitstatus
# 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+="%{$fg_no_bold[cyan]%}▴%{$reset_color%}"
# 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+="%{$fg_no_bold[magenta]%}▾%{$reset_color%}"
hook_com[misc]+=${gitstatus}
}
precmd() { vcs_info }
prompt_create zle-line-init zle-keymap-select () {
# Carriage return to give the prompt some air
PROMPT="%{$reset_color%}"$'\n'
# Username, red when logged as root
PROMPT+="$(vim_mode) $(color_username)"
# @ symbol
PROMPT+="%{$fg_bold[blue]%}@"
# Hostname, colors defined just above
PROMPT+="$(color_host)"
# White space to separate host from pwd
PROMPT+=" %{$reset_color%}"
# Current working directory, use ~ when needed
PROMPT+="%{$fg[yellow]%}"'%~'
# Display current message
PROMPT+="%{$fg[red]%} $(prompt_msg)"
# Change the background for the whole line and line feed
PROMPT+="%{$fg_bold[green]%}%E"$'\n'
# Prompt characters for virtualenv, git and zsh
PROMPT+="$(virtual_env)$(prompt_chars) %{$reset_color%}"
# Right prompt with current repo informations
RPROMPT="${vcs_info_msg_0_}%E%{$reset_color%}"
zle reset-prompt
}
# vim: ft=zsh

115
zshrc
View file

@ -8,7 +8,6 @@
# adapté et amélioré par lhark
export PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin:~/bin:/opt/cuda/bin
export EDITOR=/usr/bin/vim
# Prevent mime associations by wine
@ -19,74 +18,31 @@ export CUDA_ROOT=/opt/cuda
export ANDROID_HOME="$HOME/.android"
export PATH="$PATH:$ANDROID_HOME/tools/bin:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools"
# Get rc dir path
RC_PATH=$(dirname "$(readlink -f ${(%):-%x})")
# Import utility functions
. "$RC_PATH/functions"
# Check for rc updates in the background
(check_rc_update&) 2> /dev/null
# Check for system updates inthe background
(check_sys_update&) 2> /dev/null
# Configuration for virtualenv
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh > /dev/null 2>&1
source /usr/bin/virtualenvwrapper.sh > /dev/null 2>&1
# disables prompt mangling in virtual_env/bin/activate
export VIRTUAL_ENV_DISABLE_PROMPT=1
# Configuration for ROS
source /opt/ros/indigo/setup.zsh > /dev/null 2>&1
export PYTHONPATH=/opt/ros/indigo/lib/python2.7/site-packages:$PYTHONPATH
export PKG_CONFIG_PATH="/opt/ros/indigo/lib/pkgconfig:$PKG_CONFIG_PATH"
# Get rc dir path
RC_PATH=$(dirname "$(readlink -f ${(%):-%x})")
###########
# Aliases #
###########
# Import utility functions
. "$RC_PATH/functions"
. "$RC_PATH/aliases"
. "$RC_PATH/prompt"
alias acs='apt-cache search'
alias ls='ls --classify --tabsize=0 --literal --color=auto --show-control-chars -h'
alias ll='ls -lha'
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'
# Le fameux cd ...etc
alias -g ...='../..'
alias -g ....='../../..'
alias -g .....='../../../..'
alias -g ......='../../../../..'
alias -g .......='../../../../../..'
alias -g ........='../../../../../../..'
# Hackish tweaks
alias steam-wine="WINEDEBUG=-all wine $WINEPREFIX/drive_c/Program\ Files\ \(x86\)/Steam/Steam.exe -no-dwrite -no-cef-sandbox >/dev/null 2>&1 &"
alias pacaur='AURDEST=$HOME/aur pacaur'
alias redwm='cd ~/aur/dwm-git; updpkgsums; makepkg -fi --noconfirm; killall dwm'
alias minecraft='java -jar $HOME/.minecraft/launcher.jar'
alias shuffle='mpv --shuffle --volume=50 --no-audio-display'
alias steam="LD_PRELOAD='/usr/\$LIB/libstdc++.so.6 /usr/\$LIB/libgcc_s.so.1 /usr/\$LIB/libxcb.so.1 /usr/\$LIB/libgpg-error.so' /usr/bin/steam"
alias surftor='http_proxy=socks5://127.0.0.1:9050/ surf'
alias ytmp3='youtube-dl -x --audio-format mp3 --no-playlist -o "%(title)s.%(ext)s"'
# Fix pour archlinux
alias zbarcam='LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so zbarcam'
# Check for rc updates in the background
(check_rc_update&) 2> /dev/null
# Check for system updates inthe background
(check_sys_update&) 2> /dev/null
# Term specific hacks
case $TERM in
@ -110,18 +66,15 @@ esac
###############
unsetopt rm_star_silent # Demande confirmation pour 'rm *' -> ou 'rm path/*'
unsetopt glob_dots # (disabled) Do not require a leading '.' in a filename to be matched explicitly.
setopt null_glob # Delete pattern when no match found, instead of erroring
unsetopt promptsubst # ZLE is handling prompt recalculation
# (disabled) If there is an unambiguous prefix to insert on
# the command line, that is done without a completion list being displayed
#setopt list_ambiguous
# >| doit être utilisés pour pouvoir écraser un fichier déjà existant ;
# >| doit être utilisé pour pouvoir écraser un fichier déjà existant ;
# # le fichier ne sera pas écrasé avec '>'
#unsetopt clobber
setopt auto_remove_slash # Auto remove slash at the end of autocomp when appropriate
setopt chase_links # Traite les liens symboliques comme il faut
setopt hist_verify # !! n\'est pas exécuté directement
setopt promptsubst # Enable prompt substitution: vars are recalculated. you need '$foo'
setopt hist_ignore_all_dups # Only keep last version of duplicate command
setopt sharehistory # Import new cmds from hist file & append typed cmds
setopt hist_ignore_space # Ignore cmds with leading space
@ -130,10 +83,9 @@ setopt pushdsilent # Silent pushd & popd
setopt pushdtohome # pushd = pushd $HOME
setopt pushdignoredups
setopt pushdminus # This reverts the +/- operators for pushd.
setopt extendedglob # Treat '#', '~' and '^' chars as part of patterns for filenames, etc.
setopt nobeep # Beeps are a pain
EXPORTTIME=0 # (Disabled) Display command execution time
COMPLETION_WAITING_DOTS=1 # Display red dots while zsh autocompletes
HISTSIZE=10000000
SAVEHIST=10000000
HISTFILE=~/.history
@ -144,7 +96,13 @@ HISTTIMEFORMAT="%d/%m %H:%M:%S "
# Completion options #
######################
zstyle ':vcs_info:*' enable git cvs svn
unsetopt glob_dots # (disabled) Do not require a leading '.' in a filename to be matched explicitly.
setopt auto_remove_slash # Auto remove slash at the end of autocomp when appropriate
setopt completeinword # If the cursor is inside a word, completion is done from both ends
setopt extendedglob # Treat '#', '~' and '^' chars as part of patterns for filenames, etc.
setopt globcomplete # When the current word has a glob pattern, do not insert all the words resulting from the expansion
setopt null_glob # Delete pattern when no match found, instead of erroring
zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}'
zstyle ':completion:*' max-errors 3 numeric
zstyle ':completion:*' use-compctl false
@ -155,7 +113,7 @@ 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-colors "=(#b) #([0-9]#)*=36=31"
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
@ -164,7 +122,9 @@ zstyle ':completion:*' use-compctl false
zstyle ':completion:*' verbose true
# Des couleurs pour la complétion cf kill -9 <tab><tab>
zstyle ':completion:*:*:kill:*:processes' list-colors "=(#b) #([0-9]#)*=36=31"
zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'
zstyle ':completion:*:processes' command 'ps -au$USER -o pid,time,cmd|grep -v "ps -au$USER -o pid,time,cmd"'
# Separate man page sections. Neat.
zstyle ':completion:*:manuals' separate-sections true
# 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>
@ -179,20 +139,22 @@ zstyle ':completion:*' cache-path ~/.zs
zmodload zsh/complist
autoload -U compinit promptinit colors
compinit
promptinit
colors
autoload -Uz vcs_info
autoload -U zsh-mime-setup
autoload -U zsh-mime-handler
zsh-mime-setup
###################
# Prompt creation #
###################
prompt_create
################
# Prompt setup #
################
autoload -Uz vcs_info
promptinit
# Set timeout to 0.1s for switching to normal mode (might interfere with other apps)
export KEYTIMEOUT=1
zle -N zle-line-init
zle -N zle-keymap-select
##################
# Keyboard setup #
@ -210,8 +172,11 @@ 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
# Vim style incremental search
bindkey -M vicmd "/" history-incremental-search-backward
bindkey -M vicmd "?" history-incremental-search-forward
# Push the current command to the stack. ZLE will pop it on the next prompt
bindkey -M vicmd "q" push-line
# Page Up/Down
bindkey "^[[5~" history-beginning-search-backward
bindkey "^[[6~" history-beginning-search-forward