How do I spawn a shell command from X monad and get it output?

76 Views Asked by At

I want to write a shutdown menu for XMonad, and bind it to a key combo.

So the ingredients seem to be these following.

  1. A command, so a String, that can be executed in a shell to open the menu. The user than chooses what to do (e.g. Suspend, Shutdown, ...), and the output of that executable will be a String as well, call it choice.
  2. Then I'd have a pure String -> String function f to map the user decision to the command to run.
  3. Finally I'd have to execute that f choice :: String which woud have no output.

And this whole thing should be done by XMonad, so I assume I would have to add ("M-r", shutdownmenu) to the mappings I pass to def `additionalKeysP` mappings. That shutdownmenu function is the one that should perform the steps above.

But to do that, I'd need, I believe,

  • a String -> X String function to launch the program that asks the user to choose what to do; I though I would find something in XMonad.Util.Run, but no function there seems to have the signature and semantics that I need,
  • the String -> String function, which is the easy thing,
  • the String -> X () function, for which spawn seems to fit the bill.

What I don't find is the first of these ingredients, getCommandOutput looks similar to what I need, but it retuns in the IO moand instead of in the X monad or a generic monad m, so I can't really do much with it in the X monad.

Or can I?

0

There are 0 best solutions below