From 41116ba118ab1335947530963ad252b1c4184770 Mon Sep 17 00:00:00 2001 From: spwhitton Date: Tue, 24 Nov 2015 15:41:34 +0000 Subject: post propellor_lines script --- ...ig_files_for_inclusion_in_Propellor_config.mdwn | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 doc/forum/Script_to_convert_config_files_for_inclusion_in_Propellor_config.mdwn (limited to 'doc/forum/Script_to_convert_config_files_for_inclusion_in_Propellor_config.mdwn') diff --git a/doc/forum/Script_to_convert_config_files_for_inclusion_in_Propellor_config.mdwn b/doc/forum/Script_to_convert_config_files_for_inclusion_in_Propellor_config.mdwn new file mode 100644 index 00000000..d3c77a17 --- /dev/null +++ b/doc/forum/Script_to_convert_config_files_for_inclusion_in_Propellor_config.mdwn @@ -0,0 +1,39 @@ +This script turns + + Section "Monitor" + Identifier "Configured Monitor" + EndSection + +into this: + + [ "Section \"Monitor\"" + , "\tIdentifier \"Configured Monitor\"" + , "EndSection" + ] + +for the inclusion of short config files in your Propellor config using `File.hasContent`. + +[[!format haskell """ +#!/usr/bin/runhaskell + +main = interact $ unlines . propellorLines . lines + +propellorLines :: [String] -> [String] +propellorLines (x:xs) = ("[ " ++ wrapEscapeLine x) : propellorLines' xs + +propellorLines' :: [String] -> [String] +propellorLines' = foldr step ["]"] + where + step x xs = (", " ++ wrapEscapeLine x) : xs + +wrapEscapeLine :: String -> String +wrapEscapeLine line = "\"" ++ (foldr step "" line) ++ "\"" + where + step x xs + | x == '\t' = "\\t" ++ xs + | x == '\\' = x : x : xs + | x == '"' = '\\' : x : xs + | otherwise = x : xs +"""]] + +Usage: `cat config_file | propellor_lines` (or in Emacs, dump the config file into your propellor config, select the region and use `C-u M-|` to pipe it through). -- cgit v1.2.3