awesomeWM / awesome

awesome window manager
https://awesomewm.org/
GNU General Public License v2.0
6.39k stars 597 forks source link

Better terminal detection in default config #1217

Open blueyed opened 8 years ago

blueyed commented 8 years ago

One annoyance when being dropped into the default config is that you are getting xterm as your terminal.

E.g. with Debian based systems, we could default to x-terminal-emulator.

I am using urxvt myself, but there seems to be nothing like x-terminal-emulator for Arch Linux, or is there?

actionless commented 8 years ago

ugly but working for me:

awesome-client 'require("awful").spawn.with_shell("unknown_term || xterm || urxvt")'

(can't wait for a https://github.com/awesomeWM/awesome/issues/1166 :) )

blueyed commented 8 years ago

Where is unknown_term coming from?

actionless commented 8 years ago

it's an example of terminal command which should fail, like unknown_term is not installed, but xterm is

UPD however that approach will cause weird behavior if terminal will exit with non-zero

actionless commented 8 years ago

or we could try to do it cleaner but still weird, like:

awful.newmodule.terminals = {'x-terminal-emulator', 'xterm', 'urxvt', 'st', 'whatever else'}

local found_terminal

function awful.newmodule.get_terminal(callback)
  if found_terminal then
    return callback(found_terminal)
  end
  local terminal_index = 1

  local function _check_next()
    local terminal = awful.newmodule.terminals[terminal_index]
    awful.spawn.easy_async('which ' .. terminal, function(_, _, _, exit_code)
      if exit_code == 0 then 
        found_terminal = terminal
        callback(found_terminal)
      else
        terminal_index = terminal_index + 1
        if terminal_index <= #awful.newmodule.terminals then
          _check_next()
        else
          -- what to do if nothing found? :)
        end
      end
    end)
  end

  _check_next()
end

function awful.newmodule.set_terminal(terminal)
   found_terminal = terminal
end

<...>

awful.newmodule.set_terminal('urxvt')

<...>

    awful.key({ modkey,           }, "Return", function ()
                   awful.newmodule.get_terminal(function(term) awful.spawn(term) end)
              end,
              {description = "open a terminal", group = "launcher"}),
blueyed commented 8 years ago

Yeah, I see - but in this example xterm would still be preferred. We should not over-engineer it, but just try to look at what distributions provide.

actionless commented 8 years ago

ah, i've got the point

then we could allow it to override it somehow, see updated example

actionless commented 8 years ago

btw, do we still have some synchronous spawn? it would be easier to use get_terminal() as synchronous function which returns terminal

mindeunix commented 8 years ago

In Debian (and ubuntu?), we can simply call x-terminal-emulator -e /some/command, unfortunately not all distros includes x-terminal-emulator...

P.S it would be nice to have a new menu item which opens API documentation: xdg-open http://new.awesomewm.org/apidoc/index.html

actionless commented 8 years ago

regarding the latter point -- i think it would be better to use file:///usr/share/doc/awesome/doc/index.html instead

r3lgar commented 8 years ago

file:///usr/share/doc/awesome/doc/index.html instead

Only with docs installed, otherwise we need to go to wiki website. So we need yet another parser. Useless, don't need.

Link in man page should be enough.

actionless commented 8 years ago

built documentation will match the installed awesome version while online documentation will not

psychon commented 8 years ago

btw, do we still have some synchronous spawn? it would be easier to use get_terminal() as synchronous function which returns terminal

Which synchronous functions were available? The only one that I remember is awful.util.pread and that was just some small wrapper around io.popen: https://github.com/awesomeWM/awesome/blob/061751dd9d3a3f08e4efa1739adb4f93e73bee98/lib/awful/util.lua.in#L93-L107

Edit: And of course, the first if here doesn't help anyone, so is useless. The next if f is always true, because io.popen can in practice only fail due to out-of-memory.

actionless commented 8 years ago

yup, that was the one i kept in mind

what do you think of using it for cached sycnhronous get_terminal() function? (see asynchronous example in one of my comments above: https://github.com/awesomeWM/awesome/issues/1217#issuecomment-259575577)

psychon commented 8 years ago

I would think that it would not help you / would not work. You cannot get the exit code with popen (you can not even redirect stderr, so all unsuccessful lookups would spam awesome's stderr with something like "sh: sl: command not found").

actionless commented 8 years ago

@Elv13 mb glib have some analogue of which command?