我想在登录后如果 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
这很棒的 wiki 建议这种方式在重新加载 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 中你会发现你需要:
- 创建
~/.config/awesome/autorun.sh
并添加
#!/usr/bin/env bash
function run {
if ! pgrep -f $1 ;
then
$@&
fi
}
run
使用进程 grep 进行检查(这样您就不必重新执行该进程),并将垃圾箱直接放入后台。
告诉~/.config/awesome.rc.lua
它使用 shell(bash 或您设置的任何 shell)生成该文件。您可以这样做(文件的最后一行):
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 &