myconfig

my config files
git clone https://a3nm.net/git/myconfig/
Log | Files | Refs | README

zshrc (5985B)


      1 . ~/.zsh/path
      2 . ~/.zsh/alias
      3 . ~/.zsh/fontsize
      4 . ~/.zsh/perso
      5 
      6 SHORTHOST=$(hostname | cut -d'.' -f1)
      7 export $SHORTHOST
      8 
      9 zstyle ':completion:*' completer _expand _complete _ignored _match _correct _approximate _prefix
     10 zstyle ':completion:*' max-errors 2
     11 zstyle :compinstall filename '/home/a3_nm/.zshrc'
     12 
     13 umask 077
     14 
     15 autoload -Uz compinit
     16 compinit
     17 
     18 RED=$'%{\e[31m%}'
     19 GREEN=$'%{\e[32m%}'
     20 YELLOW=$'%{\e[33m%}'
     21 BLUE=$'%{\e[34m%}'
     22 LIGHTBLUE=$'%{\e[94m%}'
     23 MAGENTA=$'%{\e[35m%}'
     24 CYAN=$'%{\e[36m%}'
     25 
     26 COLOR1="$GREEN"
     27 COLOR2="$RED"
     28 COLORCHAR="$RED"
     29 CHAR=">"
     30 
     31 if [ -f ~/.zsh/ps1 ]
     32 then
     33   . ~/.zsh/ps1
     34 fi
     35 
     36 resetps1() {
     37 PS1=$COLOR1$'%m%{\e[0;1m%}:'$COLOR2$'%B%~%{\e[0;1m%}'$COLORCHAR$''$CHAR$'%{\e[0;1m%}%b '
     38 }
     39 
     40 resetps1
     41 
     42 HISTSIZE=200000
     43 SAVEHIST=200000
     44 HISTFILE=~/.history
     45 
     46 setopt APPEND_HISTORY
     47 setopt INC_APPEND_HISTORY
     48 setopt SHARE_HISTORY
     49 
     50 setopt EXTENDED_HISTORY
     51 
     52 setopt HIST_IGNORE_DUPS
     53 setopt HIST_EXPIRE_DUPS_FIRST
     54 
     55 setopt CORRECT
     56 setopt DVORAK
     57 
     58 LC_ALL=en_US.utf8
     59 LANG=en_US.utf8
     60 LESSCHARSET=utf-8
     61 LC_CTYPE=en_US.utf8
     62 LC_COLLATE=en_US.utf8
     63 export LC_TIME=C
     64 LC_NUMERIC=fr_FR.utf8
     65 LC_MONETARY=fr_FR.utf8
     66 LC_MESSAGES=en_US.utf8
     67 export LC_PAPER=fr_FR.utf8
     68 LC_NAME=en_US.utf8
     69 LC_ADDRESS=fr_FR.utf8
     70 LC_TELEPHONE=fr_FR.utf8
     71 LC_MEASUREMENT=fr_FR.utf8
     72 LC_IDENTIFICATION=en_US.utf8
     73 
     74 setopt HIST_IGNORE_SPACE 
     75 
     76 zstyle ':completion:*' use-cache on
     77 zstyle ':completion:*' cache-path ~/.zsh_cache
     78 zmodload zsh/complist
     79 setopt extendedglob
     80 zstyle ':completion:*:*:kill:*:processes' list-colors "=(#b) #([0-9]#)*=36=31"
     81 
     82 export GREP_COLOR="mt=31"
     83 
     84 
     85 zstyle ':completion:*:sudo:*' command-path /usr/local/sbin /usr/local/bin \
     86                              /usr/sbin /usr/bin /sbin /bin /usr/X11R6/bin
     87 
     88 export PAGER='less'
     89 export EDITOR='vim'
     90 export BROWSER="/usr/bin/firefox"
     91 
     92 bindkey -e
     93 
     94 bindkey '^N' down-line-or-history
     95 bindkey '^P' up-line-or-history
     96 bindkey '^R' history-incremental-search-backward
     97 bindkey '^S' history-incremental-search-forward
     98 # bindkey vicmd 'k' history-incremental-search-forward
     99 bindkey 'ESC-H' run-help
    100 bindkey 'ESC-h' run-help
    101 bindkey 'ESC-?' which-command
    102 bindkey '^_' undo
    103 
    104 preexec () {
    105   local WD="$(pwd | sed "s/^\/home\/$USER/~/")"
    106   export LASTDATE="`date +%T`"
    107   if [[ "$TERM" == "rxvt-unicode" || "$TERM" == "rxvt-unicode-256color" ]]; then
    108     export COMMAND="$(echo $1 | tr -d '\n')"
    109     echo -ne "\e]0;$LOCALNAME $HOST:$WD$ $COMMAND ($LASTDATE)\a"
    110     #echo -ne "\e]0;$LOCALNAME $HOST:$WD$ TODO ($LASTDATE)\a"
    111   fi
    112   export LASTCMD="$(echo $1 | tr -d '\n')"
    113   CMD=${1%% *}
    114   case $CMD in
    115     sudo)
    116       CMD=$(echo $1 | cut -d ' ' -f 2)
    117       RSL="#$CMD"
    118       ;;
    119     ssh)
    120       HST=$(echo $1 | rev | cut -d ' ' -f 1 | rev)
    121       RSL="@$HST"
    122       ;;
    123     s)
    124       HST=$(echo $1 | rev | cut -d ' ' -f 1 | rev)
    125       RSL="@$HST"
    126       ;;
    127     *)
    128       RSL="$CMD"
    129   esac
    130   CMD=$RSL
    131   if [[ "$TERM" == "screen" ]]; then
    132     echo -ne "\ek$CMD\e\\"
    133   fi
    134 }
    135 
    136 export LOCALNAME=""
    137 function termname () { export LOCALNAME="$1|"; }
    138 
    139 autoload edit-command-line
    140 zle -N edit-command-line
    141 bindkey '^X' edit-command-line
    142 
    143 #alias busy='my_file=$(find /usr/include -type f | sort -R | head -n 1); my_len=$(wc -l $my_file | awk "{print $1}"); let "r = $RANDOM % $my_len" 2>/dev/null; vim +$r $my_file'
    144 
    145 
    146 autoload -U read-from-minibuffer
    147 function save-alias()
    148 {
    149   local REPLY
    150   read-from-minibuffer "alias as "
    151   FILE="$HOME/scripts/aliases/$REPLY" 
    152   if [ -n "$REPLY" -a ! -f $FILE ]; then
    153     echo "#!/usr/bin/zsh\n\n. ~/.zshrc\n" > $FILE
    154     echo "$BUFFER \$*" >> $FILE
    155     chmod +x $FILE
    156     BUFFER="$REPLY"
    157   fi
    158   rehash
    159 }
    160 
    161 function jump()
    162 {
    163   CD=$(find . -iname \*$1\* | head -1)
    164   if [ -n "$CD" ]
    165   then
    166     echo $CD
    167     cd "$(dirname $CD)"
    168   else
    169     echo "Not found."
    170   fi
    171 }
    172 
    173 zle -N save-alias
    174 
    175 bindkey '^G' save-alias
    176 
    177 export LASTDIR="/"
    178 
    179 # fails with spaces in some cases
    180 function precmd () {
    181   # Remember where we are:
    182   #pwd > ~/.lastdir
    183  
    184   # Record new directory on change.
    185   #newdir=`pwd`
    186   #if [ ! "$LASTDIR" = "$newdir" ]; then
    187     ## List contents:
    188     #ls -t | head -7
    189   #fi
    190  
    191   export LASTDIR=$newdir
    192 
    193   # _z --add "$(pwd -P)"
    194   if [[ "$TERM" == "screen" ]]; then
    195     echo -ne "\ek_\e\\"
    196   elif [[ "$TERM" == "rxvt-unicode" || "$TERM" == "rxvt-unicode-256color" ]]; then
    197     local WD="$(pwd | sed "s/^\/home\/$USER/~/")"
    198     if [ -n "$LASTCMD" ]
    199     then
    200       echo -ne "\e]0;$LOCALNAME $SHORTHOST:$WD$ (was $LASTCMD $LASTDATE) `date +%T`\a"
    201       #echo -ne "\e]0;$LOCALNAME $SHORTHOST:$WD$ (was TODO $LASTDATE) `date +%T`\a"
    202     else
    203       echo -ne "\e]0;urxvtc ready\a"
    204     fi
    205   fi
    206 }
    207 
    208 function zshaddhistory() {
    209   # note that this can break if PWD contains ':'
    210   echo "$TTYREC:$PWD:`date +%s`:0;${1%%$'\n'}" >> ~/logs/my_hist
    211   if [[ $1 =~ '^ ' ]] ; then
    212     return 1
    213   fi
    214   print -sr -- "${1%%$'\n'}"
    215   #fc -p
    216 }
    217 
    218 # TODO http://aperiodic.net/phil/prompt/
    219 
    220 # usage: manf command -flag (via commandlinefu)
    221 manf () { man $1 | less -p "^ +$2"; }
    222 # create a directory (with flags) and cd inside it
    223 mcd () { mkdir "$@" && cd ${@:$#} }
    224 # move a file somewhere (with flags) and link it back here
    225 mln () { mv "$@" && ln -s ${@:$#} }
    226 # move a file and own it
    227 # TODO: chown doesn't work, why?
    228 grab () { sudo mv "$1" "$2" && sudo chown a3nm:a3nm "$2" }
    229 
    230 #TODO
    231 bindkey '^Q' push-line
    232 
    233 fasd_cache="$HOME/.fasd-init-zsh"
    234 if [ "$(command -v fasd)" -nt "$fasd_cache" -o ! -s "$fasd_cache" ]; then
    235   fasd --init posix-alias zsh-hook zsh-ccomp zsh-ccomp-install >| "$fasd_cache"
    236 fi
    237 source "$fasd_cache"
    238 unset fasd_cache
    239 
    240 # http://www.solipsys.co.uk/new/BashInitialisationFiles.html?HN0811
    241 # Change to most recently used directory:
    242 # http://matt.might.net/articles/console-hacks-exploiting-frequency/
    243 # if [ -f ~/.lastdir ]; then
    244 #     cd "`cat ~/.lastdir`"
    245 # fi
    246 eval $(dircolors -p | perl -pe 's/^((CAP|S[ET]|O[TR]|M|E)\w+).*/$1 00/' | dircolors -)
    247 
    248 bindkey '^U' backward-kill-line
    249 
    250 # directories in lighter blue
    251 # cf http://askubuntu.com/questions/466198/how-do-i-change-the-color-for-directories-with-ls-in-the-console/466203#466203
    252 LS_COLORS=$LS_COLORS:'di=0;94:'
    253 export LS_COLORS
    254