/etc/zsh/zshrc: added functions deswap, hex and peval
authorMichael Prokop <mika@grml.org>
Wed, 10 Jan 2007 23:27:59 +0000 (00:27 +0100)
committerMichael Prokop <mika@grml.org>
Wed, 10 Jan 2007 23:27:59 +0000 (00:27 +0100)
debian/changelog
etc/zsh/zshrc

index b354f5b..1988bc4 100644 (file)
@@ -13,6 +13,8 @@ grml-etc-core (0.2.15) unstable; urgency=low
       want to miss the feature itself, so just press 0<cr> and that's
       it :))
     - added alias debs-by-size
+    - added function deswap (useful after suspending), function hex
+      (print hex value of a number) and function peval (perl-eval)
 
  -- Michael Prokop <mika@grml.org>  Fri,  5 Jan 2007 00:00:54 +0100
 
index 7cf2087..fbefb58 100644 (file)
@@ -797,7 +797,7 @@ grmlcomp() {
   [ -d $ZSHDIR/cache ] && zstyle ':completion:*' use-cache yes && \
                           zstyle ':completion::complete:*' cache-path $ZSHDIR/cache/
 
-# host completion
+# host completion /* add brackets as vim can't parse zsh's complex cmdlines 8-) {{{ */
   if is42 ; then
     [ -r ~/.ssh/known_hosts ] && _ssh_hosts=(${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[\|]*}%%\ *}%%,*}) || _ssh_hosts=()
     [ -r /etc/hosts ] && : ${(A)_etc_hosts:=${(s: :)${(ps:\t:)${${(f)~~"$(</etc/hosts)"}%%\#*}##[:blank:]#[^[:blank:]]#}}} || _etc_hosts=()
@@ -1043,6 +1043,27 @@ If you want to use xinit anyway please call \"/usr/bin/xinit\"."
   fi
   }
 
+  # After resuming from suspend, system is paging heavilly, leading to very bad interactivity.
+  # taken from $LINUX-KERNELSOURCE/Documentation/power/swsusp.txt
+  [ -r /proc/1/maps ] && deswap() {
+     print 'Reading /proc/[0-9]*/maps and sending output to /dev/null, this might take a while.'
+     cat $(sed -ne 's:.* /:/:p' /proc/[0-9]*/maps | sort -u | grep -v '^/dev/')  > /dev/null
+     print 'Finished, running "swapoff -a; swapon -a" may also be useful.'
+  }
+
+  # print hex value of a number
+  hex() {
+    [ -n "$1" ] && printf "%x\n" $1 || { print 'Usage: hex <number-to-convert>' ; return 1 }
+  }
+
+  # calculate (or eval at all ;-)) with perl => p[erl-]eval
+  # hint: also take a look at zcalc -> 'autoload zcalc' -> 'man zshmodules | less -p MATHFUNC'
+  peval() {
+    [ -n "$1" ] && CALC="$*" || print "Usage: calc [expression]"
+    perl -e "print eval($CALC),\"\n\";"
+  }
+  functions peval &>/dev/null && alias calc=peval
+
   # Switching shell safely and efficiently? http://www.zsh.org/mla/workers/2001/msg02410.html
   # bash() {
   #  NO_SWITCH="yes" command bash "$@"