repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

Scope dev commands from Nushell

16a99c463b75e9a26b01063506fbe3fedd625ec1

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (4)

+116 / −5 text lines

niri/cfg/keybinds.kdl

Modified

+4 / −5 text lines

6 6 show-hotkey-overlay
8 8 Mod+Return hotkey-overlay-title="Open a Terminal: Wezterm" {
9 - spawn "uwsm" "app" "-s" "work.slice" "--" "wezterm" "start" "--always-new-process"
9 + spawn "uwsm" "app" "-s" "app-graphical.slice" "--" "wezterm" "start" "--always-new-process"
11 11 Mod+Space hotkey-overlay-title="Nuguland: launcher" {
12 12 spawn "uwsm" "app" "-s" "session-graphical.slice" "--" "qs" "ipc" "-c" "nuguland" "call" "nuguland" "openLauncher"
21 21 spawn "uwsm" "app" "-s" "app-graphical.slice" "--" "firefox"
23 23 Mod+A hotkey-overlay-title="Open Mail: aerc" {
24 - spawn "uwsm" "app" "-s" "work.slice" "--" "wezterm" "start" "--always-new-process" "--class" "aerc" "--" "aerc"
24 + spawn "uwsm" "app" "-s" "app-graphical.slice" "--" "wezterm" "start" "--always-new-process" "--class" "aerc" "--" "aerc"
26 26 Mod+XF86Mail hotkey-overlay-title="Open Mail: aerc" {
27 - spawn "uwsm" "app" "-s" "work.slice" "--" "wezterm" "start" "--always-new-process" "--class" "aerc" "--" "aerc"
27 + spawn "uwsm" "app" "-s" "app-graphical.slice" "--" "wezterm" "start" "--always-new-process" "--class" "aerc" "--" "aerc"
29 29 Mod+ALT+L hotkey-overlay-title="Nuguland: lock" {
30 30 spawn "uwsm" "app" "-s" "session-graphical.slice" "--" "qs" "ipc" "-c" "nuguland" "call" "nuguland" "lockRequest"
39 39 spawn "uwsm" "app" "-s" "session-graphical.slice" "--" "sh" "-c" "niri msg action focus-column-right; niri msg action move-column-to-last; niri msg action focus-window-previous"
41 41 Mod+E hotkey-overlay-title="File Manager: Yazi" {
42 - spawn "uwsm" "app" "-s" "work.slice" "--" "wezterm" "start" "--always-new-process" "--" "yazi"
42 + spawn "uwsm" "app" "-s" "app-graphical.slice" "--" "wezterm" "start" "--always-new-process" "--" "yazi"
44 44 XF86AudioRaiseVolume allow-when-locked=true {
45 45 spawn "uwsm" "app" "-s" "session-graphical.slice" "--" "qs" "ipc" "-c" "nuguland" "call" "volume" "increase"
186 186 toggle-overview

nushell/login.nu

Modified

+3 / −0 text lines

19 19 use kimi.nu
20 20 use shim.nu
21 21 use git.nu
22 +use work_scope.nu
23 24 use std/clip
24 25 use std/util "path add"
31 32 source ($nu.default-config-dir | path join 'secrets.nu')
32 33 source ($nu.default-config-dir | path join "zoxide.nu")
33 34 source ($nu.default-config-dir | path join "modules" "completion.nu")
36 +work_scope generate

nushell/modules/work_scope.nu

Added
new file mode 100644

+87 / −0 text lines

1 +const GENERATED_FILE = "zzz-work-scope.nu"
3 +def quote [value: string] {
4 + $value | to nuon
5 +}
7 +def validate-command-name [name: string] {
8 + if not ($name =~ '^[A-Za-z0-9_.+-]+$') {
9 + print -e $"work_scope refuses invalid command name: ($name)"
10 + exit 1
11 + }
14 +def existing-definitions [name: string] {
15 + let prefix = $"($name) "
16 + let commands = (
17 + scope commands
18 + | where {|cmd| $cmd.name == $name or ($cmd.name | str starts-with $prefix)}
19 + | get name
20 + )
21 + let aliases = (
22 + scope aliases
23 + | where {|alias| $alias.name == $name}
24 + | get name
25 + )
27 + {commands: $commands, aliases: $aliases}
30 +def assert-unwrapped [name: string] {
31 + validate-command-name $name
32 + let existing = (existing-definitions $name)
34 + if (($existing.commands | length) > 0) or (($existing.aliases | length) > 0) {
35 + print -e $"work_scope refuses to wrap ($name); existing Nu definitions: commands=($existing.commands | to nuon), aliases=($existing.aliases | to nuon)"
36 + exit 1
37 + }
40 +def wrapper-source [name: string, slice: string] {
41 + let quoted_name = (quote $name)
42 + let quoted_slice = (quote $slice)
44 + [
45 + "# generated by work_scope.nu; edit work_scope.nuon instead"
46 + ""
47 + "@complete external"
48 + $"def --wrapped ($quoted_name) [...args] {"
49 + $" let command = ($quoted_name)"
50 + $" let slice = ($quoted_slice)"
51 + ""
52 + ' if $nu.os-info.family == "unix" and (which systemd-run | is-not-empty) {'
53 + ' ^systemd-run --user --scope --same-dir --collect --quiet $"--slice=($slice)" $command ...$args'
54 + " } else {"
55 + " run-external $command ...$args"
56 + " }"
57 + "}"
58 + ] | str join (char nl)
61 +export def generate [] {
62 + let config_path = ($nu.default-config-dir | path join modules work_scope.nuon)
63 + if not ($config_path | path exists) {
64 + print -e $"work_scope config missing: ($config_path)"
65 + exit 1
66 + }
68 + let config = (open $config_path)
69 + let commands = ($config.commands? | default [])
70 + let slice = ($config.slice? | default "work.slice")
71 + let vendor_dir = ($nu.vendor-autoload-dirs | last)
72 + let generated_path = ($vendor_dir | path join $GENERATED_FILE)
74 + for command in $commands {
75 + assert-unwrapped $command
76 + }
78 + mkdir $vendor_dir
80 + let body = (
81 + $commands
82 + | each {|command| wrapper-source $command $slice}
83 + | str join (char nl)
84 + )
86 + $body | save --force $generated_path

nushell/modules/work_scope.nuon

Added
new file mode 100644

+22 / −0 text lines

1 +{
2 + slice: work.slice
3 + commands: [
4 + bun
5 + pi
6 + codex
7 + claude
8 + herdr
9 + topgrade
10 + mise
11 + npm
12 + cargo
13 + go
14 + zig
15 + just
16 + make
17 + mvn
18 + mvnd
19 + gradle
20 + node
21 + ]