Launch In Terminal Keyword

From awesome
Jump to: navigation, search

This is a modified run command that accepts and intial ":" keyword to indicate launching commands in a terminal.

For instance, ":mc" would open a terminal and run mc.

Or my favorite ":aptitude".

This is all done in the ~/.config/awesome/rc.lua

This is the key definition that you would add to your globalkeys:

 
awful.key({ modkey,           }, "r", 
              function () awful.prompt.run({prompt="Run:"},
                                           mypromptbox[mouse.screen].widget,
                                           check_for_terminal,
                                           clean_for_completion,
                                           awful.util.getdir("cache") .. "/history") end)

These are the functions it needs. I just added them to the bottom of my rc.lua and that seems to work just fine:

-- {{{ functions to help launch run commands in a terminal using ":" keyword 
function check_for_terminal (command)
   if command:sub(1,1) == ":" then
      command = terminal .. ' -e "' .. command:sub(2) .. '"'
   end
   awful.util.spawn(command)
end
   
function clean_for_completion (command, cur_pos, ncomp, shell)
   local term = false
   if command:sub(1,1) == ":" then
      term = true
      command = command:sub(2)
      cur_pos = cur_pos - 1
   end
   command, cur_pos =  awful.completion.shell(command, cur_pos,ncomp,shell)
   if term == true then
      command = ':' .. command
      cur_pos = cur_pos + 1
   end
   return command, cur_pos
end
-- }}}
Personal tools