#!/usr/bin/env zsh
# _________ _ _ ____ ____
# |__ / ___|| | | | _ \ / ___|
# / /\___ \| |_| | |_) | |
# _ / /_ ___) | _ | _ <| |___
#(_)____|____/|_| |_|_| \_\\____|
#
# PROMPT
#PS1="|%D|%T| %n@%m:%~%# "
function precmd {
local TERMWIDTH
(( TERMWIDTH = ${COLUMNS} - 1 ))
###
# Truncate the path if it's too long.
PR_FILLBAR=""
PR_PWDLEN=""
local promptsize=${#${(%):---(%n@%m--)-()--}}
local pwdsize=${#${(%):-%~}}
if [[ "$promptsize + $pwdsize" -gt $TERMWIDTH ]]; then
((PR_PWDLEN=$TERMWIDTH - $promptsize))
else
PR_FILLBAR="\${(l.(($TERMWIDTH - ($promptsize + $pwdsize)))..${PR_HBAR}.)}"
fi
###
# Get APM info.
#if which ibam > /dev/null; then
#PR_APM_RESULT=`ibam --percentbattery`
#elif which apm > /dev/null; then
#PR_APM_RESULT=`apm`
#fi
}
setopt extended_glob
preexec () {
if [[ "$TERM" == "screen" ]]; then
local CMD=${1[(wr)^(*=*|sudo|-*)]}
echo -n "\ek$CMD\e\\"
fi
}
setprompt () {
###
# Need this so the prompt will work.
setopt prompt_subst
###
# See if we can use colors.
autoload colors zsh/terminfo
#if [[ "$terminfo[colors]" -ge 8 ]]; then
#colors
#fi
#for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
#eval PR_$color='%{$terminfo[bold]$fg[${(L)color}]%}'
#eval PR_LIGHT_$color='%{$fg[${(L)color}]%}'
#(( count = $count + 1 ))
#done
PR_NO_COLOUR="%{$terminfo[sgr0]%}"
###
# See if we can use extended characters to look nicer.
typeset -A altchar
set -A altchar ${(s..)terminfo[acsc]}
PR_SET_CHARSET="%{$terminfo[enacs]%}"
PR_SHIFT_IN="%{$terminfo[smacs]%}"
PR_SHIFT_OUT="%{$terminfo[rmacs]%}"
PR_HBAR=${altchar[q]:--}
PR_ULCORNER=${altchar[l]:--}
PR_LLCORNER=${altchar[m]:--}
PR_LRCORNER=${altchar[j]:--}
PR_URCORNER=${altchar[k]:--}
###
# Decide if we need to set titlebar text.
case $TERM in
xterm*)
PR_TITLEBAR=$'%{\e]0;%(!.-=*[ROOT]*=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\a%}'
;;
screen)
PR_TITLEBAR=$'%{\e_screen \005 (\005t) | %(!.-=[ROOT]=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\e\\%}'
;;
*)
PR_TITLEBAR=''
;;
esac
###
# Decide whether to set a screen title
if [[ "$TERM" == "screen" ]]; then
PR_STITLE=$'%{\ekzsh\e\\%}'
else
PR_STITLE=''
fi
###
# APM detection
if which ibam > /dev/null; then
PR_APM='$PR_RED${${PR_APM_RESULT[(f)1]}[(w)-2]}%%(${${PR_APM_RESULT[(f)3]}[(w)-1]})$PR_LIGHT_BLUE:'
elif which apm > /dev/null; then
PR_APM='$PR_RED${PR_APM_RESULT[(w)5,(w)6]/\% /%%}$PR_LIGHT_BLUE:'
else
PR_APM=''
fi
###
# Finally, the prompt.
PROMPT='$PR_SET_CHARSET$PR_STITLE${(e)PR_TITLEBAR}\
$PR_CYAN$PR_SHIFT_IN$PR_ULCORNER$PR_BLUE$PR_HBAR$PR_SHIFT_OUT|\
$PR_GREEN%(!.%SROOT%s.%n)$PR_GREEN@%m\
$PR_BLUE|$PR_SHIFT_IN$PR_HBAR$PR_CYAN$PR_HBAR${(e)PR_FILLBAR}$PR_BLUE$PR_HBAR$PR_SHIFT_OUT|\
$PR_MAGENTA%$PR_PWDLEN<...<%~%<<\
$PR_BLUE|$PR_SHIFT_IN$PR_HBAR$PR_CYAN$PR_URCORNER$PR_SHIFT_OUT\
$PR_CYAN$PR_SHIFT_IN$PR_LLCORNER$PR_BLUE$PR_HBAR$PR_SHIFT_OUT|\
%(?..$PR_LIGHT_RED%?$PR_BLUE:)\
${(e)PR_APM}$PR_YELLOW%D{%H:%M}\
$PR_LIGHT_BLUE$PR_BLUE|$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\
$PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\
$PR_NO_COLOUR '
RPROMPT=' $PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_BLUE$PR_HBAR$PR_SHIFT_OUT\
|$PR_YELLOW%D{%a %d %b}$PR_BLUE|$PR_SHIFT_IN$PR_HBAR$PR_CYAN$PR_LRCORNER$PR_SHIFT_OUT$PR_NO_COLOUR'
PS2='$PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\
$PR_BLUE$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT(\
$PR_LIGHT_GREEN%_$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\
$PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT$PR_NO_COLOUR '
}
setprompt
# MODULES
autoload -U zfinit compinit promptinit
zfinit
compinit
promptinit
autoload -U zsh-mime-setup
autoload -U zsh-mime-handler
zsh-mime-setup
#OPTIONS
zmodload zsh/complist
setopt extendedglob
setopt extendedglob
setopt autocd
setopt hist_ignore_all_dups
setopt printexitvalue # alert me if something's failed
setopt nohup
setopt NO_HUP
setopt NO_BEEP
setopt INC_APPEND_HISTORY # write after each command
setopt ALL_EXPORT
setopt correctall # Correction des commandes
# ALIAS
alias ls='ls --color=auto'
alias ll='ls --color=auto -lh'
alias lll='ls --color=auto -lh | less'
alias logout='openbox --exit'
alias reboot='dbus-send --system --print-reply --dest="org.freedesktop.Hal" /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Reboot'
alias shutdown='dbus-send --system --print-reply --dest="org.freedesktop.Hal" /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Shutdown'
alias ys='yaourt -S'
alias ysu='yaourt -Su'
alias ysyu='yaourt -Syu'
alias ysy='yaourt -Sy'
alias yqi='yaourt -Qi'
alias yql='yaourt -Ql'
alias xs='cd'
alias sl='ls'
alias mplayerfb='mplayer -vo fbdev -vf scale=1024:768'
alias grep='grep --color=auto' # Un grep avec des couleurs
alias -s html=pick-web-browser
# EXPORT
export GREP_COLOR=31
export EDITOR=/usr/bin/geany
export BROWSER=/usr/bin/chromium
export HISTSIZE=2000
export SAVEHIST=2000
export HISTFILE="$HOME/.history"
# MIMES
zstyle ':mime:.odt:' handler oowriter %s
zstyle ':mime:.doc:' handler oowriter %s
zstyle ':mime:.ods:' handler oocalc %s
zstyle ':mime:.xls:' handler oocalc %s
zstyle ':mime:.abw:' handler abiword %s
zstyle ':mime:.txt:' handler geany %s
zstyle ':mime:.pdf:' handler epdfview %s
zstyle ':mime:.mp3:' handler vlc %s
zstyle ':mime:.ogg:' handler vlc %s
zstyle ':mime:.flac:' handler vlc %s
zstyle ':mime:.avi:' handler vlc %s
zstyle ':mime:.wmv:' handler vlc %s
zstyle ':mime:.mpg:' handler vlc %s
zstyle ':mime:.mpeg:' handler vlc %s
zstyle ':mime:.flv:' handler vlc %s
zstyle ':mime:.png:' handler viewnior %s
zstyle ':mime:.jpg:' handler viewnior %s
zstyle ':mime:.jpeg:' handler viewnior %s
zstyle ':mime:*' x-browsers chromium firefox
# COMPLETION
zstyle ':completion:*:descriptions' format '%U%B%d%b%u'
zstyle ':completion:*:warnings' format '%BSorry, no matches for: %d%b'
zstyle ':completion:*:sudo:*' command-path /usr/local/sbin /usr/sbin /usr/bin # pour qua la commande cd offre une completion sur les répertoires locaux puis ceux de la variable cdpath
zstyle ':completion:*:*:cd:*' tag-order local-directories path-directories # pour obtenir un menu conviviale pour le completion (avec les flèches du clavier)
zstyle ':completion:*' menu select=2
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s # Pour éviter de reproposer un argument déjà utiliser dans la commande lors de la completion
zstyle ':completion:*:rm:*' ignore-line yes
zstyle ':completion:*:mv:*' ignore-line yes
zstyle ':completion:*:cp:*' ignore-line yes
zstyle ':completion:*:*:kill:*:processes' list-colors "=(#b) #([0-9]#)*=36=31"
# 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 ~/.zsh_cache
zstyle ':completion:*:*:kill:*:processes' list-colors "=(#b)
#([0-9]#)*=36=31"
# Pour que les commandes qui demande un host en argument : ssh, telnet, etc. puissent utiliser les hosts connus par ssh (~/.ssh/know_hosts)
local _myhosts
if [ -d ~/.ssh ]; then
if [ -f ~/.ssh/known_hosts ];then
_myhosts=(${=${${(f)"$(<$HOME/.ssh/known_hosts)"}%%[# ]*}//,/ })
fi
fi
zstyle ':completion:*' hosts $_myhosts
# AUTOSTART
python ~/.scripts/Arch_info/archey3.py -c white
Dernière modification par FoolEcho le lun. 15 août 2011, 15:53, modifié 1 fois.
Raison :+ lien sur l'autre sujet pour éviter de chercher
OS : Archlinux / Debian
DE : Gnome / KDE
Serveur : OpenMediaVault
# {{{ General settings
HISTFILE=~/.zsh_history
HISTSIZE=100000
SAVEHIST=100000
setopt append_history hist_ignore_all_dups hist_reduce_blanks
# Set default text editor to vim
export EDITOR="/usr/bin/vim"
# Host is not exported by default so export it
export HOST
# Auto-cd
setopt autocd
# Disable beeps
unsetopt beep
# Disable live job notifications
unsetopt notify
# Extended globbing
setopt extendedglob
# No = expansion
#unsetopt equals
# correction
#setopt correctall
# Remove RPS1 after <enter>
setopt transient_rprompt
# Color vars
autoload -U colors terminfo
colors
# Watch for login/logout
watch=all
# enable ccache for compilation
export PATH="/usr/lib/ccache/bin:$PATH"
# colored output for gcc (need colorgcc package)
export PATH="/usr/lib/colorgcc/bin:$PATH"
# add ~/.bin to binpath
PATH="$HOME/.bin:$PATH"
# Smart completion
zstyle :compinstall filename "$HOME/.zshrc"
autoload -Uz compinit
compinit
# Zargs pawa
autoload -U zargs
# enable keychain
if [[ $EUID -ne 0 ]]; then
if [ "$HOST" = "thor" ]; then
eval `keychain -q --eval --agents ssh id_ecdsa id_dsa`
elif [ "$HOST" = "vidar" ]; then
eval `keychain -q --eval --agents ssh id_dsa`
fi
fi
# {{ Stuff for VCS infos
local reset white gray green red yellow
reset="%{${reset_color}%}"
white="%{$fg[white]%}"
green="%{$fg_bold[green]%}"
red="%{$fg[red]%}"
blue="%{$fg[blue]%}"
yellow="%{$fg[yellow]%}"
autoload -Uz vcs_info
zstyle ':vcs_info:*' enable git hg
zstyle ':vcs_info:(hg*|git*):*' get-revision true
zstyle ':vcs_info:(hg*|git*):*' check-for-changes true
#zstyle ':vcs_info:hg*' formats "(%s)[%i%u %b %m]" # rev+changes branch misc
zstyle ':vcs_info:hg*' formats "[%i%u %b %m]" # rev+changes branch misc
#zstyle ':vcs_info:hg*' actionformats "(%s|${red}%a${white})[%i%u %b %m]"
zstyle ':vcs_info:hg*' actionformats "${red}%a ${white}[%i%u ${blue}%b${white}%m]"
zstyle ':vcs_info:hg*:*' get-bookmarks true
zstyle ':vcs_info:hg*:*' get-mq true
zstyle ':vcs_info:hg*:*' get-unapplied true
zstyle ':vcs_info:hg*:*' patch-format "mq(%g):%n/%c %p"
zstyle ':vcs_info:hg*:*' nopatch-format "mq(%g):%n/%c %p"
zstyle ':vcs_info:hg*:*' unstagedstr "${green}+${white}"
zstyle ':vcs_info:hg*:*' hgrevformat "%r" # only show local rev.
zstyle ':vcs_info:hg*:*' branchformat "%b" # only show branch
#zstyle ':vcs_info:git*' formats "(%s) %12.12i %c%u %b%m" # hash changes branch misc
zstyle ':vcs_info:git*' formats "%c%u %b%m" # hash changes branch misc
zstyle ':vcs_info:git*' actionformats "(%s|${white}%a) %12.12i %c%u %b%m"
zstyle ':vcs_info:git*:*' stagedstr "${green}S${white}"
zstyle ':vcs_info:git*:*' unstagedstr "${red}U${white}"
# zstyle ':vcs_info:hg:*:-all-' command fakehg
# zstyle ':vcs_info:*+*:*' debug true
zstyle ':vcs_info:hg*+set-hgrev-format:*' hooks hg-hashfallback
zstyle ':vcs_info:hg*+set-message:*' hooks mq-vcs
#zstyle ':vcs_info:git*+set-message:*' hooks git-st git-stash
zstyle ':vcs_info:git*+set-message:*' hooks git-untracked git-st
### Dynamically set hgrevformat based on if the local rev is available
# We don't always know the local revision, e.g. if use-simple is set
# Truncate long hash to 12-chars but also allow for multiple parents
function +vi-hg-hashfallback() {
if [[ -z ${hook_com[localrev]} ]] ; then
local -a parents
parents=( ${(s:+:)hook_com[hash]} )
parents=( ${(@r:12:)parents} )
hook_com[rev-replace]="${(j:+:)parents}"
ret=1
fi
}
### Show when mq itself is under version control
function +vi-mq-vcs() {
# if [[ -d ${hook_com[base]}/.hg/patches/.hg ]]; then
# hook_com[hg-mqpatch-string]="mq:${hook_com[hg-mqpatch-string]}"
# fi
}
# Show remote ref name and number of commits ahead-of or behind
function +vi-git-st() {
local ahead behind remote
local -a gitstatus
# Are we on a remote-tracking branch?
remote=${$(git rev-parse --verify ${hook_com[branch]}@{upstream} \
--symbolic-full-name --abbrev-ref 2>/dev/null)}
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+=( "${green}+${ahead}${white}" )
# 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+=( "${red}-${behind}${white}" )
#hook_com[branch]="${hook_com[branch]} [${remote} ${(j:/:)gitstatus}]"
hook_com[branch]="[${blue}${hook_com[branch]}${white}]"
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)"
hook_com[misc]+="(${red}${stashes} ${white}stashed)"
fi
}
# Show count of untracked files
function +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
local nb_untracked=$(git status --porcelain | grep "\? \?" | wc -l)
local nb_up=$(git status --porcelain | grep "M" | wc -l)
hook_com[staged]+="${white}$nb_untracked${red}N ${white}$nb_up"
fi
}
# }}
# }}}
# {{{ Keybindings
# vi keybindings
bindkey -v
# URxvt keys
bindkey '[2~' overwrite-mode
bindkey '[3~' delete-char
bindkey '[7~' beginning-of-line
bindkey '[8~' end-of-line
bindkey '[5~' history-search-backward
bindkey '[6~' history-search-forward
# Man
bindkey '^X^H' run-help
# Edit cmdline
autoload edit-command-line
zle -N edit-command-line
bindkey '^xe' edit-command-line
# Complete help
bindkey '^xc' _complete_help
# () [] {} ...
bindkey -s '((' '()\ei'
bindkey -s '( (' '( )\ehhi'
bindkey -s '(((' '(\ea( ))\ehhhi'
bindkey -s '{{' '{}\ei'
bindkey -s '{ {' '{ }\ehi'
bindkey -s '{{{' '{\ea{ }}\ehhhi' # }}} (quick and ugly folding fix...)
bindkey -s '[[' '[]\ei'
bindkey -s '[ [' '[ ]\ehhi'
bindkey -s '[[[' '[\ea[ ]]\ehhhi'
bindkey -s "''" "'\ea'\ei"
bindkey -s '""' '"\ea"\ei'
# }}}
# {{{ Per OS settings
function BSDconfig() {
alias ll="ls -loh"
alias lla="ls -lohA"
# GNU/ls like colors (used by zsh completion)
export LS_COLORS='rs=0:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:su=37;41:sg=30;43:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz'
}
case `uname -s` in
Darwin) # *khof*
BSDconfig
;;
FreeBSD)
BSDconfig
alias toor="sudo su -l toor"
hash -d ports=/usr/ports
hash -d src=/usr/src
;;
Linux)
if [[ -r ~/.dir_colors ]]; then
eval `dircolors -b ~/.dir_colors`
elif [[ -r /etc/DIR_COLORS ]]; then
eval `dircolors -b /etc/DIR_COLORS`
fi
# GNU ls colors
alias ls='ls --color=always'
alias ll="ls -lh"
alias lla="ls -lhA"
# try to buy some real useful stuff
alias realpath="/bin/readlink -f"
;;
esac
unfunction BSDconfig
# }}}
# {{{ Completion II
zmodload -a autocomplete
zmodload -a complist
# formatting and messages
zstyle ':completion:*' verbose yes
zstyle ':completion:*:descriptions' format "${fg_bold[yellow]}%B%d%b$end"
zstyle ':completion:*:messages' format '%d'
zstyle ':completion:*' group-name ''
zstyle :compinstall filename "$HOME/.zshrc"
zstyle ':completion:*' special-dirs true
zstyle ':completion:*:*:cd:*' tag-order local-directories path-directories
zstyle ':completion:*:rm:*' ignore-line yes
# color for completion
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
# menu for auto-completion
zstyle ':completion:*' menu select=2
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
# Completion Menu for kill
#zstyle ':completion:*:processes' command 'ps -u'
#zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;32'
zstyle ':completion:*:*:kill:*:processes' list-colors "=(#b) #([0-9]#)*=$color[cyan]=$color[red]"
zstyle ':completion:*:*:kill:*' menu yes select
#zstyle ':completion:*:*:kill:*' force-list always
# Cache
zstyle ':completion::complete:*' use-cache on
zstyle ':completion::complete:*' cache-path ~/.zsh/cache
# failed match * are passed literally
unsetopt nomatch
# }}}
# {{{ General aliases
# vim as manpager when available.
#which vimmanpager &>/dev/null && alias man="man -P vimmanpager"
export PAGER=/usr/bin/vimpager
alias man="man -P $PAGER"
alias less=$PAGER
alias zless=$PAGER
alias la="ls -A"
alias :q="exit"
alias sls="screen -list"
# secure risky commands
alias rm="rm -I"
alias mv="mv -i"
alias cp="cp -i"
# aliases for navigation
#alias cd="cd && ls"
alias ...="../.."
alias ....="../../.."
alias lin="~/Hacking/hg/lincopier/src/"
alias bor="~/Hacking/git/bor/"
alias cours="~/Documents/cours/3e/"
alias conf="~/Hacking/git/bor/conf/"
# aliases for programs
alias makeman="groff -man -Tascii"
#alias autoremove="sudo pacman -Rs `pacman -Qqtd`"
alias vless="vim -u /usr/share/vim/vim73/macros/less.vim"
alias vimrestore='vim -p $(find -name "*.swp" | sed "s:\(.*/\)\.\(.*\).swp\1\2"|xargs)'
alias prolog="swipl"
alias mpdthor="ncmpcpp -h 10.0.0.226 -p 42000"
alias memtop="ps -e o comm,%mem,rss,vsz --sort -rss | head -n 20"
alias reconfobmenu="mmaker -vf OpenBox3"
alias mnthor="sudo mount -t nfs -o proto=tcp,port=2049 10.0.0.226:/ /media/thor"
alias mntvideo="sudo mount -t ext4 /dev/sdb1 /mnt/Videos -o defaults,noatime"
alias pscan="sudo nmap -sS"
# global aliases
alias -g H='| head'
alias -g T='| tail'
alias -g G='| grep'
alias -g L="| less"
alias -g M="| most"
# alias for documents
#alias -s pdf="okular"
alias -s pdf="zathura"
# alias for playing movies
alias -s {mpg,mpeg,avi,ogm,wmv,m4v,mp4,mov,mkv}="mplayer"
# }}}
# {{{ Useful functions
# delete files an manage trash can
del () {
if [[ ! -d $HOME/.trash ]]; then
echo "Trash does not exist yet, creating it."
mkdir -v $HOME/.trash
fi
if [[ -z $1 ]]; then
ls -a $HOME/.trash
echo -n "Empty Trash? (y/n)"
if read -q; then
rm -rv $HOME/.trash/*
echo "Emptied trash."
else
echo "Doing nothing."
fi
elif [[ -f $1 ]]; then
mv -v $1 $HOME/.trash/
else
echo "Error: '$1' is not a regular file!"
fi
}
# create thumbnails: 1st argument is the picture and 2nd is the thumbnail size
thumbify () {
if [ -f $1 ]; then
cp $1 thumb-$1
if [ $2 ]; then
mogrify -resize $2 thumb-$1
else
mogrify -resize 250x250 thumb-$1
fi
else
echo "Error: '$1' is not a valid file!"
fi
}
# yep, that rocks
xtrct () {
if [ -f $1 ] ; then
case $1 in
*.bz2) bunzip2 $1 && cd $(basename "$1" /bz2) ;;
*.gz) gunzip $1 && cd $(basename "$1" .gz) ;;
*.rar) unrar x $1 && cd $(basename "$1" .rar) ;;
*.tar) tar xvf $1 && cd $(basename "$1" .tar) ;;
*.tar.bz2) tar xvjf $1 && cd $(basename "$1" .tar.bz2) ;;
*.tar.gz) tar xvzf $1 && cd $(basename "$1" .tar.gz) ;;
*.tar.xz) tar Jxvf $1 && cd $(basename "$1" .tar.xz) ;;
*.tbz2) tar xvjf $1 && cd $(basename "$1" .tbz2) ;;
*.tgz) tar xvzf $1 && cd $(basename "$1" .tgz) ;;
*.zip) unzip $1 && cd $(basename "$1" .zip) ;;
*.Z) uncompress $1 && cd $(basename "$1" .Z) ;;
*.7z) 7z x $1 && cd $(basename "$1" .7z) ;;
*) echo "don't know how to extract '$1'..." ;;
esac
else
echo "Error: '$1' is not a valid file!"
exit 0
fi
}
# now that we can extract, it is nice to be able to compress a folder too
# first arg is the compression type and second arg is the folder
#cmpr () {
#if [[ -n $1 && -d $2 ]]; then
#case $1 in
#rar) rar a -m5 -R $(basename $2).rar $2 ;;
#tar) tar cf $(basename $2).tar $2 ;;
#tar.bz2) tar cjf $(basename $2).tar.bz2 $2 ;;
#tar.gz) tar czf $(basename $2).tar.gz $2 ;;
#tar.xz) tar cJf $(basename $2).tar.xz $2 ;;
#zip) zip -r $(basename $2).zip $2 ;;
#7z) 7z a -t7z $(basename $2).7z $2 ;;
#*) echo "Well...I do not know how to compress this..." ;;
#esac
#elif [ !(-n $2) ]; then
#echo "Error: '$2' is not a valid directory!"
#exit 0
#else
#echo "Error: bad syintax!"
#exit 0
#fi
#}
# compress a file or folder
cmpr () {
case "$1" in
tar.bz2|.tar.bz2) tar cvjf "${2%%/}.tar.bz2" "${2%%/}/" ;;
tbz2|.tbz2) tar cvjf "${2%%/}.tbz2" "${2%%/}/" ;;
tbz|.tbz) tar cvjf "${2%%/}.tbz" "${2%%/}/" ;;
tar.gz|.tar.gz) tar cvzf "${2%%/}.tar.gz" "${2%%/}/" ;;
tar.Z|.tar.Z) tar Zcvf "${2%%/}.tar.Z" "${2%%/}/" ;;
tgz|.tgz) tar cvjf "${2%%/}.tgz" "${2%%/}/" ;;
tar|.tar) tar cvf "${2%%/}.tar" "${2%%/}/" ;;
rar|.rar) rar a "${2%%/}.rar" "${2%%/}/" ;;
zip|.zip) zip -r9 "${2}.zip" "$2" ;;
7z|.7z) 7z a "${2}.7z" "$2" ;;
lzo|.lzo) lzop -v "$2" ;;
gz|.gz) gzip -v "$2" ;;
bz2|.bz2) bzip2 -v "$2" ;;
xz|.xz) xz -v "$2" ;;
lzma|.lzma) lzma -v "$2" ;;
*) echo "Error, please go away.";;
esac
}
# function that updates the system
upd () {
if [ -f /usr/bin/pacman ]; then
if [[ $UID -eq 0 ]]; then
pacman -Syy
else
sudo pacman -Syy
fi
elif [ -f /usr/bin/apt-get ]; then
if [[ $UID -eq 0 ]]; then
apt-get update
else
sudo apt-get update
fi
fi
}
# function that upgrades the system
upg () {
if [ -f /usr/bin/pacman ]; then
if [[ $UID -eq 0 ]]; then
pacman -Syu
else
sudo pacman -Syu
fi
elif [ -f /usr/bin/apt-get ]; then
if [[ $UID -eq 0 ]]; then
apt-get upgrade
else
sudo apt-get upgrade
fi
fi
}
# review and delete pacnew files
pacnew () {
for n in /etc/**/*.pacnew; do
if [[ -r ${n%.*} ]]; then
sudo vimdiff $n ${n%.*} &&
echo -n "delete pacnew file? ";
read -q && sudo rm $n
fi
done
}
# }}}
# {{{ Prompts
# Right prompt with clock
#RPS1=" %{$fg_bold[black]%}%D{%d/%m/%y %H:%M:%S}%{${reset_color}%}"
# Others prompts
PS2="%{$fg_no_bold[yellow]%}%_>%{${reset_color}%} "
PS3="%{$fg_no_bold[yellow]%}?#%{${reset_color}%} "
# }}}
# {{{ title()
# Display the title, and append the command if given in $1
function title {
t="%n@%m %~"
case $TERM in
screen)
print -nP "\ek$t\e\\"
print -nP "\e]0;$t\a"
;;
xterm*|rxvt*|(E|e)term)
print -nP "\e]0;$t\a"
;;
esac
}
# }}}
# {{{ precmd()
function precmd {
title
vcs_info
local deco="%{${fg_no_bold[white]}%}"
if [[ -O "$PWD" ]]; then
local path_color="${fg_no_bold[blue]}"
elif [[ -w "$PWD" ]]; then
local path_color="${fg_bold[green]}"
else
local path_color="${fg_bold[red]}"
fi
case ${HOST%%.*} in
thor) local host_color="${fg_bold[yellow]}" ;;
odin) local host_color="${fg_bold[cyan]}" ;;
vidar) local host_color="${fg_bold[green]}" ;;
bor) local host_color="${fg_bold[blue]}" ;;
eywa) local host_color="${fg_bold[green]}" ;;
apophis) local host_color="${fg_bold[magenta]}" ;;
*) local host_color="${fg_bold[default]}" ;;
esac
if [[ $UID -eq 0 ]]; then
local user_color="${fg_bold[red]}"
else
local user_color="${fg_bold[default]}"
fi
local return_code="%(?..${deco}!%{${fg_bold[red]}%}%?${deco}! )"
local user_at_host="%{${user_color}%}%n${deco}@%{${host_color}%}%m"
local cwd="%{${path_color}%}%32<...<%~"
local sign="%(!.%{${fg_bold[red]}%}.${deco})%#"
PS1="${return_code}${deco}[${user_at_host} ${cwd}${deco}] ${sign}%{${reset_color}%} "
# Prompt on the right, displayed when in a VCS repository
RPS1="${vcs_info_msg_0_}%{${reset_color}%}"
}
# }}}
# vim:filetype=zsh:tabstop=8:shiftwidth=2:fdm=marker:
Un peu hors sujet mais c'est un fichier de configuration de quoi ?
Less is more
La perfection n'est pas atteinte quand il n'y a plus rien à ajouter, mais quand il n'y a plus rien à retrancher
"On fait des boulots qu'on déteste pour se payer des merdes qui nous servent à rien"
### History
setopt HIST_IGNORE_DUPS # ignore same commands run twice+
setopt APPEND_HISTORY # don't overwrite history
setopt SHARE_HISTORY # _all_ zsh sessions share the same history files
setopt INC_APPEND_HISTORY # write after each command
### Dircolors
LS_COLORS='rs=0:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:tw=30;42:ow=34;42:st=37;44:ex=01;32:';
export LS_COLORS
### Keybindings
#bindkey -v
typeset -g -A key
#bindkey '\e[3~' delete-char
bindkey '\e[1~' beginning-of-line
bindkey '\e[4~' end-of-line
#bindkey '\e[2~' overwrite-mode
bindkey '^?' backward-delete-char
bindkey '^[[1~' beginning-of-line
bindkey '^[[5~' up-line-or-history
bindkey '^[[3~' delete-char
bindkey '^[[4~' end-of-line
bindkey '^[[6~' down-line-or-history
bindkey '^[[A' up-line-or-search
bindkey '^[[D' backward-char
bindkey '^[[B' down-line-or-search
bindkey '^[[C' forward-char
# for rxvt
bindkey "\e[8~" end-of-line
bindkey "\e[7~" beginning-of-line
# for gnome-terminal
bindkey "\eOH" beginning-of-line
bindkey "\eOF" end-of-line
### Alias
alias ls='ls --color=auto'
alias grep='grep --color=auto'
### Comp stuff
zmodload zsh/complist
autoload -Uz compinit
compinit
zstyle :compinstall filename '${HOME}/.zshrc'
#zstyle ':completion:*:pacman:*' force-list always
#zstyle ':completion:*:*:pacman:*' menu yes select
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*:*:kill:*' menu yes select
zstyle ':completion:*:kill:*' force-list always
zstyle ':completion:*:*:killall:*' menu yes select
zstyle ':completion:*:killall:*' force-list always
### Other
unsetopt beep
### Prompt
setprompt () {
# load some modules
autoload -U colors zsh/terminfo # Used in the colour alias below
colors
setopt prompt_subst
# make some aliases for the colours: (coud use normal escap.seq's too)
for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
eval PR_$color='%{$fg_bold[${(L)color}]%}'
done
PR_NO_COLOR="%{$terminfo[sgr0]%}"
# Check the UID
if [[ $UID -ge 1000 ]]; then # normal user
eval COLOR_1='${PR_RED}'
eval COLOR_2='${PR_BLUE}'
elif [[ $UID -eq 0 ]]; then # root
eval COLOR_1='${PR_RED}'
eval COLOR_2='${PR_YELLOW}'
fi
# Check if we are on SSH or not
if [[ -n "$SSH_CLIENT" || -n "$SSH2_CLIENT" ]]; then
eval PR_HOST='${PR_NO_COLOR}@${PR_YELLOW}%M${PR_NO_COLOR}' # SSH
else
eval PR_HOST='${PR_NO_COLOR}@${PR_YELLOW}_${PR_NO_COLOR}' # no SSH
fi
# set the prompt
PS1=$'${COLOR_1}> ${PR_NO_COLOR}%T ${COLOR_2}%n${PR_HOST} ${PR_NO_COLOR}{ ${COLOR_1}%~ ${PR_NO_COLOR}} ${COLOR_2}%# ${PR_NO_COLOR}'
}
setprompt
Pour le prompt ça donne ça :
J'ai aussi installé zsh-lovers, pour l'auto-completion c'est vraiment le top. Faudra que je prenne le temps de jeter un coup d'oeil un peu plus approfondie sur oh-my-zsh.