2014-05-22 32 views
0

我的點文件在計算機之間99%相似,但有一些微小的調整,我保留 各種次要設置。 我的計劃是使用基於主機名的if語句進行區分。 的東西,會是下面的殼配置類似的.bashrc或zshrc獲取xmonad/xmobar配置文件中的主機名稱

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

我懷疑xmobar僅僅是一個解析與它沒有真正的哈斯克爾配置文件。 關於如何獲得類似於我在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語法呢。

+0

xmonad的配置文件只不過是小菜一碟。的Haskell代碼,所以你可以通過'Network'包中的'getEnv「HOST」'或'getHostName'獲取主機名。但是我不認爲這是你想要的答案,那麼你能解釋一下你在xmonad的配置文件中想要完成的事情嗎? – ymonad

+0

我剛從我的xmobar.hs文件中摘錄了一段代碼。我想「.hs」的結尾應該讓我知道它是代碼而不是簡單的配置,但haskell語法對我來說非常陌生。 – bertabus

+0

@bertabus我不確定最近版本的'xmobar',但舊版本一般會解析'.xmobarrc'文件。正因爲如此,你無法在該文件中輸入評論。如果現在仍然如此,我不認爲你可以在該文件中使用'if else'表達式。如果最近的版本不是這種情況,我會很高興,但我不確定。 – Sibi

回答

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