summary refs log tree commit diff
path: root/Functions
diff options
context:
space:
mode:
Diffstat (limited to 'Functions')
-rw-r--r--Functions/MIME/pick-web-browser59
-rw-r--r--Functions/Misc/.distfiles1
-rw-r--r--Functions/Misc/zcalc31
3 files changed, 64 insertions, 27 deletions
diff --git a/Functions/MIME/pick-web-browser b/Functions/MIME/pick-web-browser
index 665b0db54..ce35a0a79 100644
--- a/Functions/MIME/pick-web-browser
+++ b/Functions/MIME/pick-web-browser
@@ -22,6 +22,8 @@
 emulate -L zsh
 setopt extendedglob cbases nonomatch
 
+zmodload -i zsh/zutil
+
 local -a xbrowsers ttybrowsers
 
 # X Windows browsers which might be running and can accept
@@ -38,7 +40,7 @@ zstyle -a :mime: tty-browsers ttybrowsers ||
 litc="-_./"
 
 local -a windows remoteargs match mbegin mend
-local url browser
+local url browser command
 
 url=$1
 if [[ -f $url ]]; then
@@ -80,22 +82,31 @@ if [[ -n $DISPLAY ]]; then
 
   # Is any browser we've heard of running?
   for browser in $xbrowsers; do
