Browse Source

Massive update of zsh configuration

Emmanuel Bouthenot 13 năm trước cách đây
mục cha
commit
c6c7cc006f
5 tập tin đã thay đổi với 173 bổ sung71 xóa
  1. 87 22
      .zsh.d/config.d/alias.zsh
  2. 10 35
      .zsh.d/config.d/prompt.zsh
  3. 20 0
      .zsh.d/config.d/zle.zsh
  4. 44 14
      .zsh.d/os.d/Debian.zsh
  5. 12 0
      .zsh.d/os.d/Linux.zsh

+ 87 - 22
.zsh.d/config.d/alias.zsh

@@ -21,19 +21,18 @@ if -exe vim; then
     export PAGER=~/.vim/bin/vimpager
     alias less="$PAGER"
     alias more="$PAGER"
-elif -exe most; then
-    export PAGER=most
-    alias less="$PAGER"
-    alias more="$PAGER"
 elif -exe less; then
     export PAGER=less
+    alias more="$PAGER"
 elif -exe more; then
     export PAGER=more
 fi
+export GIT_PAGER="$PAGER"
 
 #
-# Common aliases
+# Common aliases / functions
 #
+
 alias rm='rm -i'
 alias mv='mv -i'
 alias cp='cp -i'
@@ -41,14 +40,28 @@ alias cp='cp -i'
 alias vlock='clear;vlock'
 alias q='clear;exit'
 
-alias grep="grep --color=tty"
-alias mgrep="grep --color=tty -rnisH"
+export GREP_OPTIONS="--color=auto"
+alias mgrep="grep -rnisH"
 
 alias rsu="sudo -E zsh"
-alias reload="exec zsh"
+alias reloadsh="exec zsh"
 
 alias tmux="tmux -2"
 
+alias md="mkdir -p"
+mcd() { mkdir -p "$@" && cd "$@" }
+
+# show tar archive content
+ltar() { gunzip -c $1 | tar -tf - -- | $PAGER }
+# show zip archive content
+lzip() { unzip -l $1 | $PAGER }
+# show rar archive content
+lrar() { rar l $1 | $PAGER }
+
+ffi() {
+    find -iname "$@"
+}
+
 #
 # Log viewers aliases
 #
@@ -74,32 +87,71 @@ if -exe pydf; then
     alias df="pydf -h"
 fi
 
+if -exe python; then
+    alias httpserver="python -m SimpleHTTPServer"
+fi
+
+function mount() {
+    if [ $# = 0 ]; then
+        command mount -lv | column -t
+    else
+        command mount $@
+    fi
+}
+
+#
+# Sysadmin stuff
+#
+if -exe dig ; then
+    alias mx="dig +short MX"
+    alias ns="dig +short NS"
+elif -exe host ; then
+    alias mx="host -t MX"
+    alias ns="host -t NS"
+fi
+
+alias scp_nosec="scp -o 'StrictHostKeyChecking=no' -o 'UserKnownHostsFile=/dev/null'"
+alias ssh_nosec="ssh -o 'StrictHostKeyChecking=no' -o 'UserKnownHostsFile=/dev/null'"
+
+# OpenSSL
+for i in sha512 sha256 sha1 md5 ; do
+    ssl-cert-$i() {
+        openssl x509 -noout -fingerprint -$i -in $1
+    }
+done
+
+ssl-cert-fingerprints() {
+    for i in sha512 sha256 sha1 md5; do
+        ssl-cert-$i $1
+    done
+}
+
+ssl-cert-info() {
+    openssl x509 -noout -text -in $1
+    ssl-cert-fingerprints $1
+}
+
 #
 # Devel tools aliases
 #
+DIFFTOOL=
 if -exe colordiff; then
-    diff='colordiff'
+    DIFFTOOL='colordiff'
     if -exe tput; then
-        alias cdiff='colordiff -yW$(tput cols)'
+        alias DIFFTOOL='colordiff -yW$(tput cols)'
     fi
 fi
+if [ -n "$DIFFTOOL" ]; then
+    alias diff="$DIFFTOOL"
+fi
+udiff() {
+    $DIFFTOOL -Naur $*
+}
 
 if -exe colormake; then
     alias make="colormake"
 fi
 
-#
-# Git stuff
-#
-if [ -z "$GIT_PAGER" ]; then
-    for p in less more cat; do
-        if -exe "$p"; then
-            alias git="PAGER=$p git"
-            break
-        fi
-    done
-fi
-
 #
 # Mssh stuff
 #
@@ -108,3 +160,16 @@ if [ -f ~/.ssh/config ]; then
     compctl -k hosts mssh
 fi
 
+#
+# Misc stuff
+#
+# Save and restore directory, based on
+# http://chris-lamb.co.uk/2011/07/30/optimising-directory-navigation-multiple-terminals/
+rcd() {
+    cd "$(cat ~/.zsh.d/history/saved_dir)"
+}
+
+scd() {
+    echo "$(pwd)" > ~/.zsh.d/history/saved_dir
+}
+

+ 10 - 35
.zsh.d/config.d/prompt.zsh

@@ -13,44 +13,19 @@ 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}]%}'
 done
