Skip to content

Instantly share code, notes, and snippets.

@KirinDave
Created November 2, 2011 22:46
Show Gist options
  • Save KirinDave/1335188 to your computer and use it in GitHub Desktop.
Save KirinDave/1335188 to your computer and use it in GitHub Desktop.
A quick script to read my knife file (if it exists) and output some data for my zshrc
import System.IO
import System.Environment
import Data.List
import Data.Maybe
import Control.Applicative
import HSH
isQuote x = x == '"' || x == '\''
isntQuote = not . isQuote
lineWith = find . isInfixOf
fileLines floc = do
cH <- openFile floc ReadMode
lines `fmap` hGetContents cH
knifeLines = do
g <- (glob "~/.chef/knife.rb")
case g of
a:_ -> fileLines a
_ -> return []
getQuotedValue string =
takeWhile isntQuote start
where start = drop 1 $ dropWhile isntQuote string
userString user env = user ++ "@" ++ env
main = do
kl <- knifeLines
let klWith = flip lineWith $ kl
qname = getQuotedValue `fmap` klWith "node_name"
qenv = getQuotedValue `fmap` klWith "builder_cluster"
name = userString <$> qname <*> qenv in
putStrLn $ fromMaybe "none" name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment