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
Modified2 -autoload/20-aliases.nu nushell/autoload/30-completion.nu
Deleteddeleted file mode 1006441 -source (
$nu.default-config-dir | path join modules completion.nu)
nushell/gen-aliases.nu
Modified 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)
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)
40 - do $save_if_changed $zoxide_config_path "" 43 36 let vendor_dir = (
$nu.vendor-autoload-dirs | last)
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 = (
47 + | str replace
" carapace $spans.0 nushell ...$spans\n | from json" '
let result = (
do --ignore-errors {
48 + carapace
$spans.0 nushell ...
$spans | from json
51 + if (
$result | is-empty) {
52 + let current = (
$spans | last | default
"")
53 + if (
$current | str starts-with
"-") { [] }
else { null }
58 + if $carapace_raw ==
$carapace_config {
59 + print -e
"failed to patch generated carapace nushell completer" 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 = (
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
Deleteddeleted file mode 100644 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>|
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")
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)
22 - let result = (
do --ignore-errors {
23 - ^carapace
$spans.0 nushell ...
$spans | from json
26 - if (
$result | is-empty) {
27 - let current = (
$spans | last | default
"")
28 - if (
$current | str starts-with
"-") { [] }
else { null }
34 -let external = (
$env.config.completions.external? | default {})
35 -$env.config.completions.external = (
$external | merge {
37 - completer:
$carapace_completer nushell/modules/work_scope.nu
Modified58 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 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