Move zellij powerline to ide utils

main
Julius Riegel 8 months ago
parent c55d0b2684
commit 709e6dc3d9

@ -17,6 +17,10 @@ args = ["server", "-m", "stream"]
[language-server.typescript-language-server.config.preferences] [language-server.typescript-language-server.config.preferences]
disableSuggestions = true disableSuggestions = true
[language-server.nu-lsp]
command = "nu"
args = ["-I", "~/.config/nushell/scripts", "--lsp"]
# languages # languages
[[language]] [[language]]

@ -4,7 +4,7 @@ export def notify [] {
sleep 1sec; sleep 1sec;
}; };
let name = ($env.PWD | path basename) 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 [] { export def info [] {
if (get-ci) == "gitlab" { if (get-ci) == "gitlab" {
glab ci get -F json | from json return (glab ci get -F json | from json | {
} else { conclusion: $in.status,
(gh run list --json conclusion,name,startedAt,status | from json | first exists: true,
| { ...$in
name: $in.name, })
conclusion: $in.conclusion, } else if (get-ci) == "github" {
status: (match $in.status { 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"}, "in_progress" => {"running"},
_ => $in.status "completed" => { $info.conclusion }
_ => $info.status
}), }),
}) exists: true,
}
} }
}
({
id: null,
name: null,
status: null,
conclusion: null,
exists: false,
})
} }
# notify in background # notify in background
@ -47,6 +68,7 @@ export def watch-bg [] {
while (ci info | get status) != "running" { while (ci info | get status) != "running" {
sleep 10sec; sleep 10sec;
} }
notify-send $"CI (ci info | get id)" "Job started"
ci notify ci notify
ci watch-bg ci watch-bg
} }

@ -1,15 +1,14 @@
#!/bin/env nu #!/bin/env nu
use task.nu use task.nu
use dirs.nu use dirs.nu
use render.nu
const ZELLIJ_LAYOUT = ($dirs.CONFIG | path join zellij/development.toml) const ZELLIJ_LAYOUT = ($dirs.CONFIG | path join zellij/development.toml)
export def --env main [] { export def --env main [] {
if $env.ZELLIJ? == null { if $env.ZELLIJ? == null {
if $env.WEZTERM_PANE? != null { if $env.WEZTERM_PANE? != null {
let name = ($env.PWD | path basename) wezterm cli set-tab-title $"IDE (basename)"
wezterm cli set-tab-title $"IDE ($name)"
} }
let tmpdir = init let tmpdir = init
zellij --layout $ZELLIJ_LAYOUT --session (session-name) zellij --layout $ZELLIJ_LAYOUT --session (session-name)
@ -53,10 +52,12 @@ export def last-notification [] {
$env.NTFY_CHKSUM = (shasum $env.NOTIFY_FILE) $env.NTFY_CHKSUM = (shasum $env.NOTIFY_FILE)
if not (task group exists "notify") { let group_name = $"notify-(basename)"
task group add notify -p 4
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 { if (shasum $env.NOTIFY_FILE) == $env.NTFY_CHKSUM {
"" | save -f $env.NOTIFY_FILE "" | save -f $env.NOTIFY_FILE
} }
@ -125,3 +126,102 @@ def --env create-notify-send [tmpdir: string, tmpbin: string] {
" | save -f $new_ntfy) " | save -f $new_ntfy)
chmod +x $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
}
}
}

@ -0,0 +1,23 @@
export def powerline [
bg: string
elem: list<any>
--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 ""
)
}

@ -7,8 +7,8 @@ layout {
children children
pane size=1 borderless=true { pane size=1 borderless=true {
plugin location="https://github.com/dj95/zjstatus/releases/latest/download/zjstatus.wasm" { 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_left "{command_lpl}{tabs}"
format_right "{command_cpuusage}#[fg=cyan,bg=green]{command_memusage}#[fg=green,bg=#b1bbfa]{datetime}" format_right "{command_rpl}"
format_center "{command_notify}" format_center "{command_notify}"
format_space "#[bg=#181825]" format_space "#[bg=#181825]"
@ -21,30 +21,20 @@ layout {
tab_active_fullscreen "#[fg=#9399B2,bg=#181825,bold,italic] {index} {name} [] " tab_active_fullscreen "#[fg=#9399B2,bg=#181825,bold,italic] {index} {name} [] "
tab_active_sync "#[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_command "nu -c \"use ide.nu; ide last-notification\""
command_notify_format "{stdout}" command_notify_format "{stdout}"
command_notify_interval "1" 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 "#[fg=#181825,bg=#b1bbfa] {format} "
datetime_format "%A, %d %b %Y %H:%M" datetime_format "%A, %d %b %Y %H:%M"

Loading…
Cancel
Save