1#!/usr/bin/env nu
2
3use std "path add"
4
5
6path add /nix/var/nix/profiles/default/bin
7
8
9def unwrap-or-else [val block] {
10 if $val == null { do $block } else { $val }
11}
12
13def get-attr-keys [attr: string] {
14 nix eval $attr --apply builtins.attrNames --json --quiet | from json
15}
16
17def main [
18 _msg?: string
19 --type (-t): string
20 --scope (-s): string
21 --skip-ci (-c)
22 ...rest
23] {
24 let msg: string = unwrap-or-else $_msg { input 'enter commit message: ' }
25
26 let types = ["feat" "build" "ci" "fix" "refactor" "chore" "style"]
27 let hosts: list<string> = (get-attr-keys ".#nixosConfigurations")
28 let users: list<string> = (get-attr-keys ".#homeConfigurations")
29 let scopes = $hosts ++ $users ++ ["qol" "treewide" "deploy" "commit" "deps"]
30
31 let ty: string = unwrap-or-else $type { $types | input list 'choose type' --fuzzy }
32 let scp: string = unwrap-or-else $scope { $scopes | input list 'choose scope' --fuzzy }
33 let skipci = if not $skip_ci { "" } else { " [skip ci]" }
34 let commit_msg = $"($ty)\(($scp)\): ($msg)($skipci)"
35 git commit -m $commit_msg ...$rest
36}