0

My dotfiles are 99% similar between computers but there are minor tweaks that I keep for various minor settings. My plan was to discriminate using an if statement based on hostname. something that would look as follows in a shell config like bashrc or zshrc

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

I suspect that xmobar is simply a config file that is parsed with no real haskell in it. Any thoughts on how to get something similar to what I have with a shell in xmobar?

Mainly I am wanting to modify the widths and network interfaces in xmobar something like

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>"

}

I realize my syntax is wishful and likely wrong, I love xmonad but have not learned haskell syntax yet.

bertabus
  • 92
  • 2
  • 8
  • the config file of xmonad is just a piece of Haskell code, so you can get the hostname by `getEnv "HOST"` or `getHostName` in `Network` package. However I don't think this is the answer you want, so could you explain what you actually want to accomplish in xmonad's config file? – ymonad May 22 '14 at 04:41
  • I just updated with a snippet from my xmobar.hs file. I suppose the ".hs" ending should have tipped me off to it being code and not simply config but haskell syntax is very foreign to me. – bertabus May 22 '14 at 05:24
  • @bertabus I'm not sure about the recent versions of `xmobar`, but the older versions generally parsed `.xmobarrc` file. Because of that you couldn't enter comments in that file. If that is the case still now, I don't think so you can use the `if else` expression in that file. I would be happy if this is not the case in the recent versions, but I'm not sure. – Sibi May 22 '14 at 05:59

1 Answers1

1

Since xmonad.hs is a haskell file, you can use the package hostname, to find it's name:

In ghci:

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

It seems you want to have different xmobar settings for your host. One way to achieve that would be to write a function that will create a new .xmobarrc file for your given host. It's type definition will look something like this:

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

You can then call this method in the appropriate place in your xmonad.hs file using the following pattern:

main = do
 hostname <- getHostName
 createXmobarrc hostname -- produce appropriate .xmobarrc file for a given host
 -- other xmonad stuff follows here
icktoofay
  • 126,289
  • 21
  • 250
  • 231
Sibi
  • 47,472
  • 16
  • 95
  • 163