Skip to content

Instantly share code, notes, and snippets.

@Flowkap
Last active August 21, 2017 10:31
Show Gist options
  • Save Flowkap/8858434 to your computer and use it in GitHub Desktop.
Save Flowkap/8858434 to your computer and use it in GitHub Desktop.
This is a small gist for autostarting applications with Awesome Window Manager (http://awesome.naquadah.org/) without the need to use a third party plugin like shifty. It's maybe not nice but works!
-- {{{
--
-- Autostarting for Awesome <3.4!
-- Add this section to the end of your rc.lua
-- configuration file within ~/.config/awesome/rc.lua
--
-- If you're using Awesome 3.5 change:
-- add_signal -> connect_signal
-- remove_signal --> disconnect_signal
--
-- Thanks to eri_trabiccolo as well as psychon
--
function spawn_once(command, class, tag)
-- create move callback
local callback
callback = function(c)
if c.class == class then
awful.client.movetotag(tag, c)
client.remove_signal("manage", callback)
end
end
client.add_signal("manage", callback)
-- now check if not already running!
local findme = command
local firstspace = findme:find(" ")
if firstspace then
findme = findme:sub(0, firstspace-1)
end
-- finally run it
awful.util.spawn_with_shell("pgrep -u $USER -x " .. findme .. " > /dev/null || (" .. command .. ")")
end
-- use the spawn_once
spawn_once("subl", "Sublime_text", tags[1][2])
spawn_once("chromium", "Chromium", tags[1][3])
spawn_once("thunar", "Thunar", tags[1][4])
spawn_once("xchat", "Xchat", tags[1][5])
-- }}}
@coldfix
Copy link

coldfix commented Aug 21, 2017

By the way, in recent versions of awesome you can pass rules directly to the spawn function, like so:

awful.spawn(cmd, {
    tag = mouse.screen.selected_tag,
})

If you want to emulate with_shell just pass cmd = { awful.util.shell, '-c', cmd }.

This will provide more correct behaviour, i.e. set the tag for the correct process if several are spawned simultaneously) and maybe also set the tag for all windows if the process creates more than one (I didn't test).

Also, it simplifies the code by a good deal since you don't have to manage signal handlers manually and you don't need to know the window class name in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment