Debian Codegraph @

vicious/widgets/os_bsd.lua

raw symbols SCIP
1 -- operating system widget type for *BSD
2 -- Copyright (C) 2019 mutlusun <[email protected]>
3 --
4 -- This file is part of Vicious.
5 --
6 -- Vicious is free software: you can redistribute it and/or modify
7 -- it under the terms of the GNU General Public License as
8 -- published by the Free Software Foundation, either version 2 of the
9 -- License, or (at your option) any later version.
10 --
11 -- Vicious is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU General Public License for more details.
15 --
16 -- You should have received a copy of the GNU General Public License
17 -- along with Vicious. If not, see <https://www.gnu.org/licenses/>.
18
19 -- {{{ Grab environment
20 local los = { getenv = os.getenv }
21 local string = { match = string.match }
22 local helpers = require("vicious.helpers")
23 local spawn = require("vicious.spawn")
24 -- }}}
25
26 -- OS: provides operating system information
27 -- vicious.widgets.os
28 local os_bsd = {}
29
30 -- {{{ Operating system widget type
31 local function parse(stdout, stderr, exitreason, exitcode)
32 local system = {
33 ["ostype"] = "N/A",
34 ["hostname"] = "N/A",
35 ["osrelease"] = "N/A",
36 ["username"] = "N/A",
37 ["entropy"] = "N/A",
38 ["entropy_p"] = "N/A"
39 }
40
41 -- BSD manual page: uname(1)
42 system["ostype"], system["hostname"], system["osrelease"] =
43 string.match(stdout, "([%w]+)[%s]([%w%p]+)[%s]([%w%p]+)")
44
45 -- Get user from the environment
46 system["username"] = los.getenv("USER")
47
48 return {system["ostype"], system["osrelease"], system["username"],
49 system["hostname"], system["entropy"], system["entropy_p"]}
50 end
51
52 function os_bsd.async(format, warg, callback)
53 spawn.easy_async("uname -snr",
54 function (...) callback(parse(...)) end)
55 end
56 -- }}}
57
58 return helpers.setasyncall(os_bsd)