File: init.lua

package info (click to toggle)
awesome-extra 2010071402
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 488 kB
  • ctags: 319
  • sloc: makefile: 40
file content (55 lines) | stat: -rw-r--r-- 1,262 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
-----------------------------------
-- Author: Uli Schlachter        --
-- Copyright 2009 Uli Schlachter --
-----------------------------------

local io = io
local setmetatable = setmetatable
local pairs = pairs
local lib = {
    widget = require("obvious.lib.widget")
}

module("obvious.fs_usage")

-- This returns the percentage of used space on the given mountpoint
function fs(path)
    local df = io.popen("LC_ALL=C df -hP " .. path)
    local key
    local ret = nil

    if not df then
        return nil
    end

    for line in df:lines() do
        local mountpoint = line:match("%% ([-/%w]+)$")
        local dev = line:match("^[%w/-]+")
        local perc = line:match("(%d+)%%")

        if perc ~= nil and mountpoint ~= nil and dev ~= nil then
            ret = perc
        end
    end

    df:close()
    return ret
end

local function get(data)
    return fs(data.path)
end

local function get_data_source(path)
    local path = path or "/"
    local ret = {}

    ret.max = 100
    ret.get = get
    ret.path = path

    return lib.widget.from_data_source(ret)
end

setmetatable(_M, { __call = function (_, ...) return get_data_source(...) end })
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=4:softtabstop=4:encoding=utf-8:textwidth=80