Search code examples
awesome-wm

How to use one key-binding to spawn tag-specific program in awesome-wm?


Introduction: In my wrokflow, I am using tags for specific purposes (WEB, IDE, EMAIL, File Manager,>Terminal/Taskwarrior-tui/Timewarrior) and I want to stick to this. So whenever I go to tag 1 I want to have a browser there.

Problem: I would like to minimize the number of key bindings for the most important programs.

Question: How can I use one keybinding for launching a "default program for the tag"??

Example: Let's say that I am currently on tag 1 (called WEB) which default application would be qutebrowser (at least in my case) so I would like to hit MOD+D to spawn qutebrowser. But when I hit the same keybinding (MOD+D) on tag 2 i want awesome-wm to spawn Rstudio.

Note that I am not asking how to make a rule of spawning a certain program on specific tag (with a keybinding assigned to spawning this program) as there are a lot of answers to that around the web. I want to have conditional rule, based on which tag is active, to spawn a predefined app in this tag with one keybinding.


Solution

  • awful.keyboard.append_global_keybindings({
          awful.key({ modkey }, "d", function()
                local t = awful.screen.focused().selected_tag
                if t.name == "WEB" then
                   -- launch qutebrowser
                elseif t.name == "tag 2 name" then
                   -- launch Rstudio
                end
          end,
             {description = "description", group = "group"})
    })