From 62edc5a200ae9f0d65127ebf141d276e7c9a78ab Mon Sep 17 00:00:00 2001 From: romildo Date: Fri, 17 Mar 2017 21:14:37 -0300 Subject: [PATCH] Add get_xdg_data_home and get_xdg_data_dirs functions to gears.filesystem --- lib/gears/filesystem.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/gears/filesystem.lua b/lib/gears/filesystem.lua index eff5dbcf..9c0e340f 100644 --- a/lib/gears/filesystem.lua +++ b/lib/gears/filesystem.lua @@ -6,6 +6,8 @@ -- Grab environment we need local Gio = require("lgi").Gio +local gstring = require("gears.string") +local gtable = require("gears.table") local filesystem = {} @@ -66,6 +68,21 @@ function filesystem.get_xdg_cache_home() return (os.getenv("XDG_CACHE_HOME") or os.getenv("HOME") .. "/.cache") .. "/" end +--- Get the data home according to the XDG basedir specification. +-- @treturn string the data home (XDG_DATA_HOME) with a slash at the end. +function filesystem.get_xdg_data_home() + return (os.getenv("XDG_DATA_HOME") or os.getenv("HOME") .. "/.local/share") .. "/" +end + +--- Get the data dirs according to the XDG basedir specification. +-- @treturn table the data dirs (XDG_DATA_DIRS) with a slash at the end of each entry. +function filesystem.get_xdg_data_dirs() + local xdg_data_dirs = os.getenv("XDG_DATA_DIRS") or "/usr/share:/usr/local/share" + return gtable.map( + function(dir) return dir .. "/" end, + gstring.split(xdg_data_dirs, ":")) +end + --- Get the path to the user's config dir. -- This is the directory containing the configuration file ("rc.lua"). -- @return A string with the requested path with a slash at the end.