summaryrefslogtreecommitdiffstats
path: root/.zshrc
blob: 68cdaa8c8bb20a3fa53700e8c315298b17a5300b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
#----------------------------------------------------#
# File: 	~/.zshrc                             #
# Version:	0.3.2				     #
# Author:	Florian "Bluewind" Pritz <f-p@gmx.at>#
#----------------------------------------------------#

#--------------------
# History
#--------------------
HISTFILE=~/.zsh/histfile
HISTSIZE=10000
SAVEHIST=10000

#--------------------
# 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

#--------------------
# Completion stuff
#--------------------
autoload -Uz compinit
compinit

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:*' 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

zstyle ':completion:*' squeeze-slashes true

#if in foo/bar don't show bar when cd ../<TAB>
zstyle ':completion:*:cd:*' ignore-parents parent pwd

# ignore case
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'

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'

#--------------------
# Other ZSH options
#--------------------
autoload colors
colors
setopt autocd
setopt correct_all
setopt extendedglob
setopt auto_pushd
setopt pushd_ignore_dups
setopt no_hup
setopt print_exit_value
setopt SHARE_HISTORY
setopt NO_clobber
setopt APPEND_HISTORY
setopt EXTENDED_HISTORY

#-----------------------
# Variables
#-----------------------
#export CDPATH=.:$HOME
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>&-'
#export LESS='-i -c -N -w -g -M -R -P%t?f%f \
#:stdin .?pb%pb\%:?lbLine %lb:?bbByte %bb:-...'

#--------------------
# Colors
#--------------------
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 cyan='\e[0;36m'
export CYAN='\e[1;36m'
export NC='\e[0m'
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%}'

#--------------------
# Terminal title
#--------------------
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|-*)]}
                                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) '

#--------------------
# Aliases
#--------------------
alias rm='rm -Iv'
alias cp='cp -iv'
alias mv='mv -iv'

alias dum='du -kh --max-depth=2'
alias du='du -kh'
alias df='df -kTh'

alias ls='ls -l --color=auto -h -b'
alias ll='ls -l --color=auto -h -b'
alias la='ls -la --color=auto -h -b'

alias newpkgb=' cp $HOME/misc/aur/PKGBUILD.proto PKGBUILD'

alias u='upload.sh'
alias mtr='mtr -t'
alias wcl='wc -l'

alias pager='${PAGER}'
alias v='vim'
alias sv='sudo vim'

alias pacman='pacman-color'
alias ncmpc='ncmpc -c'
alias yup='yaourt -Syu --aur'
alias yu='yaourt -Syu'
alias x='extract'
alias more='less'
alias youtube='youtube-dl -b '

alias p='sudo powerpill'
alias pa='sudo powerpill -Syu'
alias py='sudo powerpill -S'

alias ysi='yaourt -Si'
alias yqo='yaourt -Qo'
alias y='yaourt'
alias ys='yaourt -S'
alias ad='arson -D'
alias yr='yaourt -Rs'
alias yrn='yaourt -Rns'

alias -g gg='| grep --color'
alias -g eg='| egrep --color'
alias -g tt='| tail -n 20'
alias -g vv='|'

#alias -g pp="2>&1 | curl -F 'sprunge=<-' http://sprunge.us"
alias -g pp="2>&1 | wgetpaste -X "

alias -s txt=leafpad
alias -s jpg=gpicview
alias -s png=gpicview

# source stuff that depends on the machine
source ~/.private_stuff.zsh

#--------------------
# Functions
#--------------------
bk()      { cp -b ${1} ${1}_`date +%Y-%m-%d_%T` }

# jump between directories
# Copyright 2005 Nikolai Weibull <nikolai@bitwi.se>
# 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
  }

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}'<"
  }

2html() { vim -u NONE -n -c ':syntax on' -c ':so $VIMRUNTIME/syntax/2html.vim' -c ':wqa' $1 > /dev/null 2> /dev/null }

yd (){
	mkdir $1
	cd $1
	yaourt -G $1
}

source bin/gpg-agent.sh

google(){
	firefox "http://www.google.com/search?&num=100&q=$*" &
	disown firefox
}

leaf(){
	leafpad $* &
	disown leaf
}

function _7slash {
   if [[ $words[CURRENT] = 7(#b)(*)(#e) ]]
   then
     compadd -U -X 'Correct leading 7 to /' -f /$match[1]
   fi
}

function swap()  
{
    if [ "$1" = "" ] || [ "$2" = "" ] || [ "$1" = "-h" ]; then 
        echo -e "${blue}Usage:$NC swap <file> <file>";
        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
}

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
}

function short_ii()  
{
  echo -e "\nUser ${RED}"${USER:-"N/A"}"$NC on "${RED}${HOST:-"N/A"}"$NC" 
  echo -e "\n${RED}Current date:$NC " ; date
  echo -e "\n${RED}Machine stats:$NC " ; uptime
  echo
}

function repeat()      
{
    if [ "$1" = "" ] || [ "$2" = "" ] || [ "$1" = "-h" ]; then 
        echo -e "${blue}Usage:$NC repeat <number> <command>";
        echo -e "Repeats a command";
        return 1
    fi
    local i max
    max=$1; shift;
    for ((i=1; i <= max ; i++)); do 
        eval "$@";
    done
}

# in the aur as extract
#extract () {
#     if [ "$1" = "" ] || [ "$1" = "-h" ]; then 
#         echo -e "${blue}Usage:$NC x <file>";
#         echo -e "Extracts <file>";
#         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
#}

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
}

#--------------------
# Greetings
#--------------------
echo -e "${CYAN}Welcome to ZSH ${RED}${ZSH_VERSION%.*}$NC"
short_ii
if [ -x /usr/bin/fortune ]; then
    /usr/bin/fortune -s     
fi