summaryrefslogtreecommitdiff
path: root/HostName.hs
blob: 2cc50ea92af106a061b45c6353a5d72ef83ad23e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
module HostName where

import Control.Applicative
import System.Environment

import Utility.Process

type HostName = String

getHostName :: IO HostName
getHostName = go =<< getArgs
  where
	go (h:_) = return h
	go [] = do
		s <- takeWhile (/= '\n') <$> readProcess "hostname" ["-f"]
		if null s
			then error "Cannot determine hostname! Pass it on the command line."
			else return s