#!/usr/bin/env nu def main [] { let config = { output: "compile_commands.json", compiler: "gcc" src_dir: "src" flags: [ "-Isrc" ] } let path_root = ($env.PWD | path expand | str replace --all '\' '/') let sources = (glob $"($config.src_dir)/**/*.c") let compile_db = ($sources | each { |path_file| let path_file_normalized = ($path_file | str replace --all '\' '/') { arguments: [ $config.compiler, "-std=c99" "-c", ...$config.flags, $path_file_normalized, ] directory: $path_root, file: $path_file_normalized, } }) $compile_db | to json | save -f $config.output print "Done." }