Created
November 2, 2011 22:46
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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