Re: [dev] dmenu / enso

From: Preben Randhol <randhol_AT_pvv.org>
Date: Mon, 22 Jun 2009 14:53:24 +0200 (CEST)

> Another neat thing is you could open, e.g. open openoffice writer,
> type in "2+3/5", highlight, type in enso-terminal "calc this", and
> the result replaces the "2+3/5" string in your document. They claim
> that you can do this with other programs as well. I believe I can
> program the parser as a unix command, but when it is run from dmenu,
> then I need to specify arguments.

Yes, but why do you need first to type this in application X and then mark
it and then run enzo? Seems backwards to me.

What I do is I call my simple dmenu_calc script (i could make it
multipurpose, but I like to have the calculations separate to make things
easier).

Dependancies: bash, xdotool, apcalc and units

#!/bin/bash
EQ=$(echo "" | dmenu -p "calc:" -fn
"-*-terminus-medium-r-normal-*-12-*-*-*-*-*-iso10646-*" -nb "#222222" -nf
"#fafafa" -sb "#209020" -sf "#ffffff")

if [ -n "$EQ" ]; then
        if [ "${EQ:0:1}" = "_" ]; then
                xdotool type $(units --compact -1 ${EQ:1})
        else
                xdotool type $(calc $EQ)
        fi
fi

I envoke the script by a shortcut in dwm and then you can either do
calculations or unit conversion.

unit conversion you simply prefix _ like:
_ 3inches mm

inserts 76.2 in the app you have focus

to do calculations you simply type f.eks:

12/3

or

x=1.2;(3^x)/x

and it should return 4 or 3.11432....

For me this is more intuitive than having to write the eq and then mark it
etc... and it works better with vim.

This script works on Ubuntu 9.04. Copy/port/modify/distribute as you wish
if you find it useful :-)
Received on Mon Jun 22 2009 - 12:53:24 UTC

This archive was generated by hypermail 2.2.0 : Mon Jun 22 2009 - 13:00:01 UTC