From 5e2f5aa6424cc20673f62cb6b7793ad6a75a4e72 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Fri, 23 Jan 2009 14:29:20 +0100 Subject: reordered soem stuff and added many comments --- .zshrc | 249 +++++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 142 insertions(+), 107 deletions(-) (limited to '.zshrc') diff --git a/.zshrc b/.zshrc index 16add68..571ad4e 100644 --- a/.zshrc +++ b/.zshrc @@ -1,13 +1,15 @@ #---------------------------------------------------- -# File: ~/.zshrc -# Version: 0.3.8 -# Author: Florian "Bluewind" Pritz +# File: ~/.zshrc +# Version: 0.3.9 +# Date: 2009-01-23 +# Author: Florian "Bluewind" Pritz #---------------------------------------------------- #-------------------- # History #-------------------- export HISTFILE=~/.zsh/histfile +# for some odd reason allocating RAM to save the histfile takes ages.. export HISTSIZE=4000 export SAVEHIST=4000 @@ -21,8 +23,9 @@ bindkey '\e[3~' delete-char bindkey '\e[2~' overwrite-mode bindkey "^[[7~" beginning-of-line # Pos1 bindkey "^[[8~" end-of-line # End - -eval "`dircolors -b`" +# HOWTO make your own: +# bindkey '' (do this in a shell) +# for some actions run `bindkey` #-------------------- # Completion stuff @@ -30,7 +33,8 @@ eval "`dircolors -b`" autoload -Uz compinit compinit -# Functions for completition +# correct 7etc/foo to /etc/foo +# if anyone has a working solution for /etc7foo please contact me function _7slash { if [[ $words[CURRENT] = 7(#b)(*)(#e) ]] then @@ -38,6 +42,7 @@ function _7slash { fi } +# complete my little rc function (archlinux startscripts) function _rc () { case $CURRENT in 2) compadd $(find /etc/rc.d/ -type f -executable -printf '%f ');; @@ -45,6 +50,7 @@ function _rc () { esac } +# easier way to use sshfs ;) function _ssh-mount () { compadd $(cat ${HOME}/bin/ssh-mount.sh | egrep "Servers:.*" | sed "s#echo \-e \"\${green}Servers\:\$NC##g; s#\"\;##g; s#,##g") } zstyle :compinstall filename '$HOME/.zshrc' @@ -71,14 +77,17 @@ zstyle ':completion:*:functions' ignored-patterns '_*' zstyle ':completion:*' menu yes select zstyle ':completion:*' file-sort time +# remove / after dirnames +# e.g. ls foo/ -> ls foo zstyle ':completion:*' squeeze-slashes true -#if in foo/bar don't show bar when cd ../ +# if in foo/bar don't show bar when cd ../ zstyle ':completion:*:cd:*' ignore-parents parent pwd -# ignore case +# ignore case when completing zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*' +# make some stuff look better zstyle ':completion:*:descriptions' format $'%{\e[0;31m%}completing %B%d%b%{\e[0m%}' zstyle ':completion:*:warnings' format $'%{\e[0;31m%}No matches for:%{\e[0m%} %d' @@ -87,19 +96,38 @@ zstyle ':completion:*:warnings' format $'%{\e[0;31m%}No matches for:%{\e[ #-------------------- autoload colors colors +# .. -> cd ../ setopt autocd + setopt correct_all + +# cd /etc/**/foo/blub searches ;) setopt extendedglob + +# push cds to directory stack setopt auto_pushd + +# don't push something twice setopt pushd_ignore_dups + +# don't kill jobs when exiting shell setopt no_hup + +# show us when some command didn't exit with 0 setopt print_exit_value -setopt SHARE_HISTORY -setopt NO_clobber + +# makepkg -g > PKGBUILD +# zsh: file exists: PKGBUILD +# +# work saved ;) +setopt no_clobber + setopt APPEND_HISTORY +setopt SHARE_HISTORY setopt EXTENDED_HISTORY setopt HIST_REDUCE_BLANKS setopt HIST_IGNORE_SPACE +setopt nohistverify #----------------------- # Variables @@ -108,7 +136,6 @@ setopt HIST_IGNORE_SPACE export OOO_FORCE_DESKTOP=gnome export PATH=${PATH}:${HOME}/misc/scripts:${HOME}/bin export EDITOR=vim -#export PAGER="/usr/share/vim/macros/less.sh" export PAGER=vimpager #export LESSCHARSET="UTF-8" #export LESSOPEN='|/usr/bin/lesspipe.sh %s 2>&-' @@ -118,6 +145,7 @@ export PAGER=vimpager #-------------------- # Colors #-------------------- +#use these in functions/shell scripts export red='\e[0;31m' export RED='\e[1;31m' export green='\e[0;32m' @@ -129,6 +157,8 @@ export PURPLE='\e[1;35m' export cyan='\e[0;36m' export CYAN='\e[1;36m' export NC='\e[0m' + +# these are for use in PROMPT fg_green=$'%{\e[0;32m%}' fg_blue=$'%{\e[0;34m%}' fg_cyan=$'%{\e[0;36m%}' @@ -146,28 +176,32 @@ fg_no_colour=$'%{\e[0m%}' fg_white=$'%{\e[1;37m%}' fg_black=$'%{\e[0;30m%}' +# colors in framebuffer! if [ "$TERM" = "linux" ]; then ${HOME}/bin/parse_xdefaults.sh clear #for background artifacting fi +# some better colors for ls +eval "`dircolors -b`" #-------------------- # Terminal title #-------------------- +# also found somewhere prompt_eof_setup() { - # preexec() is run after you press enter on your command but before the command is run. - preexec() { - # define screen/terminal title with the current command (http://aperiodic.net/phil/prompt/) - case $TERM in - rxvt-unicode*) - printf '\33]2;%s\007' $1 - ;; - screen*) - local CMD=${1[(wr)^(*=*|sudo|ssh|exec|-*)]} - printf '\ek%s\e\\' $CMD;; - esac - } + # preexec() is run after you press enter on your command but before the command is run. + preexec() { + # define screen/terminal title with the current command (http://aperiodic.net/phil/prompt/) + case $TERM in + rxvt-unicode*) + printf '\33]2;%s\007' $1 + ;; + screen*) + local CMD=${1[(wr)^(*=*|sudo|ssh|exec|-*)]} + printf '\ek%s\e\\' $CMD;; + esac + } } prompt_eof_setup "$@" @@ -185,67 +219,82 @@ SPROMPT='zsh: correct '%R' to '%r' ? ([Y]es/[N]o/[E]dit/[A]bort) ' #-------------------- # Aliases #-------------------- +# better ask before we loose data alias rm='rm -Iv' alias cp='cp -iv' alias mv='mv -iv' +# I don't like bytes alias dum='du -kh --max-depth=2' alias du='du -kh' alias dus='du -skh' alias df='df -kTh' -alias ls='ls -lhbtF --color=auto' -alias ll='ls -lhbtF --color=auto' -alias la='ls -lahbtF --color=auto' +# function to make ls look nice is below +alias ll='ls' +alias la='ls -a' alias newpkgb=' cp $HOME/misc/aur/PKGBUILD.proto PKGBUILD' + +# well I got used to that name ;) alias aurball='makepkg --source -f' +alias s='sudo' +alias x='x -v' alias u='upload.sh' alias mtr='mtr -t' alias wcl='wc -l' alias mdstat='cat /proc/mdstat' alias pager='${PAGER}' +alias more='${PAGER}' +alias less='${PAGER}' alias c='${PAGER}' -alias sc='sudo ${PAGER}' alias v='vim' +# sudo needs support for aliases! +alias sc='sudo ${PAGER}' alias sv='sudo vim' -alias s='sudo' -alias pacman='pacman-color' alias ncmpc='ncmpc -c' +alias youtube='youtube-dl -b ' + +# updating commands can be long... alias yup='yaourt -Syu --aur' alias yu='yaourt -Syu' -alias x='extract' -alias more='less' -alias youtube='youtube-dl -b ' +# can't they make it use sudo on it's own like yaourt? alias p='sudo powerpill' alias pa='sudo powerpill -Syu' alias py='sudo powerpill -S' +alias pacman='sudo pacman-color' alias su='su -' -alias ysi='yaourt -Si' -alias yqo='yaourt -Qo' alias y='yaourt' alias ys='yaourt -S' -alias ad='arson -D' +alias ysi='yaourt -Si' alias yr='yaourt -Rs' alias yrn='yaourt -Rns' +alias yqo='yaourt -Qo' +# too long to remember alias asciidoc_full='asciidoc -a icons -a toc' +# global aliases work EVERYWHERE +# e.g. dmesg tt +# show last 20 lines of dmesg alias -g gg='| grep --color' alias -g eg='| egrep --color' alias -g tt='| tail -n 20' +# I always hit y instead of | ... alias -g vv='|' -#alias -g pp="2>&1 | curl -F 'sprunge=<-' http://sprunge.us" +# who doesn't need pastebins? +alias -g sp="2>&1 | curl -F 'sprunge=<-' http://sprunge.us" alias -g pp="2>&1 | wgetpaste -X " -alias -s txt=leafpad +# e.g. "blub.txt" opens the file instead of showing command not found +alias -s txt=mousepad alias -s jpg=gpicview alias -s png=gpicview @@ -255,16 +304,24 @@ source ~/.private_stuff.zsh #-------------------- # Functions #-------------------- + +# always /etc/rc.d/blub is a bit too much work ;) rc () { sudo /etc/rc.d/$1 $2 } +# usefull if you have more machines and want to easily update that config here update_zshrc () { wget http://flo.server-speed.net/stuff/dotfiles/zshrc -O ${HOME}/.zshrc } -bk() { cp -b ${1} ${1}_`date +%Y-%m-%d_%T` } +# easily make backups +bk() { + cp -b ${1} ${1}_`date +%Y-%m-%d_%T` +} +# some colors! +# idea see below cd() { builtin cd $@ && ls @@ -279,26 +336,27 @@ ls () { # jump between directories # Copyright 2005 Nikolai Weibull # notice: option AUTO_PUSHD has to be set - d(){ - emulate -L zsh - autoload -U colors - local color=$fg_bold[blue] - integer i=0 - dirs -p | while read dir; do - local num="${$(printf "%-4d " $i)/ /.}" - printf " %s $color%s$reset_color\n" $num $dir - (( i++ )) - done - integer dir=-1 - read -r 'dir?Jump to directory: ' || return - (( dir == -1 )) && return - if (( dir < 0 || dir >= i )); then - echo d: no such directory stack entry: $dir - return 1 - fi - cd ~$dir - } +d(){ + emulate -L zsh + autoload -U colors + local color=$fg_bold[blue] + integer i=0 + dirs -p | while read dir; do + local num="${$(printf "%-4d " $i)/ /.}" + printf " %s $color%s$reset_color\n" $num $dir + (( i++ )) + done + integer dir=-1 + read -r 'dir?Jump to directory: ' || return + (( dir == -1 )) && return + if (( dir < 0 || dir >= i )); then + echo d: no such directory stack entry: $dir + return 1 + fi + cd ~$dir +} +# from the grml zshrc iirc hglob() { echo -e " / directories @@ -335,28 +393,34 @@ hglob() { print -l *(.c|.h) # Nur Dateien mit dem Suffix '.c' und / oder '.h' print **/*(g:users:) # Alle Dateien/Verzeichnisse der Gruppe >users< echo /proc/*/cwd(:h:t:s/self//) # Analog zu >ps ax | awk '{print $1}'<" - } +} -2html() { vim -n -c ':syntax on' -c ':so $VIMRUNTIME/syntax/2html.vim' -c ':wqa' $1 > /dev/null 2> /dev/null } +# let vim highlight any file for us and save it as html +2html() { + vim -n -c ':syntax on' -c ':so $VIMRUNTIME/syntax/2html.vim' -c ':wqa' $1 > /dev/null 2> /dev/null +} +# download any package's PKGBUILD and go into that dir yd (){ - mkdir $1 - builtin cd $1 - yaourt -G $1 + if [ "$1" -ne "" ]; then + mkdir -p $1 + builtin cd $1 + yaourt -G $1 + else + echo "Sorry, I need at least a name..." + fi } +# some script to make this damn agent work easier source ${HOME}/bin/gpg-agent.sh +# yeah I know you shouldn't use it... google(){ firefox "http://www.google.com/search?&num=100&q=$*" & disown firefox } -leaf(){ - leafpad $* & - disown leaf -} - +# swaps 2 files function swap() { if [ "$1" = "" ] || [ "$2" = "" ] || [ "$1" = "-h" ]; then @@ -375,10 +439,12 @@ function swap() fi } +# get your internal and external IPs +# also found somewhere on the net function my_ip() { MY_IP=$(/sbin/ifconfig eth0 | awk '/inet/ { print $2 } ' | \ -sed -e s/addr://) + sed -e s/addr://) MY_ISP=$(curl www.wieistmeineip.de | awk '(/[0-9]?[0-9]?[0-9]\.[0-9]?[0-9]?[0-9]\.[0-9]?[0-9]?[0-9]\.[0-9]?[0-9]?[0-9]/) {print}' | awk 'gsub(/[>||<]/," ")' | awk '{print $3}') } @@ -396,6 +462,7 @@ function ii() echo } +# short info to display when opening a new shell function short_ii() { echo -e "\nUser ${RED}"${USER:-"N/A"}"$NC on "${RED}${HOST:-"N/A"}"$NC" @@ -417,46 +484,13 @@ function repeat() done } -# in the aur as extract -#extract () { -# if [ "$1" = "" ] || [ "$1" = "-h" ]; then -# echo -e "${blue}Usage:$NC x "; -# echo -e "Extracts "; -# return 1 -# fi -# for file in "$@" -# do -# if [ -f ${file} ] ; then -# case ${file} in -# *.tar.bz2) tar xjf ${file} ;; -# *.tar.gz) tar xzf ${file} ;; -# *.tbz2) tar xjf ${file} ;; -# *.tgz) tar xzf ${file} ;; -# *) -# case $(file -bi ${file}) in -# application/x-bzip2) bunzip2 ${file} ;; -# application/rar) unrar x ${file} ;; -# application/x-gzip) gunzip ${file} ;; -# application/x-tar) tar xf ${file} ;; -# application/zip) unzip ${file} ;; -# application/x-compressed) uncompress ${file} ;; -# application/x-7z-compressed) 7z x ${file} ;; -# *) echo -e "${RED}Error:$NC No rule how to extract \"${file}\" ($(file -bi ${file}))" ;; -# esac -# ;; -# esac -# else -# echo -e "${RED}Error:$NC \"${file}\" doesn't exist" -# fi -# done -#} - +# actually it converts any mp4 or flv to mp3... youtube2mp3 () { for file in "$@" do - if [ -f ${file} ] ; then + if [ -f ${file} ] ; then title=$(echo ${file} | sed 's/\(.*\)\..*/\1/') - case $(file -bi ${file}) in + case $(file -bi ${file}) in video/mp4) faad "${file}" && lame "${title}.wav" "${title}.mp3" && @@ -470,8 +504,8 @@ youtube2mp3 () { ;; esac else - echo -e "${RED}Error:$NC \"${file}\" doesn't exist" - fi + echo -e "${RED}Error:$NC \"${file}\" doesn't exist" + fi done } @@ -481,7 +515,8 @@ youtube2mp3 () { cat /etc/motd echo -e "${CYAN}Welcome to ZSH ${RED}${ZSH_VERSION}$NC" short_ii +# don't want to read nearly the same every time I open a new shell if [ -x /usr/bin/fortune ]; then /usr/bin/fortune -s fi -echo "" +echo -- cgit v1.2.3-24-g4f1b