Add function run
authorJoerg Jaspert <joerg@debian.org>
Fri, 22 Mar 2013 21:52:29 +0000 (22:52 +0100)
committerJoerg Jaspert <joerg@debian.org>
Fri, 22 Mar 2013 21:52:29 +0000 (22:52 +0100)
.zsh/functions/run [new file with mode: 0644]

diff --git a/.zsh/functions/run b/.zsh/functions/run
new file mode 100644 (file)
index 0000000..2a3bccc
--- /dev/null
@@ -0,0 +1,21 @@
+# Run command in background and GUI notify when done
+run () {
+       cmd=($argv[1] $argv[2,-1])
+       runit &
+}
+
+runit() {
+       printable=()
+       for piece in $cmd; do
+               if [[ -n "${piece//[^ ]/}" ]]; then
+                       printable+=('"'"$piece"'"')
+               else
+                       printable+=($piece)
+               fi
+       done
+       {
+       ${cmd}
+       } 2>&1 && notify-send "$printable" "done" || notify-send "$printable" "error $?" &
+}
+
+run "$@"