2010-12-05 16:57:06 +01:00
|
|
|
# @author Sebastian Tramp <mail@sebastian.tramp.name>
|
|
|
|
# @license http://opensource.org/licenses/gpl-license.php
|
|
|
|
#
|
|
|
|
# functions and key bindings to that functions
|
|
|
|
#
|
|
|
|
|
|
|
|
# strg+x,s adds sudo to the line
|
|
|
|
# Zsh Buch p.159 - http://zshbuch.org/
|
|
|
|
run-with-sudo() { LBUFFER="sudo $LBUFFER" }
|
|
|
|
zle -N run-with-sudo
|
|
|
|
bindkey '^Xs' run-with-sudo
|
|
|
|
|
|
|
|
# Top ten memory hogs
|
|
|
|
# http://www.commandlinefu.com/commands/view/7139/top-ten-memory-hogs
|
|
|
|
memtop() {ps -eorss,args | sort -nr | pr -TW$COLUMNS | head}
|
|
|
|
zle -N memtop
|
|
|
|
|
2011-03-09 19:33:53 +01:00
|
|
|
tmux-hglog() {
|
2010-12-20 10:45:27 +01:00
|
|
|
tmux kill-pane -t 1
|
|
|
|
tmux split-window -h -l 40 "while true; do clear; date; echo; hg xlog-small -l 5 || exit; sleep 600; done;"
|
|
|
|
tmux select-pane -t 0
|
|
|
|
}
|
|
|
|
|
2011-03-09 19:33:53 +01:00
|
|
|
# tmux-neww-in-cwd - open a new shell with same cwd as calling pane
|
|
|
|
# http://chneukirchen.org/dotfiles/bin/tmux-neww-in-cwd
|
|
|
|
tmux-neww-in-cwd() {
|
|
|
|
SIP=$(tmux display-message -p "#S:#I:#P")
|
|
|
|
|
|
|
|
PTY=$(tmux server-info |
|
|
|
|
egrep flags=\|bytes |
|
|
|
|
awk '/windows/ { s = $2 }
|
|
|
|
/references/ { i = $1 }
|
|
|
|
/bytes/ { print s i $1 $2 } ' |
|
|
|
|
grep "$SIP" |
|
|
|
|
cut -d: -f4)
|
|
|
|
|
|
|
|
PTS=${PTY#/dev/}
|
|
|
|
|
|
|
|
PID=$(ps -eao pid,tty,command --forest | awk '$2 == "'$PTS'" {print $1; exit}')
|
|
|
|
|
|
|
|
DIR=$(readlink /proc/$PID/cwd)
|
|
|
|
|
|
|
|
tmux neww "cd '$DIR'; $SHELL"
|
|
|
|
}
|
|
|
|
|
2010-12-05 17:16:44 +01:00
|
|
|
# Escape potential tarbombs
|
|
|
|
# http://www.commandlinefu.com/commands/view/6824/escape-potential-tarbombs
|
2010-12-25 19:55:20 +01:00
|
|
|
etb() {
|
2010-12-05 17:16:44 +01:00
|
|
|
l=$(tar tf $1);
|
|
|
|
if [ $(echo "$l" | wc -l) -eq $(echo "$l" | grep $(echo "$l" | head -n1) | wc -l) ];
|
|
|
|
then tar xf $1;
|
|
|
|
else mkdir ${1%.t(ar.gz||ar.bz2||gz||bz||ar)} && tar xvf $1 -C ${1%.t(ar.gz||ar.bz2||gz||bz||ar)};
|
|
|
|
fi ;
|
|
|
|
}
|
|
|
|
|
2010-12-20 10:45:27 +01:00
|
|
|
# http://www.commandlinefu.com/commands/view/4792/a-function-to-find-the-newest-file-in-a-directory
|
|
|
|
newest () { find ${1:-\.} -type f |xargs ls -lrt ; }
|
|
|
|
|
|
|
|
# http://www.commandlinefu.com/commands/view/7294/backup-a-file-with-a-date-time-stamp
|
|
|
|
buf () {
|
|
|
|
oldname=$1;
|
|
|
|
if [ "$oldname" != "" ]; then
|
|
|
|
datepart=$(date +%Y-%m-%d);
|
|
|
|
firstpart=`echo $oldname | cut -d "." -f 1`;
|
|
|
|
newname=`echo $oldname | sed s/$firstpart/$firstpart.$datepart/`;
|
2011-04-11 22:51:59 +02:00
|
|
|
cp -R ${oldname} ${newname};
|
2010-12-20 10:45:27 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
atomtitles () { curl --silent $1 | xmlstarlet sel -N atom="http://www.w3.org/2005/Atom" -t -m /atom:feed/atom:entry -v atom:title -n}
|
|
|
|
|
2010-12-05 17:16:44 +01:00
|
|
|
|
2011-01-03 00:12:13 +01:00
|
|
|
function printHookFunctions () {
|
|
|
|
print -C 1 ":::pwd_functions:" $chpwd_functions
|
|
|
|
print -C 1 ":::periodic_functions:" $periodic_functions
|
|
|
|
print -C 1 ":::precmd_functions:" $precmd_functions
|
|
|
|
print -C 1 ":::preexec_functions:" $preexec_functions
|
|
|
|
print -C 1 ":::zshaddhistory_functions:" $zshaddhistory_functions
|
|
|
|
print -C 1 ":::zshexit_functions:" $zshexit_functions
|
|
|
|
}
|
|
|
|
|
2010-12-05 16:57:06 +01:00
|
|
|
# reloads all functions
|
|
|
|
# http://www.zsh.org/mla/users/2002/msg00232.html
|
|
|
|
r() {
|
|
|
|
local f
|
|
|
|
f=(~/.zsh/functions.d/*(.))
|
|
|
|
unfunction $f:t 2> /dev/null
|
|
|
|
autoload -U $f:t
|
|
|
|
}
|
|
|
|
|
|
|
|
# activates zmv
|
|
|
|
autoload zmv
|
2010-12-05 17:37:31 +01:00
|
|
|
# noglob so you don't need to quote the arguments of zmv
|
|
|
|
# mmv *.JPG *.jpg
|
|
|
|
alias mmv='noglob zmv -W'
|
2011-01-09 10:39:04 +01:00
|
|
|
|
|
|
|
# start a webcam for screencast
|
|
|
|
function webcam () {
|
|
|
|
mplayer -cache 128 -tv driver=v4l2:width=350:height=350 -vo xv tv:// -noborder -geometry "+1340+445" -ontop -quiet 2>/dev/null >/dev/null
|
|
|
|
}
|
2011-02-08 21:13:23 +01:00
|
|
|
|
|
|
|
# Rename files in a directory in an edited list fashion
|
|
|
|
# http://www.commandlinefu.com/commands/view/7818/
|
|
|
|
function massmove () {
|
|
|
|
ls > ls; paste ls ls > ren; vi ren; sed 's/^/mv /' ren|bash; rm ren ls
|
|
|
|
}
|
|
|
|
|
2011-02-18 19:54:00 +01:00
|
|
|
|
|
|
|
# Put a console clock in top right corner
|
|
|
|
# http://www.commandlinefu.com/commands/view/7916/
|
|
|
|
function clock () {
|
|
|
|
while sleep 1;
|
|
|
|
do
|
|
|
|
tput sc
|
|
|
|
tput cup 0 $(($(tput cols)-29))
|
|
|
|
date
|
|
|
|
tput rc
|
|
|
|
done &
|
|
|
|
}
|
2011-03-09 19:33:53 +01:00
|
|
|
|
|
|
|
function apt-import-key () {
|
|
|
|
gpg --keyserver subkeys.pgp.net --recv-keys $1 | gpg --armor --export $1 | sudo apt-key add -
|
|
|
|
}
|
|
|
|
|
|
|
|
# create a new script, automatically populating the shebang line, editing the
|
|
|
|
# script, and making it executable.
|
|
|
|
# http://www.commandlinefu.com/commands/view/8050/
|
|
|
|
shebang() {
|
|
|
|
if i=$(which $1);
|
|
|
|
then
|
|
|
|
printf '#!/usr/bin/env %s\n\n' $1 > $2 && chmod 755 $2 && vim + $2 && chmod 755 $2;
|
|
|
|
else
|
|
|
|
echo "'which' could not find $1, is it in your \$PATH?";
|
|
|
|
fi;
|
|
|
|
}
|
|
|
|
|
|
|
|
|