awesome で起動時にコマンドを実行するにはどうすればいいですか?

awesome で起動時にコマンドを実行するにはどうすればいいですか?

awesome-windowmanager が起動したら、ログイン後にいくつかのコマンドを実行したいです。 awesome-config に起動コマンドを追加するにはどうすればいいですか?

答え1

これによればArchLinux ウィキ以下の内容を に追加するだけですrc.lua:

-- Autorun programs
autorun = true
autorunApps = 
{ 
   "swiftfox",
   "mutt",
   "consonance",
   "linux-fetion",
   "weechat-curses",
}
if autorun then
   for app = 1, #autorunApps do
       awful.util.spawn(autorunApps[app])
   end
end

ウィキでは、同じ効果を実現する他の方法もいくつか紹介されています。

答え2

私は一緒に行きますデックス、 これまでのところ。

$ cat /etc/X11/Sessions/awesome 
#!/bin/sh
# Awesome Xsession starter, based on Xsession shipped by x11-apps/xinit-1.0.5-r1
...
zenity --title "Autostart" --timeout=30 --question --text="Launch autostart items?" && dex -a
exec ck-launch-session /usr/bin/awesome

自動起動アイテムもいくつか用意しましょう:

$ ls -1 ~/.config/autostart/
gol.desktop
KeePass 2.desktop
skype-skype.desktop
tomboy.desktop
wpa_gui-wpa_supplicant.desktop
xterm-logs.desktop

自動起動項目の例:

$ cat ~/.config/autostart/gol.desktop 

[Desktop Entry]
Type=Application
Terminal=false
Name=Growl For Linux
Comment=Growl Desktop Notification System For Linux
Categories=GNOME;GTK;Utility;
Exec=/usr/bin/gol
Icon=/usr/share/growl-for-linux/data/icon.png
X-GNOME-Autostart-enabled=true
X-KDE-autostart-after=panel
X-Desktop-File-Install-Version=0.18

答え3

素晴らしいウィキが提案するこの方法は、Awesome をリロードするときに機能します。

これをrunonce.luaに書き込む

-- @author Peter J. Kranz (Absurd-Mind, [email protected])
-- Any questions, criticism or praise just drop me an email

local M = {}

-- get the current Pid of awesome
local function getCurrentPid()
    -- get awesome pid from pgrep
    local fpid = io.popen("pgrep -u " .. os.getenv("USER") .. " -o awesome")
    local pid = fpid:read("*n")
    fpid:close()

    -- sanity check
    if pid == nil then
        return -1
    end

    return pid
end

local function getOldPid(filename)
    -- open file
    local pidFile = io.open(filename)
    if pidFile == nil then
        return -1
    end

    -- read number
    local pid = pidFile:read("*n")
    pidFile:close()

    -- sanity check
    if pid <= 0 then
        return -1
    end

    return pid;
end

local function writePid(filename, pid)
    local pidFile = io.open(filename, "w+")
    pidFile:write(pid)
    pidFile:close()
end

local function shallExecute(oldPid, newPid)
    -- simple check if equivalent
    if oldPid == newPid then
        return false
    end

    return true
end

local function getPidFile()
    local host = io.lines("/proc/sys/kernel/hostname")()
    return awful.util.getdir("cache") .. "/awesome." .. host .. ".pid"
end

-- run Once per real awesome start (config reload works)
-- does not cover "pkill awesome && awesome"
function M.run(shellCommand)
    -- check and Execute
    if shallExecute(M.oldPid, M.currentPid) then
        awful.util.spawn_with_shell(shellCommand)
    end
end

M.pidFile = getPidFile()
M.oldPid = getOldPid(M.pidFile)
M.currentPid = getCurrentPid()
writePid(M.pidFile, M.currentPid)

return M

次のように使用します:

local r = require("runonce")

r.run("urxvtd -q -o -f")
r.run("urxvtc")
r.run("urxvtc")
r.run("wmname LG3D")

答え4

ArchWiki アプローチ

新しいユーザーの場合、ArchWiki で次のことが必要であることがわかります。

  1. 作成~/.config/awesome/autorun.shして追加する
#!/usr/bin/env bash
function run {
  if ! pgrep -f $1 ;
  then
    $@&
  fi
}

runプロセス grep でチェックし (プロセスを再実行しないようにする)、ビンを直接バックグラウンドに配置します。

~/.config/awesome.rc.luaシェル (bash または設定したシェル) を使用してそのファイルを生成するように指示します。次のようにします (ファイルの最後の行) :

awful.spawn.with_shell("~/.config/awesome/autorun.sh")

よりシンプルなアプローチ

さて、私にとっては、引数が多いと pgrep が少々扱いづらくなりました。そこで、少なくとも私の用途には適した、よりシンプルなスクリプトを作成しました。これが私のスクリプトですautorun.sh

#!/usr/bin/env bash

feh --bg-scale $(ls ${HOME}/wallpaper/*.png|shuf -n1) &
nm-applet &

関連情報