diff --git a/README.md b/README.md index abb603b..8ef7659 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,13 @@ zsh === Zsh configuration + +Install +------- + +* clone oh-my-zsh + git clone https://github.com/robbyrussell/oh-my-zsh.git ~/.oh-myzsh + +* Link configuration + ln -s zshrc ~/.zshrc + for i in `ls custom`; do ln -s custom/$i ~/.oh-my-zsh/custom/$i diff --git a/custom/hybris-alias.zsh b/custom/hybris-alias.zsh new file mode 100644 index 0000000..fa4d714 --- /dev/null +++ b/custom/hybris-alias.zsh @@ -0,0 +1,46 @@ +# Scripts files +if [ -d $HOME/scripts ] +then + files=`ls $HOME/scripts` + if [ "x$files" != "x" ] + then + for i in `ls --file-type $HOME/scripts` + do + ALIAS=`echo $i | cut -d. -f1` + alias $ALIAS=$HOME/scripts/$i + done + fi +fi + +# Everyday aliases +alias cp='nocorrect cp' # no spelling correction on cp +alias cvlc-add='cvlc --playlist-enqueue' +alias grep='grep --color=auto' +alias h=history +alias j=jobs +alias l='ls -l' +alias la='ls -la' +alias ll='ls -l' +alias ls='ls --color=auto -F' +alias mkdir='nocorrect mkdir' # no spelling correction on mkdir +alias mv='nocorrect mv' # no spelling correction on mv +alias wi='wicd-curses' + +alias -g M='|more' +alias -g H='|head' +alias -g T='|tail' + +configupdate() {cd ~/; git add config; git commit -m "config update"; git push; cd -} +e() {emacsclient -n $@ > /dev/null 2>&1} +git-send-email() {git send-email --smtp-server /usr/bin/msmtp $@} +history() {perl -lne 'm#: (\d+):\d+;(.+)# && printf "\033[94m%s\033[0m %s\n",scalar localtime $1,$2' ~/.zhist} +logtail() {tail -f $1 | ccze -A} +mutt() {echo -ne "\033]0;screen mutt\007" ; /usr/bin/screen -O -S mutt -c ~/.screenrc_mutt} +quicksave() {cp --backup=numbered "$@" /tmp/} +wallpaper() {rm -f /home/hybris/Pictures/wallpaper; ln -s `pwd`/$1 /home/hybris/Pictures/wallpaper} +whiteboard() {convert "$1" -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 "$2"} + +# System +mouseon() {xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Device Enabled" 8 1} +mouseoff() {xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Device Enabled" 8 0} +pulse-restart() {killall pulseaudio && /usr/bin/pulseaudio --start --log-target=syslog} diff --git a/custom/hybris-dir-colors b/custom/hybris-dir-colors new file mode 100644 index 0000000..39a08c2 --- /dev/null +++ b/custom/hybris-dir-colors @@ -0,0 +1,108 @@ +# Configuration file for dircolors, a utility to help you set the +# LS_COLORS environment variable used by GNU ls with the --color option. +# The keywords COLOR, OPTIONS, and EIGHTBIT (honored by the +# slackware version of dircolors) are recognized but ignored. +# Below, there should be one TERM entry for each termtype that is colorizable +TERM linux +TERM linux-c +TERM mach-color +TERM console +TERM con132x25 +TERM con132x30 +TERM con132x43 +TERM con132x60 +TERM con80x25 +TERM con80x28 +TERM con80x30 +TERM con80x43 +TERM con80x50 +TERM con80x60 +TERM cygwin +TERM dtterm +TERM putty +TERM xterm +TERM xterm-color +TERM xterm-debian +TERM rxvt +TERM screen +TERM screen-bce +TERM screen-w +TERM vt100 +TERM Eterm +# Below are the color init strings for the basic file types. A color init +# string consists of one or more of the following numeric codes: +# Attribute codes: +# 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed +# Text color codes: +# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white +# Background color codes: +# 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white +NORMAL 00 # global default, although everything should be something. +FILE 00 # normal file +DIR 01;33 # directory +LINK 01;36 # symbolic link. (If you set this to 'target' instead of a + # numerical value, the color is as for the file pointed to.) +FIFO 40;33 # pipe +SOCK 01;35 # socket +DOOR 01;35 # door +BLK 40;33;01 # block device driver +CHR 40;33;01 # character device driver +ORPHAN 40;31;01 # symlink to nonexistent file +SETUID 37;41 # file that is setuid (u+s) +SETGID 30;43 # file that is setgid (g+s) +STICKY_OTHER_WRITABLE 30;42 # dir that is sticky and other-writable (+t,o+w) +OTHER_WRITABLE 34;42 # dir that is other-writable (o+w) and not sticky +STICKY 37;44 # dir with the sticky bit set (+t) and not other-writable +# This is for files with execute permission: +EXEC 01;32 +# List any file extensions like '.gz' or '.tar' that you would like ls +# to colorize below. Put the extension, a space, and the color init string. +# (and any comments you want to add after a '#') +# If you use DOS-style suffixes, you may want to uncomment the following: +#.cmd 01;32 # executables (bright green) +#.exe 01;32 +#.com 01;32 +#.btm 01;32 +#.bat 01;32 +.tar 01;31 # archives or compressed (bright red) +.tgz 01;31 +.arj 01;31 +.taz 01;31 +.lzh 01;31 +.zip 01;31 +.z 01;31 +.Z 01;31 +.gz 01;31 +.bz2 01;31 +.deb 01;31 +.rpm 01;31 +.jar 01;31 +# image formats +.jpg 01;35 +.jpeg 01;35 +.gif 01;35 +.bmp 01;35 +.pbm 01;35 +.pgm 01;35 +.ppm 01;35 +.tga 01;35 +.xbm 01;35 +.xpm 01;35 +.tif 01;35 +.tiff 01;35 +.png 01;35 +.mov 01;35 +.mpg 01;35 +.mpeg 01;35 +.avi 01;35 +.fli 01;35 +.gl 01;35 +.dl 01;35 +.xcf 01;35 +.xwd 01;35 +# audio formats +.flac 01;35 +.mp3 01;35 +.mpc 01;35 +.ogg 01;35 +.wav 01;35 diff --git a/custom/hybris-display.zsh b/custom/hybris-display.zsh new file mode 100644 index 0000000..d8fb54d --- /dev/null +++ b/custom/hybris-display.zsh @@ -0,0 +1,19 @@ +# Shut the f*ck up. +xset b off + +# bip at command end +function precmd() { + echo -n -e "\a" + if [ "$TERM" != dumb ]; then echo -en "\033]0;${USER}@$(hostname)\007"; fi +} + +# do not share history between terms... +unsetopt share_history + +# "ctrl-x e" to edit command +autoload edit-command-line +zle -N edit-command-line +bindkey '^Xe' edit-command-line + +# dir colors +eval `dircolors $HOME/.oh-my-zsh/custom/hybris-dir-colors` diff --git a/custom/hybris-export.zsh b/custom/hybris-export.zsh new file mode 100644 index 0000000..aa67e1a --- /dev/null +++ b/custom/hybris-export.zsh @@ -0,0 +1,11 @@ +# Personnal +export EDITOR=emacsclient +export HISTFILE=~/.zhist +export HISTSIZE=5000 +export LESS=-cex3MRX +export LESSOPEN='|~/.lessfilter %s' +export LOGCHECK=60 +export READNULLCMD=${PAGER:-/usr/bin/pager} +export SAVEHIST=5000 +export WATCH=all +export WATCHFMT="%n has %a %l from %M" diff --git a/custom/hybris-zsh.zsh b/custom/hybris-zsh.zsh new file mode 100644 index 0000000..cad18c3 --- /dev/null +++ b/custom/hybris-zsh.zsh @@ -0,0 +1,72 @@ +if [ $UID -eq 0 ]; then + umask 077; +else + umask 022; +fi + +autoload incremental-complete-word +autoload insert-files +autoload mere zed zfinit +autoload run-help +autoload -U compinit +autoload -U promptinit +autoload -U zen +compinit +promptinit +zle -N incremental-complete-word +zle -N insert-files +zmodload zsh/complist + +bindkey m menu-select +bindkey i incremental-complete-word +bindkey j insert-files + +fignore=(.o .c~ .pro) +fpath=( + $fpath + /root/.zen/zsh/scripts + /root/.zen/zsh/zle ) + +limit core 0 + +setopt correct +setopt auto_cd +setopt hist_ignore_dups +setopt auto_list +setopt append_history +setopt auto_param_keys +setopt auto_param_slash +setopt no_bg_nice +setopt complete_aliases +setopt equals +setopt extended_glob +setopt extendedhistory +setopt hash_cmds +setopt hash_dirs +setopt mail_warning +setopt magic_equal_subst +setopt numericglobsort +setopt interactivecomments +setopt printeightbit + +zstyle ':completion:*:sudo:*' command-path /usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin /usr/X11R6/bin +zstyle ':completion:*' format '-=> %d' +zstyle ':completion:*' auto-description 'specify: %d' +zstyle ':completion:*' completer _complete _correct _approximate +zstyle ':completion:*' group-name '' +zstyle ':completion:*' insert-unambiguous true +zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} +zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}' 'l:|=* r:|=*' 'r:|[ +._-]=* r:|=*' +zstyle ':completion:*' max-errors 2 +zstyle ':completion:*' menu select=5 +zstyle ':completion:*' original true +zstyle ':completion:*' squeeze-slashes true +zstyle ':completion:*' verbose true +zstyle ':completion:*:rm:*' ignore-line yes +zstyle ':completion:*:mv:*' ignore-line yes +zstyle ':completion:*:cp:*' ignore-line yes + +unsetopt inc_append_history + +if [ "$TERM" != dumb ]; then echo -en "\033]0;${USER}@$(hostname)\007"; fi diff --git a/custom/hybris.zsh-theme b/custom/hybris.zsh-theme new file mode 100644 index 0000000..0a91384 --- /dev/null +++ b/custom/hybris.zsh-theme @@ -0,0 +1,7 @@ +PROMPT='%{${fg_bold[white]}%}%n%{$reset_color%}%{${fg[white]}%}@%m%{$reset_color%} %{$fg[white]%}$%{$reset_color%} ' +RPROMPT='%(?,,%{${fg_bold[red]}%}[%?] %{$reset_color%})$(git_prompt_info)%{$fg[green]%}%~%{$reset_color%}' + +ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[blue]%}(" +ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} " +ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%})%{$fg[red]%}!%{$reset_color%}" +ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})" diff --git a/custom/z.zsh b/custom/z.zsh new file mode 100644 index 0000000..ec9736a --- /dev/null +++ b/custom/z.zsh @@ -0,0 +1,245 @@ +# Copyright (c) 2009 rupa deadwyler under the WTFPL license + +# maintains a jump-list of the directories you actually use +# +# INSTALL: +# * put something like this in your .bashrc/.zshrc: +# . /path/to/z.sh +# * cd around for a while to build up the db +# * PROFIT!! +# * optionally: +# set $_Z_CMD in .bashrc/.zshrc to change the command (default z). +# set $_Z_DATA in .bashrc/.zshrc to change the datafile (default ~/.z). +# set $_Z_NO_RESOLVE_SYMLINKS to prevent symlink resolution. +# set $_Z_NO_PROMPT_COMMAND if you're handling PROMPT_COMMAND yourself. +# set $_Z_EXCLUDE_DIRS to an array of directories to exclude. +# +# USE: +# * z foo # cd to most frecent dir matching foo +# * z foo bar # cd to most frecent dir matching foo and bar +# * z -r foo # cd to highest ranked dir matching foo +# * z -t foo # cd to most recently accessed dir matching foo +# * z -l foo # list matches instead of cd +# * z -c foo # restrict matches to subdirs of $PWD + +export _Z_EXCLUDE_DIRS="/tmp /lost+found" + +[ -d "${_Z_DATA:-$HOME/.z}" ] && { + echo "ERROR: z.sh's datafile (${_Z_DATA:-$HOME/.z}) is a directory." +} + +_z() { + + local datafile="${_Z_DATA:-$HOME/.z}" + + # bail if we don't own ~/.z (we're another user but our ENV is still set) + [ -f "$datafile" -a ! -O "$datafile" ] && return + + # add entries + if [ "$1" = "--add" ]; then + shift + + # $HOME isn't worth matching + [ "$*" = "$HOME" ] && return + + # don't track excluded dirs + local exclude + for exclude in "${_Z_EXCLUDE_DIRS[@]}"; do + [ "$*" = "$exclude" ] && return + done + + # maintain the data file + local tempfile="$datafile.$RANDOM" + while read line; do + # only count directories + [ -d "${line%%\|*}" ] && echo $line + done < "$datafile" | awk -v path="$*" -v now="$(date +%s)" -F"|" ' + BEGIN { + rank[path] = 1 + time[path] = now + } + $2 >= 1 { + # drop ranks below 1 + if( $1 == path ) { + rank[$1] = $2 + 1 + time[$1] = now + } else { + rank[$1] = $2 + time[$1] = $3 + } + count += $2 + } + END { + if( count > 6000 ) { + # aging + for( x in rank ) print x "|" 0.99*rank[x] "|" time[x] + } else for( x in rank ) print x "|" rank[x] "|" time[x] + } + ' 2>/dev/null >| "$tempfile" + # do our best to avoid clobbering the datafile in a race condition + if [ $? -ne 0 -a -f "$datafile" ]; then + env rm -f "$tempfile" + else + env mv -f "$tempfile" "$datafile" || env rm -f "$tempfile" + fi + + # tab completion + elif [ "$1" = "--complete" ]; then + while read line; do + [ -d "${line%%\|*}" ] && echo $line + done < "$datafile" | awk -v q="$2" -F"|" ' + BEGIN { + if( q == tolower(q) ) imatch = 1 + split(substr(q, 3), fnd, " ") + } + { + if( imatch ) { + for( x in fnd ) tolower($1) !~ tolower(fnd[x]) && $1 = "" + } else { + for( x in fnd ) $1 !~ fnd[x] && $1 = "" + } + if( $1 ) print $1 + } + ' 2>/dev/null + + else + # list/go + while [ "$1" ]; do case "$1" in + --) while [ "$1" ]; do shift; local fnd="$fnd${fnd:+ }$1";done;; + -*) local opt=${1:1}; while [ "$opt" ]; do case ${opt:0:1} in + c) local fnd="^$PWD $fnd";; + h) echo "${_Z_CMD:-z} [-chlrtx] args" >&2; return;; + x) sed -i -e "\:^${PWD}|.*:d" "$datafile";; + l) local list=1;; + r) local typ="rank";; + t) local typ="recent";; + esac; opt=${opt:1}; done;; + *) local fnd="$fnd${fnd:+ }$1";; + esac; local last=$1; shift; done + [ "$fnd" -a "$fnd" != "^$PWD " ] || local list=1 + + # if we hit enter on a completion just go there + case "$last" in + # completions will always start with / + /*) [ -z "$list" -a -d "$last" ] && cd "$last" && return;; + esac + + # no file yet + [ -f "$datafile" ] || return + + local cd + cd="$(while read line; do + [ -d "${line%%\|*}" ] && echo $line + done < "$datafile" | awk -v t="$(date +%s)" -v list="$list" -v typ="$typ" -v q="$fnd" -F"|" ' + function frecent(rank, time) { + # relate frequency and time + dx = t - time + if( dx < 3600 ) return rank * 4 + if( dx < 86400 ) return rank * 2 + if( dx < 604800 ) return rank / 2 + return rank / 4 + } + function output(files, out, common) { + # list or return the desired directory + if( list ) { + cmd = "sort -n >&2" + for( x in files ) { + if( files[x] ) printf "%-10s %s\n", files[x], x | cmd + } + if( common ) { + printf "%-10s %s\n", "common:", common > "/dev/stderr" + } + } else { + if( common ) out = common + print out + } + } + function common(matches) { + # find the common root of a list of matches, if it exists + for( x in matches ) { + if( matches[x] && (!short || length(x) < length(short)) ) { + short = x + } + } + if( short == "/" ) return + # use a copy to escape special characters, as we want to return + # the original. yeah, this escaping is awful. + clean_short = short + gsub(/[\(\)\[\]\|]/, "\\\\&", clean_short) + for( x in matches ) if( matches[x] && x !~ clean_short ) return + return short + } + BEGIN { split(q, words, " "); hi_rank = ihi_rank = -9999999999 } + { + if( typ == "rank" ) { + rank = $2 + } else if( typ == "recent" ) { + rank = $3 - t + } else rank = frecent($2, $3) + matches[$1] = imatches[$1] = rank + for( x in words ) { + if( $1 !~ words[x] ) delete matches[$1] + if( tolower($1) !~ tolower(words[x]) ) delete imatches[$1] + } + if( matches[$1] && matches[$1] > hi_rank ) { + best_match = $1 + hi_rank = matches[$1] + } else if( imatches[$1] && imatches[$1] > ihi_rank ) { + ibest_match = $1 + ihi_rank = imatches[$1] + } + } + END { + # prefer case sensitive + if( best_match ) { + output(matches, best_match, common(matches)) + } else if( ibest_match ) { + output(imatches, ibest_match, common(imatches)) + } + } + ')" + [ $? -gt 0 ] && return + [ "$cd" ] && cd "$cd" + fi +} + +alias ${_Z_CMD:-z}='_z 2>&1' + +[ "$_Z_NO_RESOLVE_SYMLINKS" ] || _Z_RESOLVE_SYMLINKS="-P" + +if compctl >/dev/null 2>&1; then + # zsh + [ "$_Z_NO_PROMPT_COMMAND" ] || { + # populate directory list, avoid clobbering any other precmds. + if [ "$_Z_NO_RESOLVE_SYMLINKS" ]; then + _z_precmd() { + _z --add "${PWD:a}" + } + else + _z_precmd() { + _z --add "${PWD:A}" + } + fi + [[ -n "${precmd_functions[(r)_z_precmd]}" ]] || { + precmd_functions[$(($#precmd_functions+1))]=_z_precmd + } + } + _z_zsh_tab_completion() { + # tab completion + local compl + read -l compl + reply=(${(f)"$(_z --complete "$compl")"}) + } + compctl -U -K _z_zsh_tab_completion _z +elif complete >/dev/null 2>&1; then + # bash + # tab completion + complete -o filenames -C '_z --complete "$COMP_LINE"' ${_Z_CMD:-z} + [ "$_Z_NO_PROMPT_COMMAND" ] || { + # populate directory list. avoid clobbering other PROMPT_COMMANDs. + grep "_z --add" <<< "$PROMPT_COMMAND" >/dev/null || { + PROMPT_COMMAND="$PROMPT_COMMAND"$'\n''_z --add "$(command pwd '$_Z_RESOLVE_SYMLINKS' 2>/dev/null)" 2>/dev/null;' + } + } +fi + diff --git a/zshrc b/zshrc new file mode 100644 index 0000000..42e4101 --- /dev/null +++ b/zshrc @@ -0,0 +1,45 @@ +# Path to your oh-my-zsh configuration. +ZSH=$HOME/.oh-my-zsh + +# Set name of the theme to load. +# Look in ~/.oh-my-zsh/themes/ +# Optionally, if you set this to "random", it'll load a random theme each +# time that oh-my-zsh is loaded. +ZSH_THEME="hybris" + +# Example aliases +# alias zshconfig="mate ~/.zshrc" +# alias ohmyzsh="mate ~/.oh-my-zsh" + +# Set to this to use case-sensitive completion +# CASE_SENSITIVE="true" + +# Comment this out to disable bi-weekly auto-update checks +DISABLE_AUTO_UPDATE="true" + +# Uncomment to change how often before auto-updates occur? (in days) +# export UPDATE_ZSH_DAYS=13 + +# Uncomment following line if you want to disable colors in ls +# DISABLE_LS_COLORS="true" + +# Uncomment following line if you want to disable autosetting terminal title. +DISABLE_AUTO_TITLE="true" + +# Uncomment following line if you want to disable command autocorrection +# DISABLE_CORRECTION="true" + +# Uncomment following line if you want red dots to be displayed while waiting for completion +COMPLETION_WAITING_DOTS="true" + +# Uncomment following line if you want to disable marking untracked files under +# VCS as dirty. This makes repository status check for large repositories much, +# much faster. +# DISABLE_UNTRACKED_FILES_DIRTY="true" + +# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*) +# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/ +# Example format: plugins=(rails git textmate ruby lighthouse) +plugins=(colored-man git ssh-agent web-search) + +source $ZSH/oh-my-zsh.sh