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

コメントを残す

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

Your post must include a link to this post.

How does this work?
Write a response on your own website and include a link to this post. Then submit your response’s URL here. Your response may appear here after moderation. To update or remove it, edit or delete your original post and submit the same URL again. Learn more about Webmentions.