repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

Generate Nushell integrations into vendor autoload

4b63d5a7abdff732d7ca29ff0e8a520c65b0e31b

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (6)

nushell/.gitignore

Modified
1 1 aliases.nu
2 -autoload/20-aliases.nu
3 2 carapace.nu
4 3 history.*
5 4 plugin.nu

nushell/autoload/30-completion.nu

Deleted
deleted file mode 100644
1 -source ($nu.default-config-dir | path join modules completion.nu)

nushell/gen-aliases.nu

Modified
1 1 # create file initially, so that we can append to it later
2 -let file = ($nu.default-config-dir | path join autoload "20-aliases.nu")
2 +let file = (($nu.vendor-autoload-dirs | last) | path join "20-aliases.nu")
3 3 mkdir ($file | path dirname)
4 4 '' | save -f $file

nushell/login.nu

Modified
36 -let zoxide_config_path = ($nu.default-config-dir | path join "zoxide.nu")
37 -if not (which zoxide | is-empty) {
38 - do $save_if_changed $zoxide_config_path (zoxide init nushell)
39 -} else {
40 - do $save_if_changed $zoxide_config_path ""
41 -}
43 36 let vendor_dir = ($nu.vendor-autoload-dirs | last)
44 37 mkdir $vendor_dir
39 +if not (which zoxide | is-empty) {
40 + do $save_if_changed ($vendor_dir | path join "zoxide.nu") (zoxide init nushell)
43 +if not (which carapace | is-empty) {
44 + let carapace_raw = (^carapace _carapace nushell)
45 + let carapace_config = (
46 + $carapace_raw
47 + | str replace " carapace $spans.0 nushell ...$spans\n | from json" ' let result = (do --ignore-errors {
48 + carapace $spans.0 nushell ...$spans | from json
49 + })
51 + if ($result | is-empty) {
52 + let current = ($spans | last | default "")
53 + if ($current | str starts-with "-") { [] } else { null }
54 + } else {
55 + $result
56 + }'
57 + )
58 + if $carapace_raw == $carapace_config {
59 + print -e "failed to patch generated carapace nushell completer"
60 + exit 1
61 + }
62 + do $save_if_changed ($vendor_dir | path join "carapace.nu") $carapace_config
46 65 if not (which mise | is-empty) {
47 66 let mise_config = (
48 67 ^mise activate nu
59 78 source ($nu.default-config-dir | path join 'secrets.nu')
60 -source ($nu.default-config-dir | path join "zoxide.nu")
62 80 work_scope generate

nushell/modules/completion.nu

Deleted
deleted file mode 100644
1 -# Interactive completion setup.
2 -# Carapace is wrapped so empty results fall back to Nushell path completion.
4 -# Helpers expected by some Carapace env-aware completions.
5 -def --env get-env [name: string] { $env | get -o $name }
6 -def --env set-env [name: string, value: any] { load-env { $name: $value } }
7 -def --env unset-env [name: string] { hide-env $name }
9 -let carapace_completer = {|spans: list<string>|
10 - load-env {
11 - CARAPACE_SHELL_BUILTINS: (help commands | where category != "" | get name | each { split row " " | first } | uniq | str join "\n")
12 - CARAPACE_SHELL_FUNCTIONS: (help commands | where category == "" | get name | each { split row " " | first } | uniq | str join "\n")
13 - }
15 - let expanded_alias = (scope aliases | where name == $spans.0 | get -o 0.expansion)
16 - let spans = if $expanded_alias != null {
17 - $spans | skip 1 | prepend ($expanded_alias | split row " " | take 1)
18 - } else {
19 - $spans
20 - }
22 - let result = (do --ignore-errors {
23 - ^carapace $spans.0 nushell ...$spans | from json
24 - })
26 - if ($result | is-empty) {
27 - let current = ($spans | last | default "")
28 - if ($current | str starts-with "-") { [] } else { null }
29 - } else {
30 - $result
31 - }
32 -}
34 -let external = ($env.config.completions.external? | default {})
35 -$env.config.completions.external = ($external | merge {
36 - enable: true
37 - completer: $carapace_completer
38 -})

nushell/modules/work_scope.nu

Modified
58 58 ] | str join (char nl)
61 +def save-if-changed [path: path, content: string] {
62 + if (not ($path | path exists)) or ((open --raw $path) != $content) {
63 + $content | save --force $path
64 + }
61 67 export def generate [] {
62 68 let config_path = ($nu.default-config-dir | path join modules work_scope.nuon)
63 69 if not ($config_path | path exists) {
83 89 | str join (char nl)
86 - $body | save --force $generated_path
92 + save-if-changed $generated_path $body