diff --git a/content/config/helix/languages.toml b/content/config/helix/languages.toml index d894371..6995f8f 100644 --- a/content/config/helix/languages.toml +++ b/content/config/helix/languages.toml @@ -17,6 +17,10 @@ args = ["server", "-m", "stream"] [language-server.typescript-language-server.config.preferences] disableSuggestions = true +[language-server.nu-lsp] +command = "nu" +args = ["-I", "~/.config/nushell/scripts", "--lsp"] + # languages [[language]] diff --git a/content/config/nushell/scripts/ci.nu b/content/config/nushell/scripts/ci.nu index 23c9137..344171d 100644 --- a/content/config/nushell/scripts/ci.nu +++ b/content/config/nushell/scripts/ci.nu @@ -4,7 +4,7 @@ export def notify [] { sleep 1sec; }; let name = ($env.PWD | path basename) - notify-send $"CI ($name)" "Job completed" + notify-send $"CI ($name)" $"Job (info | get conclusion)" } @@ -19,18 +19,39 @@ export def watch [] { export def info [] { if (get-ci) == "gitlab" { - glab ci get -F json | from json - } else { - (gh run list --json conclusion,name,startedAt,status | from json | first - | { - name: $in.name, - conclusion: $in.conclusion, - status: (match $in.status { - "in_progress" => {"running"}, - _ => $in.status - }), + return (glab ci get -F json | from json | { + conclusion: $in.status, + exists: true, + ...$in }) + } else if (get-ci) == "github" { + use git.nu + let branch = (git gb | where current == true | first | get branch) + let info = (gh run list --json conclusion,name,startedAt,status,number,headBranch | from json | where headBranch == $branch | get -i 0 ) + + if $info != null { + return { + id: $info.number, + name: $info.name, + conclusion: $info.conclusion, + status: (match $info.status { + "in_progress" => {"running"}, + "completed" => { $info.conclusion } + _ => $info.status + }), + exists: true, + } + } } + + ({ + id: null, + name: null, + status: null, + conclusion: null, + exists: false, + }) + } # notify in background @@ -47,6 +68,7 @@ export def watch-bg [] { while (ci info | get status) != "running" { sleep 10sec; } + notify-send $"CI (ci info | get id)" "Job started" ci notify ci watch-bg } diff --git a/content/config/nushell/scripts/ide.nu b/content/config/nushell/scripts/ide.nu index 9ce8f56..24bb7fd 100755 --- a/content/config/nushell/scripts/ide.nu +++ b/content/config/nushell/scripts/ide.nu @@ -1,15 +1,14 @@ #!/bin/env nu - use task.nu use dirs.nu +use render.nu const ZELLIJ_LAYOUT = ($dirs.CONFIG | path join zellij/development.toml) export def --env main [] { if $env.ZELLIJ? == null { if $env.WEZTERM_PANE? != null { - let name = ($env.PWD | path basename) - wezterm cli set-tab-title $"IDE ($name)" + wezterm cli set-tab-title $"IDE (basename)" } let tmpdir = init zellij --layout $ZELLIJ_LAYOUT --session (session-name) @@ -53,10 +52,12 @@ export def last-notification [] { $env.NTFY_CHKSUM = (shasum $env.NOTIFY_FILE) - if not (task group exists "notify") { - task group add notify -p 4 + let group_name = $"notify-(basename)" + + if not (task group exists $group_name) { + task group add $group_name -p 4 } - task spawn -d 10sec -g notify { + task spawn -d 10sec -g $group_name { if (shasum $env.NOTIFY_FILE) == $env.NTFY_CHKSUM { "" | save -f $env.NOTIFY_FILE } @@ -125,3 +126,102 @@ def --env create-notify-send [tmpdir: string, tmpbin: string] { " | save -f $new_ntfy) chmod +x $new_ntfy } + +def basename [] { + $env.PWD | path basename +} + + +const ZELLIJ_BG = "#181825" + +export def `zjstatus powerline_left` [] { + use ci.nu + + let elements = ([ + { + text: $"($env.PWD | path relative-to $env.HOME) " + icon: " " + bg: "#4b0082" + fg: "#ffffff" + } + { + text: $"(git rev-parse --abbrev-ref HEAD) " + icon: "" + bg: "blue" + fg: $ZELLIJ_BG + } + ] | where $in != null) + render powerline $ZELLIJ_BG $elements --start "" +} + +export def `zjstatus powerline_right` [] { + use ci.nu + let sys = (sys) + + let elements = ([ + (ci status) + { + text: ($sys.cpu.cpu_usage | math avg | math round -p 2 | $"($in) % ") + icon: "" + bg: "cyan" + fg: $ZELLIJ_BG + } + { + text: $"($sys.mem.used) " + icon: "" + bg: "green" + fg: $ZELLIJ_BG + } + { + text: (date now | format date "%A, %d.%m.%y %H:%M ") + icon: "" + bg: "#b1bbfa" + fg: $ZELLIJ_BG + } + ] | where $it != null) + render powerline $ZELLIJ_BG $elements --end "" +} + +def `ci status` [] { + use ci.nu + let info = (ci info) + + if $info == null or not $info.exists { + return null + } + let icon = "" + + match (ci info | get status) { + "running" => { + { + fg: $ZELLIJ_BG + bg: '#ffaa00' + icon: $icon + } + }, + "skipped" => { + { + fg: $ZELLIJ_BG + bg: 'grey' + icon: $icon + } + }, + "failed" => { + { + fg: $ZELLIJ_BG + bg: '#ff0000' + icon: $icon + } + }, + "success" => { + { + fg: $ZELLIJ_BG + bg: 'green' + icon: $icon + } + }, + _ => { + null + } + } +} diff --git a/content/config/nushell/scripts/render.nu b/content/config/nushell/scripts/render.nu new file mode 100644 index 0000000..f49caaf --- /dev/null +++ b/content/config/nushell/scripts/render.nu @@ -0,0 +1,23 @@ +export def powerline [ + bg: string + elem: list + --separator = '' + --start = '' + --end = '' +] { + if ($elem | is-empty) { + return + } + let first = ($elem | first) + let last = ($elem | last) + + ($elem + | window 2 + | each {|it| + $"(ansi {fg: $it.0.fg, bg: $it.0.bg})($it.0.icon? | default '') ($it.0.text? | default '')(ansi {fg: $it.0.bg, bg: $it.1.bg})($separator)" + } + | append $"(ansi {fg: $last.fg, bg: $last.bg})($last.icon? | default '') ($last.text? | default '')(ansi {fg: $last.bg, bg: $bg})($end)(ansi reset)" + | prepend $"(ansi {fg: $bg, bg: $first.bg})($start)" + | str join "" + ) +} diff --git a/content/config/zellij/development.kdl.tmpl b/content/config/zellij/development.kdl.tmpl index 496d3c2..323df81 100644 --- a/content/config/zellij/development.kdl.tmpl +++ b/content/config/zellij/development.kdl.tmpl @@ -7,8 +7,8 @@ layout { children pane size=1 borderless=true { plugin location="https://github.com/dj95/zjstatus/releases/latest/download/zjstatus.wasm" { - format_left "{mode}#[fg=#181825,bg=#4b0082]{command_pwd}#[fg=#4b0082,bg=blue]{command_git_branch}#[fg=blue,bg=#181825]{tabs}" - format_right "{command_cpuusage}#[fg=cyan,bg=green]{command_memusage}#[fg=green,bg=#b1bbfa]{datetime}" + format_left "{command_lpl}{tabs}" + format_right "{command_rpl}" format_center "{command_notify}" format_space "#[bg=#181825]" @@ -21,30 +21,20 @@ layout { tab_active_fullscreen "#[fg=#9399B2,bg=#181825,bold,italic] {index} {name} [] " tab_active_sync "#[fg=#9399B2,bg=#181825,bold,italic] {index} {name} <> " - command_git_branch_command "git rev-parse --abbrev-ref HEAD" - command_git_branch_format "#[fg=#181825,bg=blue] {stdout} " - command_git_branch_interval "10" - command_git_branch_rendermode "static" - - command_pwd_command "nu -c '$env.PWD | path relative-to $env.HOME'" - command_pwd_format "#[fg=#ffffff,bg=#4b0082] {stdout} " - command_pwd_interval "1" - command_pwd_rendermode "static" - - command_cpuusage_command "nu -c 'sys | get cpu | get cpu_usage | math avg | math round -p 2 | $\"($in) %\"'" - command_cpuusage_format "#[fg=#181825,bg=cyan] {stdout} " - command_cpuusage_interval "10" - command_cpuusage_rendermode "static" - - command_memusage_command "nu -c 'sys | get mem.used'" - command_memusage_format "#[fg=#181825,bg=green] {stdout} " - command_memusage_interval "10" - command_memusage_rendermode "static" - command_notify_command "nu -c \"use ide.nu; ide last-notification\"" command_notify_format "{stdout}" command_notify_interval "1" - command_notify_rendermode "static" + command_notify_rendermode "raw" + + command_lpl_command "nu -c \"use ide.nu; ide zjstatus powerline_left\"" + command_lpl_format "{stdout}" + command_lpl_interval "1" + command_lpl_rendermode "raw" + + command_rpl_command "nu -c \"use ide.nu; ide zjstatus powerline_right\"" + command_rpl_format "{stdout}" + command_rpl_interval "1" + command_rpl_rendermode "raw" datetime "#[fg=#181825,bg=#b1bbfa] {format} " datetime_format "%A, %d %b %Y %H:%M"