summaryrefslogtreecommitdiffstats
path: root/.zsh/rc/30functions
diff options
context:
space:
mode:
Diffstat (limited to '.zsh/rc/30functions')
-rw-r--r--.zsh/rc/30functions223
1 files changed, 223 insertions, 0 deletions
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 <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
+}
+
+# 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 <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
+}
+
+# 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 <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
+}
+
+# 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"
+}