在xmonad / xmobar配置文件中获取主机名

时间:2014-05-22 04:14:37

标签: haskell xmonad

我的dotfiles在计算机之间有99%相似,但我保留了一些小调整 用于各种小设置。 我的计划是使用基于主机名的if语句进行区分。 在shell配置中看起来如下的内容,如bashrc或zshrc

if [ $(hostname) == 'host1' ]; then
# things to do differently on host1.
elif [ $(hostname) == 'host2' ]; then
# things to do differently on host2.
fi

我怀疑xmobar只是一个配置文件,解析时没有真正的haskell。 关于如何在xmobar中获得与shell相似的任何想法?

主要是我想修改xmobar中的宽度和网络接口,如

Config {
if hostname == "host1" 
then
    font = "xft:Fixed-9",
    position = Static { xpos = 0, ypos = 0, width = 1280, height = 16 },
else if hostname == "host2"
then
    font = "xft:Fixed-12",
    position = Static { xpos = 1920, ypos = 0, width = 1800, height = 16 },
lowerOnStart = True,
commands = [
    -- if here as well to switch between eth0 and wls3 
    Run Network "wls3" ["-t","Net: <rx>, <tx>","-H","200","-L","10","-h","#cc9393","-l","#709080","-n","#705050"] 10,
    Run Date "%a %b %_d %l:%M" "date" 10,
    Run Battery ["-t", "Bat: <left>%","-L","10","-H","11","-l","#CC9393","-h","#709080"] 10,
    Run StdinReader
],
sepChar = "%",
alignSep = "}{",
template = "%StdinReader% }{ %multicpu% | %memory% | %Vol% | %wls3% | %battery% |   <fc=#709080>%date%</fc>"

}

我意识到我的语法是如意,可能是错误的,我喜欢xmonad,但还没有学过haskell语法。

1 个答案:

答案 0 :(得分:1)

由于xmonad.hs是一个haskell文件,您可以使用包hostname来查找它的名称:

在ghci:

λ> import Network.HostName
λ> getHostName
Loading package hostname-1.0 ... linking ... done.
"hostname1"

您似乎希望为主机设置不同的xmobar设置。实现这一目标的一种方法是编写一个函数,为给定的主机创建一个新的.xmobarrc文件。它的类型定义如下所示:

createXmobarrc :: String -> IO ()
createXmobarrc hostname = undefined -- Write your logic

然后,您可以使用以下模式在xmonad.hs文件中的适当位置调用此方法:

main = do
 hostname <- getHostName
 createXmobarrc hostname -- produce appropriate .xmobarrc file for a given host
 -- other xmonad stuff follows here