mirror of
https://github.com/hcartiaux/dotfiles.git
synced 2024-10-18 09:15:24 +02:00
[zsh] Initial commit
This commit is contained in:
parent
d49157d160
commit
597b800adc
2 changed files with 276 additions and 0 deletions
135
zsh/prompt_hyacinthe_setup
Normal file
135
zsh/prompt_hyacinthe_setup
Normal file
|
@ -0,0 +1,135 @@
|
|||
# hyacinthe prompt theme with git support
|
||||
# Derivated from <http://sebastiancelis.com/2009/11/16/zsh-prompt-git-users/>
|
||||
|
||||
prompt_hyacinthe_help () {
|
||||
cat <<'EOF'
|
||||
|
||||
This prompt is color-scheme-able. You can invoke it thus:
|
||||
|
||||
prompt hyacinthe [<color1> [<color2> [<color3> [<color4> [<color5>]]]]]
|
||||
|
||||
The defaults colors are red, cyan, green, white, and yellow, respectively.
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
prompt_hyacinthe_setup () {
|
||||
|
||||
local p_date p_userpwd p_end p_win
|
||||
local -A pc
|
||||
|
||||
setopt prompt_subst
|
||||
|
||||
pcc[1]=${1:-${${SSH_CLIENT+'yellow'}:-'red'}}
|
||||
pcc[2]=${2:-'cyan'}
|
||||
|
||||
if [[ "$USERNAME" == "root" ]] ; then
|
||||
pcc[3]=${3:-'red'}
|
||||
else
|
||||
pcc[3]=${3:-'green'}
|
||||
fi
|
||||
|
||||
pcc[4]=${4:-'white'}
|
||||
pcc[5]=${5:-'yellow'}
|
||||
|
||||
pc['\[']="%F{$pcc[1]}["
|
||||
pc['\]']="%F{$pcc[1]}]"
|
||||
pc['<']="%F{$pcc[1]}<"
|
||||
pc['>']="%F{$pcc[1]}>"
|
||||
pc['\(']="%F{$pcc[1]}("
|
||||
pc['\)']="%F{$pcc[1]})"
|
||||
|
||||
p_date="$pc['\[']%F{$pcc[2]}%D{%R}$pc['\]']"
|
||||
|
||||
[[ -n "$WINDOW" ]] && p_win="$pc['\(']%F{$pcc[4]}$WINDOW$pc['\)']"
|
||||
|
||||
p_userpwd="$pc['<']%F{$pcc[3]}%n@%m$p_win%F{$pcc[5]}:%F{$pcc[4]}%~$pc['>']"
|
||||
|
||||
p_end="%f%B%#%b "
|
||||
|
||||
zle_highlight[(r)default:*]=default:$pcc[2]
|
||||
prompt="$p_date $p_userpwd $p_end"
|
||||
PS2='%(4_.\.)%3_> %E'
|
||||
|
||||
add-zsh-hook precmd update_git_vars
|
||||
add-zsh-hook preexec preexec_update_git_vars
|
||||
add-zsh-hook chpwd update_git_vars
|
||||
}
|
||||
|
||||
update_current_git_vars()
|
||||
{
|
||||
unset __CURRENT_GIT_BRANCH
|
||||
unset __CURRENT_GIT_BRANCH_STATUS
|
||||
unset __CURRENT_GIT_BRANCH_IS_DIRTY
|
||||
|
||||
local st="$(git status 2>/dev/null)"
|
||||
if [[ -n "$st" ]]; then
|
||||
local -a arr
|
||||
arr=(${(f)st})
|
||||
|
||||
if [[ $arr[1] =~ 'Not currently on any branch.' ]]; then
|
||||
__CURRENT_GIT_BRANCH='no-branch'
|
||||
else
|
||||
__CURRENT_GIT_BRANCH="${arr[1][(w)4]}";
|
||||
fi
|
||||
|
||||
if [[ $arr[2] =~ 'Your branch is' ]]; then
|
||||
if [[ $arr[2] =~ 'ahead' ]]; then
|
||||
__CURRENT_GIT_BRANCH_STATUS='ahead'
|
||||
elif [[ $arr[2] =~ 'diverged' ]]; then
|
||||
__CURRENT_GIT_BRANCH_STATUS='diverged'
|
||||
else
|
||||
__CURRENT_GIT_BRANCH_STATUS='behind'
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ ! $st =~ 'nothing to commit' ]]; then
|
||||
__CURRENT_GIT_BRANCH_IS_DIRTY='1'
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
prompt_git_info()
|
||||
{
|
||||
if [ -n "$__CURRENT_GIT_BRANCH" ]; then
|
||||
local s="("
|
||||
case "$__CURRENT_GIT_BRANCH_STATUS" in
|
||||
ahead)
|
||||
s+="↑"
|
||||
;;
|
||||
diverged)
|
||||
s+="↕"
|
||||
;;
|
||||
behind)
|
||||
s+="↓"
|
||||
;;
|
||||
esac
|
||||
if [ -n "$__CURRENT_GIT_BRANCH_IS_DIRTY" ]; then
|
||||
s+="⚡"
|
||||
fi
|
||||
s+="$__CURRENT_GIT_BRANCH"
|
||||
s+=")"
|
||||
|
||||
printf " %s%s" "%{${fg[yellow]}%}" $s
|
||||
fi
|
||||
}
|
||||
|
||||
preexec_update_git_vars()
|
||||
{
|
||||
case "$1" in
|
||||
git*)
|
||||
__EXECUTED_GIT_COMMAND=1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
update_git_vars() {
|
||||
update_current_git_vars
|
||||
|
||||
if [ "$__CURRENT_GIT_BRANCH" != "no-branch" ] ; then
|
||||
RPROMPT="%F{$pcc[3]}$(prompt_git_info)"
|
||||
fi
|
||||
}
|
||||
|
||||
prompt_hyacinthe_setup "$@"
|
||||
|
141
zsh/zshrc
Executable file
141
zsh/zshrc
Executable file
|
@ -0,0 +1,141 @@
|
|||
source /etc/profile
|
||||
|
||||
autoload -U promptinit compinit
|
||||
promptinit
|
||||
compinit
|
||||
|
||||
setopt autopushd pushdminus pushdsilent pushdtohome
|
||||
setopt autocd
|
||||
setopt cdablevars
|
||||
setopt interactivecomments
|
||||
setopt nobanghist
|
||||
setopt noclobber
|
||||
setopt HIST_REDUCE_BLANKS
|
||||
setopt HIST_IGNORE_SPACE
|
||||
setopt SH_WORD_SPLIT
|
||||
setopt nohup
|
||||
setopt correctall
|
||||
setopt chase_links
|
||||
unsetopt ignore_eof
|
||||
unsetopt rm_star_silent
|
||||
unsetopt list_ambiguous
|
||||
|
||||
export SVN_EDITOR=vim
|
||||
export EDITOR="vim"
|
||||
|
||||
eval `dircolors -b`
|
||||
|
||||
zstyle ':completion:*:descriptions' format '%U%B%d%b%u'
|
||||
zstyle ':completion:*:warnings' format '%BDésolé, pas de résultats pour : %d%b'
|
||||
zstyle ':completion:*' menu select=2
|
||||
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
|
||||
zstyle ':completion:*:rm:*' ignore-line yes
|
||||
zstyle ':completion:*:mv:*' ignore-line yes
|
||||
zstyle ':completion:*:cp:*' ignore-line yes
|
||||
|
||||
# allow approximate
|
||||
zstyle ':completion:*' completer _complete _match _approximate
|
||||
zstyle ':completion:*:match:*' original only
|
||||
zstyle ':completion:*:approximate:*' max-errors 1 numeric
|
||||
# tab completion for PID :D
|
||||
zstyle ':completion:*:*:kill:*' menu yes select
|
||||
zstyle ':completion:*:kill:*' force-list always
|
||||
# cd not select parent dir.
|
||||
zstyle ':completion:*:cd:*' ignore-parents parent pwd
|
||||
|
||||
|
||||
##################################################################
|
||||
## Key bindings
|
||||
## http://mundy.yazzy.org/unix/zsh.php
|
||||
## http://www.zsh.org/mla/users/2000/msg00727.html
|
||||
#
|
||||
typeset -g -A key
|
||||
bindkey "\e[1~" beginning-of-line
|
||||
bindkey "\e[4~" end-of-line
|
||||
bindkey "\e[5~" beginning-of-history
|
||||
bindkey "\e[6~" end-of-history
|
||||
bindkey "\e[3~" delete-char
|
||||
bindkey "\e[2~" quoted-insert
|
||||
bindkey "\e\e[C" forward-word
|
||||
bindkey "\e\e[D" backward-word
|
||||
|
||||
bindkey '5D' emacs-backward-word
|
||||
bindkey '5C' emacs-forward-word
|
||||
|
||||
bindkey "^H" backward-delete-word
|
||||
# for rxvt
|
||||
bindkey "\e[8~" end-of-line
|
||||
bindkey "\e[7~" beginning-of-line
|
||||
# for non RH/Debian xterm, can't hurt for RH/DEbian xterm
|
||||
bindkey "\eOH" beginning-of-line
|
||||
bindkey "\eOF" end-of-line
|
||||
# for freebsd console
|
||||
bindkey "\e[H" beginning-of-line
|
||||
bindkey "\e[F" end-of-line
|
||||
# completion in the middle of a line
|
||||
bindkey '^i' expand-or-complete-prefix
|
||||
|
||||
alias vi='/usr/bin/vim'
|
||||
alias ls='/bin/ls --color=auto -F --group-directories-first -h'
|
||||
alias ll='/bin/ls -l --color=auto'
|
||||
alias la='ll -a'
|
||||
alias lh='la -h'
|
||||
|
||||
export GREP_COLOR=31
|
||||
alias grep='grep --color=auto'
|
||||
|
||||
alias top='htop'
|
||||
|
||||
alias cp='cp -iv'
|
||||
alias mv='mv -iv'
|
||||
alias rm='rm -i'
|
||||
[ -x /usr/bin/most ] && alias more='most' && alias less='most'
|
||||
|
||||
# read man in vim with colors
|
||||
man() {
|
||||
/usr/bin/man $* | \
|
||||
col -b | \
|
||||
vim -R -c 'set ft=man nomod nolist' -
|
||||
}
|
||||
|
||||
# This will set the default prompt
|
||||
source ~/.zsh/prompt_hyacinthe_setup
|
||||
|
||||
# type a directory's name to cd to it.
|
||||
compctl -/ cd
|
||||
|
||||
# history
|
||||
|
||||
HISTFILE=~/.zhistory
|
||||
HISTSIZE=10000
|
||||
SAVEHIST=10000
|
||||
setopt appendhistory
|
||||
setopt incappendhistory
|
||||
|
||||
# git
|
||||
unset SSH_ASKPASS
|
||||
|
||||
# Syntax highlighting
|
||||
source ~/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
|
||||
|
||||
|
||||
# Personal aliases
|
||||
|
||||
alias -s pdf="/usr/bin/xpdf "
|
||||
alias killflash=" ps aux | grep flash | xargs | cut -d' ' -f2 | xargs kill"
|
||||
alias ssha="ssh-add ~/.ssh/id_dsa"
|
||||
alias sshg="ssh-add ~/.ssh/id_rsa_uni"
|
||||
alias cdpuppet="cd ~/Uni.lu-repos/puppet-repo"
|
||||
alias cdsys="~/Uni.lu-repos/sysadmins-repo"
|
||||
|
||||
# g5k alias
|
||||
alias puppetplay='bundle exec puppetplay'
|
||||
alias g5kcap='bundle exec cap'
|
||||
alias g5k="~/Grid5000"
|
||||
alias g5kpuppet="~/Grid5000/git.grid5000.fr/puppet-repo"
|
||||
|
||||
|
||||
# RVM
|
||||
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
|
||||
PATH=$PATH:/usr/lib/ruby/gems/1.9.1/bin/:$HOME/.rvm/bin # Add RVM to PATH for scripting
|
||||
|
Loading…
Reference in a new issue