-
-
Notifications
You must be signed in to change notification settings - Fork 100
/
hey
executable file
·88 lines (85 loc) · 3.77 KB
/
hey
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env janet
# A helper for common NixOS operations.
#
# I envy the user story for Guix's CLI; Nix's does not spark joy, in my humble
# opinion. This script exists to abstract my more common NixOS workflows, like
# rebuilding (nixos-rebuild), cleaning up (nix-collect-garbage), managing the
# system profile (rollback or diffing), updating flakes, and dotfile management
# (and then some).
#
# SYNOPSIS:
# hey [-?|-??|-???|-!] [-h|--help] COMMAND [ARGS...]
#
# OPTIONS:
# -! -- Do a dry run. WARNING: It's up to called scripts to obey!
# -?,-??,-??? -- Enable debug (verbose) mode.
# -h,--help -- Display the documentation embedded in a target script's
# header.
#
# COMMANDS:
# - build|b -- Build nix images or recompile bin/hey
# - exec -- Dispatch to $DOTFILES_HOME/{,hosts/$HOST,config/$WM}/bin/shim.d $PATH
# - get|set -- Alias for hey vars {get,set} ...
# - gc -- Run garbage collection on the user's/system's profile
# - help|h -- Display documentation for the command
# - hook -- Trigger scripts associated with an event
# - host -- Dispatch to $DOTFILES_HOME/hosts/$HOST/bin
# - info -- Display information about current system (JSON)
# - path -- Display path to area of my dotfiles
# - profile -- Manage or analyze a system or user nix profile
# - pull -- Update flake inputs
# - reload -- Run reload hooks
# - repl -- Open a Janet, Nix, or nix-develop REPL
# - swap -- Swap nix-store symlinks with copies (and back)
# - sync|s -- Rebuild this flake (using nixos-rebuild)
# - test -- Run Hey and/or Nix test suites
# - which -- Print out the script's path (with arguments) w/o executing it
# - wm -- Dispatch to $DOTFILES_HOME/config/$WM/bin
# - vars -- Get or set session or persistent state in userspace.
# - @* -- Dispatch to $DOTFILES_HOME/config/${1#@}/bin
# - .* -- Tries to be smart. Looks for any executable under host, wm,
# then $DOTFILES_HOME/bin.
(use hey)
(use hey/cmd)
(import ./hey.d/build)
(import ./hey.d/gc)
(import ./hey.d/hook)
(import ./hey.d/info)
(import ./hey.d/ops)
(import ./hey.d/path)
(import ./hey.d/profile)
(import ./hey.d/pull)
(import ./hey.d/reload)
(import ./hey.d/repl)
(import ./hey.d/swap)
(import ./hey.d/sync)
(import ./hey.d/vars)
(defn main [_ & args]
(dispatch [[:build :b] (cmd 'build)
[:get :set] |[:eval (cmd 'vars) ;$&]
:gc (cmd 'gc)
:hook (cmd 'hook)
:host |[:exec (path (keyword $0) "bin") ;$&]
:info (cmd 'info)
:ops (cmd 'ops)
:path (cmd 'path)
[:profile :pr] (cmd 'profile)
:pull (cmd 'pull)
[:reload :re] (cmd 'reload)
:repl (cmd 'repl)
[:swap :sw] (cmd 'swap)
[:sync :s] (cmd 'sync)
:test |[:exec "judge" (path :home "test/hey") ;(slice $& 1)]
:theme |[:exec (path (keyword $0) "bin") ;$&]
:vars (cmd 'vars)
:wm |[:exec (path (keyword $0) "bin") ;$&]
:exec |[:exec (or (path/find $1)
(abort "%s: command not found" $1))
;$&]
'(+ "./" "/") |[:exec ;$&]
'(* ".") |[:exec ;(resolve [(path :host "bin")
(path :wm "bin")
(path :bin)]
(slice $0 1) ;$&)]
'(* "@") |[:exec (path :config (slice $0 1) :bin) ;$&]]
;args))