diff options
| author | spwhitton <spwhitton@web> | 2015-11-24 15:41:34 +0000 |
|---|---|---|
| committer | admin <admin@branchable.com> | 2015-11-24 15:41:34 +0000 |
| commit | 41116ba118ab1335947530963ad252b1c4184770 (patch) | |
| tree | 85e35bf7f8f8f6c4a0c8494a573735f3548dd552 /doc | |
| parent | 4773631a3854869769d23a5a696766f51322a830 (diff) | |
post propellor_lines script
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/forum/Script_to_convert_config_files_for_inclusion_in_Propellor_config.mdwn | 39 |
1 files changed, 39 insertions, 0 deletions
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). |
