zshrc: fixing broken any() function (drop usage of expr)
authorBernhard Tittelbach <bernhard@tittelbach.org>
Fri, 8 Jul 2011 10:00:39 +0000 (12:00 +0200)
committerMichael Prokop <mika@grml.org>
Thu, 21 Jul 2011 09:02:24 +0000 (11:02 +0200)
bug: try "any -i", "any index", "any length", or anything else
that "expr" thinks is a command or option

etc/zsh/zshrc

index 54ce024..996e4e8 100644 (file)
@@ -2875,18 +2875,16 @@ check_com -c qma && alias ?='qma zshall'
 # grep for running process, like: 'any vim'
 any() {
     emulate -L zsh
+    unsetopt KSH_ARRAYS
     if [[ -z "$1" ]] ; then
         echo "any - grep for process(es) by keyword" >&2
         echo "Usage: any <keyword>" >&2 ; return 1
     else
-        local STRING=$1
-        local LENGTH=$(expr length $STRING)
-        local FIRSCHAR=$(echo $(expr substr $STRING 1 1))
-        local REST=$(echo $(expr substr $STRING 2 $LENGTH))
-        ps xauwww| grep "[$FIRSCHAR]$REST"
+        ps xauwww | grep --color=auto "[${1[1]}]${1[2,-1]}"
     fi
 }
 
+
 # After resuming from suspend, system is paging heavily, leading to very bad interactivity.
 # taken from $LINUX-KERNELSOURCE/Documentation/power/swsusp.txt
 [[ -r /proc/1/maps ]] && \