1. 14

I’ve been annoyed that Mac (and Windows?) users have been able to write math in their launcher, while I with my i3wm and dmenu couldn’t. I decided to do something about that today.

mmenu is a short script intended to be a replacement for dmenu_run. It works the same, executing the program you select, except that if you don’t select the name of a program, the result is fed to python to be executed.

I also added a function to convert from a number to another base, as I find myself needing to do that often. If you have a suggestion for other useful functions, do tell, and I’ll consider adding it (or you could just do a pull request).

The script menu-calc is great, and does something similar, but because it’s just an executable in your $PATH, it has some limitations; you can’t just write an expression but have to prepend =, you have to quote stuff, etc. I found there to be just enough quirks and friction that I never really ended up using it even though I’ve had it installed for months.

Edit: a short screencast: https://gfycat.com/ElectricDesertedGrub

Edit 2: I created a git repo for it: https://github.com/mortie/mmenu

  1.  

  2. 3

    mmenu is a short script intended to be a replacement for dmenu_run. It works the same, executing the program you select, except that if you don’t select the name of a program, the result is fed to python to be executed.

    It shouldn’t be hard to do this more generally, which is really the best thing about dmenu… the fact that it does one thing really well.

    1. 2

      I assume the part you’re saying could be done more generally is letting you plug in any launcher, not just dmenu. That should be possible. I’ll look into doing that.

      1. 2

        No! The opposite! dmenu is general enough to allow for a math script, or any other type of thing you’d want to do here.

        1. 3

          Oh. Well, that’s basically what the menu-calc script I mentioned does; it creates a binary called =, which you can give a bath expression which it evaluates. The problem with that is that you can’t really make it “just work” with any expression as you have to type the = to make dmenu run it. dmenu_run will also run your input through sh (or $SHELL), so if you type = 200 * 5, the shell will try to expand the * into all files in the “current directory”.

          Unless there’s some way to extend it which I’m not aware of?

          1. 2

            What I was getting at is that you could do things like this. Based on some prefix, you could run additional commands, and use dmenu to display the result with -p (like you already do) in mmenu.

            Most people use dmenu_run as synonym for dmenu, though, and probably wouldn’t want to have to type run\n just to launch a program.

            1. 3

              Come to think of it, you could do a number of other neat things as well. Like, as an example (this wiki over DNS service is now defunct, but…), if you did wiki foo, it could spit out to you the output of

              host -t txt foo.wp.dg.cx | fmt | dmenu -l 10