-PR_NO_COLOUR="%{$terminfo[sgr0]%}"
+PR_NO_COLOR="%{$terminfo[sgr0]%}"
 
 export PR_OS_NAME=$(uname -s)
 export PR_OS_ARCH=$(uname -m)
 
 if [ -f /etc/debian_version ]; then
-
-    # ugly way to detect Ubuntu chroots
-    LSB_NAME=$(egrep 'DISTRIB_(ID|CODENAME)' /etc/lsb-release 2>/dev/null \
-                | tr '\n' '=' | cut -d'=' -f2,4 | tr '=' ' ')
-
-    if [ "$PR_OS_NAME" = "Linux" ]; then
-        PR_OS_NAME="Debian $(</etc/debian_version)"
-    else
-        PR_OS_NAME="Debian/${PR_OS_NAME} $(</etc/debian_version)"
-    fi
+    PR_OS_NAME="$(lsb_release -is)/$(lsb_release -cs)"
     if [ -f /etc/debian_chroot ]; then
-        if [ -n "$LSB_NAME" ]; then
-            PR_OS_NAME="${PR_OS_NAME} ${PR_LIGHT_RED}chroot:${PR_WHITE}$LSB_NAME"
-        else
-            PR_OS_NAME="${PR_OS_NAME} ${PR_LIGHT_RED}chroot:${PR_WHITE}Debian $(</etc/debian_version)"
-        fi
-    else
-        if [ -n "$LSB_NAME" ]; then
-            PR_OS_NAME="$LSB_NAME"
-        fi
+        PR_OS_NAME="${PR_LIGHT_RED}chroot:${PR_WHITE}${PR_OS_NAME}"
     fi
-
-    unset LSB_NAME
 fi
 PR_OS_NAME="${PR_OS_NAME} ${PR_OS_ARCH}"
 
-if [ "$TERM" = "screen" -a -n "$WINDOW" ]; then
-    export PR_OS_PTY="scr/$WINDOW"
-else
-    export PR_OS_PTY=$(print -P %l)
-fi
-
 if [ -n "$SSH_CLIENT" ]; then
     export PR_OS_SSH="${PR_LIGHT_RED}ssh:"
 else
