Skip to content

Instantly share code, notes, and snippets.

@tomasperezv
Forked from Flowkap/spawn_once.lua
Created March 30, 2014 16:26
Show Gist options
  • Save tomasperezv/9875345 to your computer and use it in GitHub Desktop.
Save tomasperezv/9875345 to your computer and use it in GitHub Desktop.
-- {{{
--
-- 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])
-- }}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment