From 0f0b43b67c0405c8f254f52627b7da950a6e5136 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sun, 15 Feb 2009 21:22:32 +0100 Subject: added --- .zsh/rc/10colors | 42 +++++++ .zsh/rc/10keybindings | 13 ++ .zsh/rc/10variables | 12 ++ .zsh/rc/15prompt | 30 +++++ .zsh/rc/30functions | 223 +++++++++++++++++++++++++++++++++++ .zsh/rc/50options | 45 +++++++ .zsh/rc/60aliases | 86 ++++++++++++++ .zsh/rc/70completion/10misc | 49 ++++++++ .zsh/rc/70completion/10own_functions | 14 +++ .zsh/rc/99greetings | 13 ++ 10 files changed, 527 insertions(+) create mode 100644 .zsh/rc/10colors create mode 100644 .zsh/rc/10keybindings create mode 100644 .zsh/rc/10variables create mode 100644 .zsh/rc/15prompt create mode 100644 .zsh/rc/30functions create mode 100644 .zsh/rc/50options create mode 100644 .zsh/rc/60aliases create mode 100644 .zsh/rc/70completion/10misc create mode 100644 .zsh/rc/70completion/10own_functions create mode 100644 .zsh/rc/99greetings (limited to '.zsh') diff --git a/.zsh/rc/10colors b/.zsh/rc/10colors new file mode 100644 index 0000000..b43c4f1 --- /dev/null +++ b/.zsh/rc/10colors @@ -0,0 +1,42 @@ +#-------------------- +# Colors +#-------------------- +#use these in functions/shell scripts +export red='\e[0;31m' +export RED='\e[1;31m' +export green='\e[0;32m' +export GREEN='\e[1;32m' +export blue='\e[0;34m' +export BLUE='\e[1;34m' +export purple='\e[0;35m' +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%}' +fg_red=$'%{\e[0;31m%}' +fg_brown=$'%{\e[0;33m%}' +fg_purple=$'%{\e[0;35m%}' +fg_light_gray=$'%{\e[0;37m%}' +fg_dark_gray=$'%{\e[1;30m%}' +fg_light_blue=$'%{\e[1;34m%}' +fg_light_green=$'%{\e[1;32m%}' +fg_light_cyan=$'%{\e[1;36m%}' +fg_light_red=$'%{\e[1;31m%}' +fg_light_purple=$'%{\e[1;35m%}' +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`" \ No newline at end of file diff --git a/.zsh/rc/10keybindings b/.zsh/rc/10keybindings new file mode 100644 index 0000000..5d76ab8 --- /dev/null +++ b/.zsh/rc/10keybindings @@ -0,0 +1,13 @@ +#-------------------- +# Keybindings +#-------------------- +bindkey -e +bindkey '\e[1~' beginning-of-line +bindkey '\e[4~' end-of-line +bindkey '\e[3~' delete-char +bindkey '\e[2~' overwrite-mode +bindkey "^[[7~" beginning-of-line # Pos1 +bindkey "^[[8~" end-of-line # End +# HOWTO make your own: +# bindkey '' (do this in a shell) +# for some actions run `bindkey` diff --git a/.zsh/rc/10variables b/.zsh/rc/10variables new file mode 100644 index 0000000..4796cf3 --- /dev/null +++ b/.zsh/rc/10variables @@ -0,0 +1,12 @@ +#----------------------- +# Variables +#----------------------- +#export CDPATH=.:$HOME +export OOO_FORCE_DESKTOP=gnome +export PATH=${HOME}/misc/scripts:${HOME}/bin:${PATH} +export EDITOR=vim +export PAGER=vimpager +#export LESSCHARSET="UTF-8" +#export LESSOPEN='|/usr/bin/lesspipe.sh %s 2>&-' +#export LESS='-i -c -N -w -g -M -R -P%t?f%f \ +#:stdin .?pb%pb\%:?lbLine %lb:?bbByte %bb:-...' diff --git a/.zsh/rc/15prompt b/.zsh/rc/15prompt new file mode 100644 index 0000000..ea7b58a --- /dev/null +++ b/.zsh/rc/15prompt @@ -0,0 +1,30 @@ +#-------------------- +# 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 + } +} + +prompt_eof_setup "$@" + +#-------------------- +# Prompt +#-------------------- +#PS1="[${fg_cyan}%*${fg_no_colour}] - ${fg_light_red}$USERNAME${fg_no_colour} ${fg_light_blue}%~${fg_no_colour} > " +PS1="${fg_light_red}$USERNAME${fg_no_colour}@${fg_light_green}%m${fg_no_colour} - ${fg_light_blue}%~${fg_no_colour} +[${fg_cyan}%*${fg_no_colour}] > " + +## Spelling prompt +SPROMPT='zsh: correct '%R' to '%r' ? ([Y]es/[N]o/[E]dit/[A]bort) ' diff --git a/.zsh/rc/30functions b/.zsh/rc/30functions new file mode 100644 index 0000000..24a2ddc --- /dev/null +++ b/.zsh/rc/30functions @@ -0,0 +1,223 @@ +#-------------------- +# 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 the config here +update_zshrc () { + old_pwd="$PWD" + builtin cd "$HOME/.zsh" + wget http://flo.server-speed.net/stuff/dotfiles/zshrc -O $HOME/.zshrc + wget http://flo.server-speed.net/stuff/dotfiles/zsh/filelist -O /tmp/zsh_filelist + wget -B "http://flo.server-speed.net/stuff/dotfiles/zsh/" -i /tmp/zsh_filelist -x --cut-dirs=3 -nH + rm /tmp/zsh_fileslist + rm **/index.html + builtin cd "$old_pwd" + exec zsh +} + +# easily make backups +bk() { + cp -b ${1} ${1}_`date +%Y-%m-%d_%T` +} + +# idea see below +cd() { + builtin cd $@ && + ls +} + +# idea by Gigamo http://bbs.archlinux.org/viewtopic.php?pid=478094#p478094 +ls () { + /bin/ls -rlhbtF --color=auto $@ && + echo "${PURPLE}Files: ${BLUE}$(/bin/ls -l $@ | grep -v "^[l|d|total]" | wc -l) ${GREEN}--- ${PURPLE}Directories: ${BLUE}$(/bin/ls -l $@ | grep "^d" | wc -l)${NC}" +} + +# 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 +} + +# from the grml zshrc iirc +hglob() { + echo -e " + / directories + . plain files + @ symbolic links + = sockets + p named pipes (FIFOs) + * executable plain files (0100) + % device files (character or block special) + %b block special files + %c character special files + r owner-readable files (0400) + w owner-writable files (0200) + x owner-executable files (0100) + A group-readable files (0040) + I group-writable files (0020) + E group-executable files (0010) + R world-readable files (0004) + W world-writable files (0002) + X world-executable files (0001) + s setuid files (04000) + S setgid files (02000) + t files with the sticky bit (01000) + print *(m-1) # Dateien, die vor bis zu einem Tag modifiziert wurden. + print *(a1) # Dateien, auf die vor einem Tag zugegriffen wurde. + print *(@) # Nur Links + print *(Lk+50) # Dateien die ueber 50 Kilobytes grosz sind + print *(Lk-50) # Dateien die kleiner als 50 Kilobytes sind + print **/*.c # Alle *.c - Dateien unterhalb von \$PWD + print **/*.c~file.c # Alle *.c - Dateien, aber nicht 'file.c' + print (foo|bar).* # Alle Dateien mit 'foo' und / oder 'bar' am Anfang + print *~*.* # Nur Dateien ohne '.' in Namen + chmod 644 *(.^x) # make all non-executable files publically readable + 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}'<" +} + +# 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 (){ + if [ -n "$1" ]; 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 +} + +# swaps 2 files +function swap() +{ + if [ "$1" = "" ] || [ "$2" = "" ] || [ "$1" = "-h" ]; then + echo -e "${blue}Usage:$NC swap "; + echo -e "Swaps files"; + return 1 + fi + if [ -f $1 ] && [ -f $2 ]; then + local TMPFILE=tmp.$$ + mv "$1" $TMPFILE + mv "$2" "$1" + mv $TMPFILE "$2" + else + echo -e "${RED}Error:$NC One or more files don't exist" + return 1 + 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://) + 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}') +} + +function ii() +{ + echo -e "\nUser ${RED}"${USER:-"N/A"}"$NC on "${RED}${HOST:-"N/A"}"$NC" + echo -e "\n${RED}Additionnal information:$NC " ; uname -a + echo -e "\n${RED}Users logged on:$NC " ; w -h + echo -e "\n${RED}Current date:$NC " ; date + echo -e "\n${RED}Machine stats:$NC " ; uptime + echo -e "\n${RED}Memory stats:$NC " ; free + my_ip 2>&- ; + echo -e "\n${RED}Local IP Address:$NC" ; echo ${MY_IP:-"N/A"} + echo -e "\n${RED}ISP Address:$NC" ; echo ${MY_ISP:-"N/A"} + 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" + echo -e "\n${RED}Machine stats:$NC " ; uptime + echo +} + +function repeat() +{ + if [ "$1" = "" ] || [ "$2" = "" ] || [ "$1" = "-h" ]; then + echo -e "${blue}Usage:$NC repeat "; + echo -e "Repeats a command"; + return 1 + fi + local i max + max=$1; shift; + for ((i=1; i <= max ; i++)); do + eval "$@"; + done +} + +# actually it converts any mp4 or flv to mp3... +youtube2mp3 () { + for file in "$@" + do + if [ -f ${file} ] ; then + title=$(echo ${file} | sed 's/\(.*\)\..*/\1/') + case $(file -bi ${file}) in + video/mp4) + faad "${file}" && + lame "${title}.wav" "${title}.mp3" && + rm "${title}.wav" + ;; + video/x-flv) + ffmpeg -i "${file}" -vn -acodec copy "${title}.mp3" + ;; + *) + echo -e "${RED}Error:$NC No rule how to convert \"${file}\"" + ;; + esac + else + echo -e "${RED}Error:$NC \"${file}\" doesn't exist" + fi + done +} + +upload_zshrc() { + old_pwd="$PWD" + builtin cd "$HOME/.zsh" + cp -rv "${HOME}/.zsh/rc" "/mnt/nevera/web/html/webseiten/florian/stuff/dotfiles/zsh/" + cp -rv "${HOME}/.zshrc" "/mnt/nevera/web/html/webseiten/florian/stuff/dotfiles/zshrc" + tree -fin --noreport "rc" -o "/mnt/nevera/web/html/webseiten/florian/stuff/dotfiles/zsh/filelist" + builtin cd "$old_pwd" +} diff --git a/.zsh/rc/50options b/.zsh/rc/50options new file mode 100644 index 0000000..fda3936 --- /dev/null +++ b/.zsh/rc/50options @@ -0,0 +1,45 @@ +#-------------------- +# History +#-------------------- +export HISTFILE=~/.zsh/histfile +# for some odd reason allocating RAM to save the histfile takes ages.. +export HISTSIZE=4000 +export SAVEHIST=4000 + +#-------------------- +# Other ZSH options +#-------------------- +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 + +# 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 diff --git a/.zsh/rc/60aliases b/.zsh/rc/60aliases new file mode 100644 index 0000000..6aa652d --- /dev/null +++ b/.zsh/rc/60aliases @@ -0,0 +1,86 @@ +#-------------------- +# 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' + +# 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 pkgbuild='makepkg -fc && aurball' +alias pushpkg='cp *.pkg.tar.gz *.src.tar.gz /mnt/mistral/srv/drop' + +alias sudo="sudo " #Sudo wont recognize aliases without this +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 keymap='setxkbmap de -variant nodeadkeys' + +alias pager='${PAGER}' +alias more='${PAGER}' +alias less='${PAGER}' +alias c='${PAGER}' +alias v='vim' +# sudo needs support for aliases! +alias sc='sudo ${PAGER}' +alias sv='sudo vim' + +alias ncmpc='ncmpc -c' +alias youtube='youtube-dl -b ' + +# updating commands can be long... +alias yup='yaourt -Syu --aur' +alias yu='yaourt -Syu' + +# 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 y='yaourt' +alias ys='yaourt -S' +alias ysb='yaourt -Sb' +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='|' + +# who doesn't need pastebins? +alias -g sp="2>&1 | curl -F 'sprunge=<-' http://sprunge.us" +alias -g pp="2>&1 | wgetpaste -X " + +# 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 diff --git a/.zsh/rc/70completion/10misc b/.zsh/rc/70completion/10misc new file mode 100644 index 0000000..e0fdffe --- /dev/null +++ b/.zsh/rc/70completion/10misc @@ -0,0 +1,49 @@ +#-------------------- +# Completion stuff +#-------------------- +autoload -Uz compinit +compinit + +# 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 + compadd -U -X 'Correct leading 7 to /' -f /$match[1] + fi +} + +zstyle :compinstall filename '$HOME/.zshrc' + +# cache results because yaourt is slow +zstyle ':completion:*' use-cache on +zstyle ':completion:*' cache-path $HOME/.zsh/cache +zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} +zstyle ':completion:*' completer _complete _match _approximate _7slash +zstyle ':completion:*:match:*' original only + +# allow more mistypes if longer command +zstyle -e ':completion:*:approximate:*' \ + max-errors 'reply=($((($#PREFIX+$#SUFFIX)/3))numeric)' + +# ignore completion for commands we don't have +zstyle ':completion:*:functions' ignored-patterns '_*' + +# show menu when tabbing +zstyle ':completion:*' menu yes select +zstyle ':completion:*' file-sort time + +# remove / after dirnames +# e.g. ls foo/ -> ls foo +#zstyle ':completion:*' squeeze-slashes true +zstyle ':completion:*' squeeze-slashes false + +# if in foo/bar don't show bar when cd ../ +zstyle ':completion:*:cd:*' ignore-parents parent pwd + +# 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' diff --git a/.zsh/rc/70completion/10own_functions b/.zsh/rc/70completion/10own_functions new file mode 100644 index 0000000..2be4e67 --- /dev/null +++ b/.zsh/rc/70completion/10own_functions @@ -0,0 +1,14 @@ +# complete my little rc function (archlinux startscripts) +function _rc () { + case $CURRENT in + 2) compadd $(find /etc/rc.d/ -maxdepth 1 -type f -executable -printf '%f ');; + 3) compadd $(/etc/rc.d/$words[2] 2> /dev/null | grep -i usage | sed 's/.*{\(.*\)}/\1/' | sed 's/|/ /g');; + esac +} +compdef _rc rc + +# 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") +} +compdef _ssh-mount ssh-mount.sh \ No newline at end of file diff --git a/.zsh/rc/99greetings b/.zsh/rc/99greetings new file mode 100644 index 0000000..444eda5 --- /dev/null +++ b/.zsh/rc/99greetings @@ -0,0 +1,13 @@ +# machine dependent stuff +. $HOME/.private_stuff.zsh +#-------------------- +# Greetings +#-------------------- +cat /etc/motd +echo -e "${CYAN}Welcome to ZSH ${RED}${ZSH_VERSION}$NC" +short_ii +# don't want to read the same every time I open a new shell +if [ -x /usr/bin/fortune ]; then + /usr/bin/fortune -s +fi +echo -- cgit v1.2.3-24-g4f1b