Improve helix config and fix notification task spam bug

main
Julius Riegel 8 months ago
parent c0d374f8ed
commit 21fc519cd5

@ -28,6 +28,9 @@ display-inlay-hints = true
render = true render = true
rainbow = "dim" rainbow = "dim"
[editor.file-picker]
hidden = false
[editor.whitespace.render] [editor.whitespace.render]
tab = "all" tab = "all"
nbsp = "all" nbsp = "all"

@ -470,3 +470,4 @@ use ci.nu
{{/if-installed}} {{/if-installed}}
use ide.nu use ide.nu
source remoting.nu

@ -45,6 +45,12 @@ export def floating-prompt [] {
} }
export def last-notification [] { 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) $env.NTFY_CHKSUM = (shasum $env.NOTIFY_FILE)
if not (task group exists "notify") { if not (task group exists "notify") {
@ -55,7 +61,7 @@ export def last-notification [] {
"" | save -f $env.NOTIFY_FILE "" | save -f $env.NOTIFY_FILE
} }
} }
open $env.NOTIFY_FILE | str trim $notif
} }
def open-editor [path: string] { def open-editor [path: string] {

@ -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"
}
}
}
}

@ -10,7 +10,7 @@ client:
%Y-%m-%d %Y-%m-%d
%H:%M:%S %H:%M:%S
daemon: daemon:
default_parallel_tasks: 16 default_parallel_tasks: 4
pause_group_on_failure: false pause_group_on_failure: false
pause_all_on_failure: false pause_all_on_failure: false
callback: null callback: null

@ -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

@ -57,6 +57,7 @@ config.modules = {
'efm-langserver', 'efm-langserver',
'gitlint', 'gitlint',
'commitlint', 'commitlint',
'meld',
}, },
gui = mod { gui = mod {
'kdePackages.breeze-icons', 'kdePackages.breeze-icons',

Loading…
Cancel
Save