decided to yeet my entire cosmic config into a home manager module and needed a script to do it. Kinda a qd solution but it works
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

yeets

MLC Bloeiman 72a757c2

+112
+4
.gitignore
··· 1 + *.beam 2 + *.ez 3 + /build 4 + erl_crash.dump
+7
README.md
··· 1 + # convert_cosmic 2 + 3 + decided to yeet my entire cosmic config into a home manager module and needed a script to do it. Kinda a qd solution but it works. yeet. 4 + 5 + ```sh 6 + gleam run 7 + ```
+20
gleam.toml
··· 1 + name = "convert_cosmic" 2 + version = "1.0.0" 3 + 4 + # Fill out these fields if you intend to generate HTML documentation or publish 5 + # your project to the Hex package manager. 6 + # 7 + # description = "" 8 + # licences = ["Apache-2.0"] 9 + # repository = { type = "github", user = "", repo = "" } 10 + # links = [{ title = "Website", href = "" }] 11 + # 12 + # For a full reference of all the available options, you can have a look at 13 + # https://gleam.run/writing-gleam/gleam-toml/. 14 + 15 + [dependencies] 16 + gleam_stdlib = ">= 0.44.0 and < 2.0.0" 17 + simplifile = ">= 2.4.0 and < 3.0.0" 18 + 19 + [dev_dependencies] 20 + gleeunit = ">= 1.0.0 and < 2.0.0"
+14
manifest.toml
··· 1 + # This file was generated by Gleam 2 + # You typically do not need to edit this file 3 + 4 + packages = [ 5 + { name = "filepath", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "B06A9AF0BF10E51401D64B98E4B627F1D2E48C154967DA7AF4D0914780A6D40A" }, 6 + { name = "gleam_stdlib", version = "0.70.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "86949BF5D1F0E4AC0AB5B06F235D8A5CC11A2DFC33BF22F752156ED61CA7D0FF" }, 7 + { name = "gleeunit", version = "1.9.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "DA9553CE58B67924B3C631F96FE3370C49EB6D6DC6B384EC4862CC4AAA718F3C" }, 8 + { name = "simplifile", version = "2.4.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "7C18AFA4FED0B4CE1FA5B0B4BAC1FA1744427054EA993565F6F3F82E5453170D" }, 9 + ] 10 + 11 + [requirements] 12 + gleam_stdlib = { version = ">= 0.44.0 and < 2.0.0" } 13 + gleeunit = { version = ">= 1.0.0 and < 2.0.0" } 14 + simplifile = { version = ">= 2.4.0 and < 3.0.0" }
+54
src/convert_cosmic.gleam
··· 1 + import gleam/io 2 + import gleam/list 3 + import gleam/result 4 + import gleam/string 5 + import simplifile 6 + 7 + pub fn main() { 8 + let assert Ok(_) = simplifile.write("./output.nix", "{ ... }: {") 9 + use modules <- result.try(simplifile.read_directory( 10 + "/home/mar/.config/cosmic", 11 + )) 12 + list.map(modules, fn(current_module) { 13 + let current_module_path = 14 + "/home/mar/.config/cosmic/" <> current_module <> "/v1/" 15 + let current_module_path_xdg_config_relative = 16 + "cosmic/" <> current_module <> "/v1/" 17 + // io.println( 18 + // "Current module:\t" 19 + // <> current_module 20 + // <> " (" 21 + // <> current_module_path_xdg_config_relative 22 + // <> ")", 23 + // ) 24 + use items <- result.try(simplifile.read_directory({ current_module_path })) 25 + 26 + list.map(items, fn(item) { 27 + simplifile.read(current_module_path <> item) 28 + |> result.map(fn(content) { 29 + let #(file_entry, file_contents) = #( 30 + "xdg.configFile.\"" 31 + <> current_module_path_xdg_config_relative 32 + <> item 33 + <> "\"", 34 + content |> string.trim(), 35 + ) 36 + 37 + // This is where the fun begins 38 + let qouted_file = case file_contents |> string.contains("\n") { 39 + True -> "''\n" <> file_contents <> "\n''" 40 + False -> "\"" <> file_contents |> string.replace("\"", "\\\"") <> "\"" 41 + } 42 + // Printie 43 + let oui = file_entry <> ".text = " <> qouted_file <> ";" 44 + io.println(oui) 45 + let assert Ok(_) = simplifile.append("./output.nix", oui <> "\n\n") 46 + }) 47 + }) 48 + 49 + Ok(Nil) 50 + }) 51 + 52 + let assert Ok(_) = simplifile.append("./output.nix", "}") 53 + Ok(Nil) 54 + }
+13
test/convert_cosmic_test.gleam
··· 1 + import gleeunit 2 + 3 + pub fn main() -> Nil { 4 + gleeunit.main() 5 + } 6 + 7 + // gleeunit test functions end in `_test` 8 + pub fn hello_world_test() { 9 + let name = "Joe" 10 + let greeting = "Hello, " <> name <> "!" 11 + 12 + assert greeting == "Hello, Joe!" 13 + }