-    if [[ $windows[(I)(#i)$browser] -ne 0 ]]; then
-      if [[ $browser = konqueror ]]; then
-	# kfmclient is less hairy and better supported than direct
-	# use of dcop.  Run kfmclient --commands
-	# for more information.  Note that as konqueror is a fully
-	# featured file manager, this will actually do complete
-	# MIME handling, not just web pages.
-	kfmclient openURL $url ||
-	  dcop $(dcop|grep konqueror) default openBrowserWindow $url
-      elif [[ $browser = firefox ]]; then
-	  # open in new tab: should make this customizable
-	  $browser -new-tab $url
+    # Some browser executables call themselves <browser>-bin
+    if [[ $windows[(I)(#i)$browser(|[.-]bin)] -ne 0 ]]; then
+      if zstyle -s ":mime:browser:running:${browser}:" command command; then
+	# The (q)'s here and below are pure paranoia:  no browser
+	# name is going to include metacharacters, and we already
+	# converted difficult characters in the URL to hex.
+	zformat -f command $command b:${(q)browser} u:${(q)url}
+	eval $command
       else
-	# Mozilla bells and whistles are described at:
-	# http://www.mozilla.org/unix/remote.html
-	$browser -remote "openURL($url)"
+	if [[ $browser = konqueror ]]; then
+	  # kfmclient is less hairy and better supported than direct
+	  # use of dcop.  Run kfmclient --commands
+	  # for more information.  Note that as konqueror is a fully
+	  # featured file manager, this will actually do complete
+	  # MIME handling, not just web pages.
+	  kfmclient openURL $url ||
+	    dcop $(dcop|grep konqueror) default openBrowserWindow $url
+        elif [[ $browser = firefox ]]; then
+	  # open in new tab
+	  $browser -new-tab $url
+        else
+	  # Mozilla bells and whistles are described at:
+	  # http://www.mozilla.org/unix/remote.html
+	  $browser -remote "openURL($url)"
+        fi
       fi
       return
     fi
@@ -104,8 +115,13 @@ if [[ -n $DISPLAY ]]; then
   # Start our preferred X Windows browser in the background.
   for browser in $xbrowsers; do
       if eval "[[ =$browser != \\=$browser ]]"; then
-	# The following is to make the job text more readable.
-	eval ${(q)browser} ${(q)url} "&"
+	if zstyle -s ":mime:browser:new:${browser}:" command command; then
+	  zformat -f command $command b:${(q)browser} u:${(q)url}
+	  eval $command "&"
+	else
+	  # The following is to make the job text more readable.
+	  eval ${(q)browser} ${(q)url} "&"
+	fi
 	break
       fi
   done
@@ -113,7 +129,12 @@ else
   # Start up dumb terminal browser.
   for browser in $ttybrowsers; do
     if eval "[[ =$browser != \\=$browser ]]"; then
-      $browser $url
+      if zstyle -s ":mime:browser:new:${browser}" command command; then
+	zformat -f command $command b:${(q)browser} u:${(q)url}
+	eval $command
+      else
+	$browser $url
+      fi
       break
     fi
   done
diff --git a/Functions/Misc/.distfiles b/Functions/Misc/.distfiles
index 9b078cb65..08cd89554 100644
--- a/Functions/Misc/.distfiles
+++ b/Functions/Misc/.distfiles
@@ -3,4 +3,5 @@ DISTFILES_SRC='
 allopt      getjobs       mere       relative   zcalc   zmv          zargs
 checkmail   harden        nslookup   run-help   zed     zrecompile
 colors      is-at-least   promptnl   tetris     zkbd    zstyle+
+zmathfuncdef
 '
diff --git a/Functions/Misc/zcalc b/Functions/Misc/zcalc
index b83a939c9..9ce02c02f 100644
--- a/Functions/Misc/zcalc
+++ b/Functions/Misc/zcalc
@@ -42,6 +42,13 @@
 # use the variables listed in the `local' and `integer' lines below
 # (translation: I can't be bothered to provide a sandbox).
 #
+# You can declare or delete math functions (implemented via zmathfuncdef):
+#   1> function cube $1 * $1 * $1
+# This has a single compulsory argument.  Note the function takes care of
+# the punctuation.  To delete the function, put nothing (at all) after
+# the function name:
+#   1> function cube
+#
 # Some constants are already available: (case sensitive as always):
 #   PI     pi, i.e. 3.1415926545897931
 #   E      e, i.e. 2.7182818284590455
@@ -86,6 +93,8 @@
 emulate -L zsh
 setopt extendedglob
 
+# TODO: make local variables that shouldn't be visible in expressions
+# begin with _.
 local line ans base defbase forms match mbegin mend psvar optlist opt arg
 local compcontext="-math-"
 integer num outdigits outform=1
@@ -96,6 +105,7 @@ history -ap "${ZDOTDIR:-$HOME}/.zcalc_history"
 forms=( '%2$g' '%.*g' '%.*f' '%.*E' )
 
 zmodload -i zsh/mathfunc 2>/dev/null
+autoload zmathfuncdef
 
 : ${ZCALCPROMPT="%1v> "}
 
@@ -167,34 +177,39 @@ while vared -cehp "${(%)ZCALCPROMPT}" line; do
   print -s -- $line
 
   case ${${line##[[:blank:]]#}%%[[:blank:]]#} in
-    q) # Exit if `q' on its own.
+    (q) # Exit if `q' on its own.
       return 0
     ;;
-    norm) # restore output format to default
+    (norm) # restore output format to default
       outform=1
     ;;
-    sci[[:blank:]]#(#b)(<->)(#B))
+    (sci[[:blank:]]#(#b)(<->)(#B))
       outdigits=$match[1]
       outform=2
     ;;
-    fix[[:blank:]]#(#b)(<->)(#B))
+    (fix[[:blank:]]#(#b)(<->)(#B))
       outdigits=$match[1]
       outform=3
     ;;
-    eng[[:blank:]]#(#b)(<->)(#B))
+    (eng[[:blank:]]#(#b)(<->)(#B))
       outdigits=$match[1]
       outform=4
     ;;
-    local([[:blank:]]##*|))
+    (local([[:blank:]]##*|))
       eval $line
       line=
       continue
     ;;
-    *)
+    (function[[:blank:]]##(#b)([^[:blank:]]##)(|[[:blank:]]##([^[:blank:]]*)))
+      zmathfuncdef $match[1] $match[3]
+      line=
+      continue
+    ;;
+    (*)
       # Latest value is stored as a string, because it might be floating
       # point or integer --- we don't know till after the evaluation, and
       # arrays always store scalars anyway.
-      # 
+      #
       # Since it's a string, we'd better make sure we know which
       # base it's in, so don't change that until we actually print it.
       eval "ans=\$(( $line ))"