From 21fc519cd582e22bfa71d2504698390a93454bb1 Mon Sep 17 00:00:00 2001 From: Julius Riegel Date: Fri, 22 Mar 2024 11:05:39 +0100 Subject: [PATCH] Improve helix config and fix notification task spam bug --- content/config/helix/config.toml | 3 + content/config/nushell/config.nu.tmpl | 1 + content/config/nushell/scripts/ide.nu | 8 +- .../config/nushell/scripts/remoting.nu.tmpl | 100 ++++++++++++++++++ content/config/pueue/pueue.yml | 2 +- hooks/systemd.hook.lua | 13 +++ silo.config.lua | 1 + 7 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 content/config/nushell/scripts/remoting.nu.tmpl create mode 100644 hooks/systemd.hook.lua diff --git a/content/config/helix/config.toml b/content/config/helix/config.toml index fb6f8dd..e02385b 100644 --- a/content/config/helix/config.toml +++ b/content/config/helix/config.toml @@ -28,6 +28,9 @@ display-inlay-hints = true render = true rainbow = "dim" +[editor.file-picker] +hidden = false + [editor.whitespace.render] tab = "all" nbsp = "all" diff --git a/content/config/nushell/config.nu.tmpl b/content/config/nushell/config.nu.tmpl index 309cd09..bfd2091 100644 --- a/content/config/nushell/config.nu.tmpl +++ b/content/config/nushell/config.nu.tmpl @@ -470,3 +470,4 @@ use ci.nu {{/if-installed}} use ide.nu +source remoting.nu diff --git a/content/config/nushell/scripts/ide.nu b/content/config/nushell/scripts/ide.nu index d383b69..e0dcc90 100755 --- a/content/config/nushell/scripts/ide.nu +++ b/content/config/nushell/scripts/ide.nu @@ -45,6 +45,12 @@ export def floating-prompt [] { } export def last-notification [] { + let notif = open $env.NOTIFY_FILE | str trim + + if ($notif | str length) == 0 { + return + } + $env.NTFY_CHKSUM = (shasum $env.NOTIFY_FILE) if not (task group exists "notify") { @@ -55,7 +61,7 @@ export def last-notification [] { "" | save -f $env.NOTIFY_FILE } } - open $env.NOTIFY_FILE | str trim + $notif } def open-editor [path: string] { diff --git a/content/config/nushell/scripts/remoting.nu.tmpl b/content/config/nushell/scripts/remoting.nu.tmpl new file mode 100644 index 0000000..8376062 --- /dev/null +++ b/content/config/nushell/scripts/remoting.nu.tmpl @@ -0,0 +1,100 @@ +# internal function that holds the host data. We could store it in a yaml file as well but that would require nushell to read it from disk every single time +def hosts [] { + [ + {{#each cfg.ssh_hosts}} + "{{this}}" + {{/each}} + ] +} +def "nu-complete wol" [] { + hosts + |where mac != '' + |get name +} + +def "nu-complete nu" [] { + hosts + |where nu + |get name +} + +def "nu-complete hosts" [] { + hosts + |get name +} + +def "nu-complete scripts" [] { + $nu.scope.commands + |where is_custom + |get -i command +} + +# Returns ssh connection as url to be consumed by original ssh command +def get-url [ + host: record +] { + if 'ip' in ($host|columns) { + echo $"ssh://($host.username)@($host.ip):($host.port)" + } else { + echo $"ssh://($host.username)@($host.name).($host.domain):($host.port)" + } +} + +# Connect over ssh to one of predefined hosts, execute nushell commands and parse them on the host +export def ssh [ + hostname: string@"nu-complete hosts" # name of the host you want to connect to + ...args # commands you wish to run on the host +] { + let host = (hosts|where name == $hostname|get -i 0) + if ($host.nu) { + if ($args|length) > 0 { + ^ssh (get-url $host) (build-string ($args|str join ' ') '|to json -r')|from json + } else { + ^ssh (get-url $host) + } + } else { + ^ssh (get-url $host) $args + } +} + +# Connect over ssh to one of predefined hosts, execute nushell script with arguments passed from the host +export def "ssh script" [ + hostname: string@"nu-complete nu" # name of the host you want to connect to + script: string@"nu-complete scripts" # name of the script + ...args # arguments you wish to pass to the script in key=value format +] { + let span = (metadata $script).span + if $script in ($nu.scope.commands|where is_custom|get command) { + + let host = (hosts|where name == $hostname|get 0) + let full_command = (build-string (view-source $script) '; ' $script ' ' ($args|str join ' ') '|to json -r') + ^ssh (get-url $host) ($full_command)|from json + + } else { + error make { + msg: $"($script) is not a custom command, use regular ssh command instead" + label: { + text: "Not a custom command", + start: $span.start, + end: $span.end + } + } + } +} +# Turns on specified hosts using Wake on Lan +export def wake [ + ...names: string@"nu-complete wol" # list of host names to wake +] { + hosts + |where name in $names + |each {|host| + if $host.mac != '' { + echo $"Waking ($host.name)" + wakeonlan $host.mac|ignore + } else { + error make { + msg: $"($host.name) does not support Wake on Lan" + } + } + } +} diff --git a/content/config/pueue/pueue.yml b/content/config/pueue/pueue.yml index 431245a..cc39024 100644 --- a/content/config/pueue/pueue.yml +++ b/content/config/pueue/pueue.yml @@ -10,7 +10,7 @@ client: %Y-%m-%d %H:%M:%S daemon: - default_parallel_tasks: 16 + default_parallel_tasks: 4 pause_group_on_failure: false pause_all_on_failure: false callback: null diff --git a/hooks/systemd.hook.lua b/hooks/systemd.hook.lua new file mode 100644 index 0000000..12b9409 --- /dev/null +++ b/hooks/systemd.hook.lua @@ -0,0 +1,13 @@ +local utils = require 'utils' +local log = require 'log' + +local exports = {} + + +exports.after_apply_all = function() + local systemctl = utils.ext "systemctl" + systemctl {"--user","daemon-reload"} + log.info "Systemd user daemon reloaded" +end + +return exports diff --git a/silo.config.lua b/silo.config.lua index c233c20..cde279d 100644 --- a/silo.config.lua +++ b/silo.config.lua @@ -57,6 +57,7 @@ config.modules = { 'efm-langserver', 'gitlint', 'commitlint', + 'meld', }, gui = mod { 'kdePackages.breeze-icons',