@@ -64,10 +39,10 @@ else
 fi
 
 function mytitle {
-    # if running screen, setting current directory name in caption/statusbar
-    [ "$TERM" = "screen" ] && echo -ne "\033k${PR_ROOT_PREFIX}${1}\033\\"
     # if running 'xterm like' terminal setting directory name in title bar
-    [ "$TERM" = "xterm" ] && echo -ne "\033]0;${PR_ROOT_PREFIX}${1}\007"
+    if [ "$TERM" = "xterm" ]; then
+        echo -ne "\033]0;${PR_ROOT_PREFIX}${1}\007"
+    fi
 }
 
 function preexec {
@@ -80,18 +55,18 @@ function precmd {
     mytitle "$(print -P %~)"
 }
 
-myprompt() {    
+myprompt() {
     if [ "$TERM" = "dumb" ]; then
-    PROMPT="-(%n@%m)-(%(!.%d.%~))->"
+        PROMPT="-(%n@%m)-(%(!.%d.%~))->"
     else
-    PROMPT='\
+        PROMPT='\
 ${PR_BLUE}\
 %1(j.-(${PR_YELLOW}jobs:${PR_WHITE}%j${PR_BLUE}).)\
 ${PR_BLUE}-(\
 %(!.${PR_RED}%n.${PR_LIGHT_GREEN}%n)\
 ${PR_WHITE}@${PR_OS_SSH}${PR_MAGENTA}%m${PR_WHITE} ${PR_OS_PTY}${PR_BLUE})-(\
 ${PR_WHITE}${PR_OS_NAME}${PR_BLUE})-(${PR_WHITE}%(!.%d.%~)${PR_BLUE})
-%0(?..${PR_RED}ret:${PR_WHITE}%?${PR_BLUE})>${PR_NO_COLOUR}'
+%0(?..${PR_RED}ret:${PR_WHITE}%?${PR_BLUE})>${PR_NO_COLOR}'
     fi
 }
 

+ 20 - 0
.zsh.d/config.d/zle.zsh

@@ -2,3 +2,23 @@
 # Zle config
 #
 
+# autoescape specials chars with urls
+autoload -U url-quote-magic
+zle -N self-insert url-quote-magic
+
+# insert sudo at beggining of current command
+insert-sudo-prefix () {
+    local prefix
+    prefix='sudo'
+    if [ "${BUFFER:0:${#prefix}}" != "$prefix" ]; then
+        BUFFER="$prefix $BUFFER"
+        CURSOR=$(($CURSOR + $#prefix + 1))
+    fi
+}
+zle -N insert-sudo-prefix
+bindkey "^b" insert-sudo-prefix
+
+# make home and end keys work with tmux
+bindkey "^[[H" beginning-of-line
+bindkey "^[[F" end-of-line
+

+ 44 - 14
.zsh.d/os.d/Debian.zsh

@@ -2,15 +2,49 @@
 # Debian stuff
 #
 
-# specific aliases
+# specific aliases / functions
 alias lintian="lintian --color=auto -IEm --pedantic"
+alias acp="apt-cache policy"
+alias acs="apt-cache search"
+alias acsh="apt-cache show"
+alias adg"sudo apt-get dist-upgrade"
+alias ag="sudo apt-get upgrade"
+alias agi="sudo apt-get install"
+alias au="sudo apt-get update"
+alias aug="sudo apt-get update && sudo apt-get upgrade"
+
+apt-rbdepends() {
+    grep-dctrl -F Build-Depends "$1" -s Package /var/lib/apt/lists/*_Sources
+}
+debdoc() {
+    cd /usr/share/doc/$1 && ls
+}
+
+dbug() {
+    if [[ $# -eq 1 ]]; then
+        case "$1" in
+            [0-9]*)
+                xdg-open "http://bugs.debian.org/$1"
+            ;;
+            *@*)
+                xdg-open "http://bugs.debian.org/cgi-bin/pkgreport.cgi?submitter=$1"
+            ;;
+            *)
+                xdg-open "http://bugs.debian.org/src:$*"
+            ;;
+        esac
+    else
+        print "$0 needs one argument"
+        return 1
+    fi
+}
 
 # specific completions
 # rdebsign is a trivial shell script wrapper around debsign
 compdef rdebsign=scp
 
 # building environements
-cow-dist () {
+cow-dist() {
     if [ $# -lt 2 ]; then
         echo "Error args."
         return
@@ -58,30 +92,26 @@ if [ -d "${PBUILDER_PATH}" ]; then
 fi
 unset PBUILDER_PATH
 
-# tools
-apt-rbdepends () {
-    grep-dctrl -F Build-Depends "$1" -s Package /var/lib/apt/lists/*_Sources
-}
 
 pdebdiff() {
     if [ ! -r debian/changelog ]; then
         echo "ERR: can't read debian/changelog"
-        exit
+        return
     fi
 
      egrep -v "^([[:space:]]+|$)" debian/changelog | \
         sed 's/[^ ]* (\([^)]*\)).*/\1/' | \
-        head -n2|tr '\n' $IFS | \
+        head -n2 | tr '\n' $IFS | \
         read v1 v2
 
    if [ -z "$v1" -o -z "$v2" ]; then
         echo "ERR: can't find version \$n and \$n-1 of the package";
-        exit
+        return
     fi
 
     if [ ! -r debian/control ]; then
         echo "ERR: can't read debian/control"
-        exit
+        return
     fi
 
     egrep '^(Package|Architecture): ' debian/control | \
@@ -96,14 +126,14 @@ pdebdiff() {
                 echo "*** DIFF ${pkg}_${v2} -> ${pkg}_${v1} ***"
                 echo
                 debdiff ../${pkg}_${v2}_${arch}.deb ../${pkg}_${v1}_${arch}.deb
-            )|$PAGER
+            ) | $PAGER
     done
 }
 
 pdeblint() {
     if [ ! -r debian/changelog ]; then
         echo "ERR: can't read debian/changelog"
-        exit
+        return
     fi
 
     v=$(egrep -v "^([[:space:]]+|$)" debian/changelog | \
@@ -112,7 +142,7 @@ pdeblint() {
 
     if [ ! -r debian/control ]; then
         echo "ERR: can't read debian/control"
-        exit
+        return
     fi
 
     pkg=$(grep '^Source: ' debian/control | sed 's/Source: //')
@@ -121,7 +151,7 @@ pdeblint() {
     changes="../${pkg}_${v}_${arch}.changes"
     if [ ! -r "$changes" ]; then
         echo "ERR: can't read changes file : ${changes}"
-        exit
+        return
     fi
 
     lintian --color=auto -IEm --pedantic $changes $@

+ 12 - 0
.zsh.d/os.d/Linux.zsh

@@ -21,6 +21,18 @@ else
     alias l='ls -lh'
 fi
 
+#
+# Alias / Functions
+#
+mdstat() {
+    if [ -f /proc/mdstat ]; then
+        cat /proc/mdstat
+    else
+        print "Linux Software RAID not available on this system."
+        return 1
+    fi
+}
+
 # Fancy cp with progressbar (using strace)
 # from http://chris-lamb.co.uk/2008/01/24/can-you-get-cp-to-give-a-progress-bar-like-wget/