local fs = {}

local DEFAULT_SIGNAL = "fs::value"

local fs_script = [[ df -h --output=used,size / | sed 's/G//g' ]]

function fs.get(callback)
  awful.spawn.easy_async_with_shell(fs_script, function (out)
    local val = gears.string.split(out, " ")
    callback(tonumber(val[6]), tonumber(val[8]))
  end)
end

function fs.emit(name)
	fs.get(function(...)
		awesome.emit_signal(name or DEFAULT_SIGNAL, ...)
	end)
end

function fs.register_signal(signal_name, update_interval)
	gears.timer {
		timeout = update_interval or 5,
		call_now = true,
		autostart = true,
		callback = function() fs.emit(signal_name) end
	}
end

return fs
