Permalink
Browse files

Convenient way to label sections

  • Loading branch information...
1 parent 2a6b2e8 commit 3bdf99d096ac94b36621172a4c5f49690b00d550 @samstokes committed Jun 18, 2011
Showing with 20 additions and 1 deletion.
  1. +20 −1 SSH/Config.hs
View
@@ -4,6 +4,9 @@ module SSH.Config
, HostOption(..)
, alias
, hostName
+ , label
+ , user
+ , port
, parser
)
where
@@ -12,7 +15,7 @@ import Control.Applicative hiding(many, (<|>))
import Control.Monad (ap)
import Data.List (find)
import Data.Maybe
-import Text.ParserCombinators.Parsec hiding(space)
+import Text.ParserCombinators.Parsec hiding(space, label)
{- REPRESENTATION -}
@@ -37,6 +40,22 @@ alias = head . names
hostName :: Section -> String
hostName section = fromMaybe (alias section) $ lookup "HostName" (options section)
+label :: Section -> String
+label section = if friendly == detail
+ then friendly
+ else friendly ++ " (" ++ detail ++ ")"
+ where
+ friendly = alias section
+ detail = userPart ++ hostName section ++ portPart
+ userPart = maybe "" (++ "@") $ user section
+ portPart = maybe "" (":" ++) $ port section
+
+user :: Section -> Maybe String
+user = lookup "User" . options
+
+port :: Section -> Maybe String
+port = lookup "Port" . options
+
{- PARSER -}

0 comments on commit 3bdf99d

Please sign in to comment.