awesome WM の設定内で ホームディレクトリを指定する

awesome WM での設定ファイルは Lua で書かないといけないのですが,Lua がよくわからずホームディレクトリのパスを指定するのに ~`や `${HOME} が利用できないので /home/USER な感じでフルパスで書いていたのですが,いつもと違うアカウント名の環境に clone していろいろと動かなくなりました.
またパスを書き換えるのもなーということでちゃんと確認してみると,os.getenv(HOME) が使えそうです.

os.getenv (varname)
Returns the value of the process environment variable varname, or nil if the variable is not defined.

ということで,こんな感じで別アカウントでも動作するようになりました :)
これで /home/* だろうが /export/home/* だろうがへっちゃらです!

rc.lua
diff --git a/rc.lua b/rc.lua
index 817937a..a564559 100644
--- a/rc.lua
+++ b/rc.lua
@@ -11,6 +11,8 @@ local naughty = require("naughty")
 local menubar = require("menubar")
 local hotkeys_popup = require("awful.hotkeys_popup").widget

+local home = os.getenv("HOME")
+
 -- Load Debian menu entries
 require("debian.menu")

@@ -276,14 +278,14 @@ globalkeys = awful.util.table.join(

     -- bind PrintScrn to capture a screen
-    awful.key({                   }, "Print", function () awful.util.spawn("/home/mk/.config/awesome/bin/ss-root.sh", false)   end),
-    awful.key({ "Mod1"            }, "Print", function () awful.util.spawn("/home/mk/.config/awesome/bin/ss-window.sh", false) end),
-    awful.key({ "Shift"           }, "Print", function () awful.util.spawn("/home/mk/.config/awesome/bin/ss-area.sh", false)   end),
+    awful.key({                   }, "Print", function () awful.util.spawn(home .. "/.config/awesome/bin/ss-root.sh", false)   end),
+    awful.key({ "Mod1"            }, "Print", function () awful.util.spawn(home .. "/.config/awesome/bin/ss-window.sh", false) end),
+    awful.key({ "Shift"           }, "Print", function () awful.util.spawn(home .. "/.config/awesome/bin/ss-area.sh", false)   end),

     -- Audio Controle
環境
$ dpkg-query -W awesome*
awesome 4.2-5
awesome-doc     4.2-5
awesome-extra   2018041201
$ lsb_release -d
Description:    Debian GNU/Linux unstable (sid)
$ uname -m
x86_64

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

To respond on your own website, enter the URL of your response which should contain a link to this post's permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post's URL again. (Find out more about Webmentions.)