You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
258 lines
5.3 KiB
Plaintext
258 lines
5.3 KiB
Plaintext
#!/bin/env nu
|
|
use task.nu
|
|
use dirs.nu
|
|
use render.nu
|
|
use ci.nu
|
|
|
|
const ZELLIJ_LAYOUT = ($dirs.CONFIG | path join zellij/development.toml)
|
|
|
|
export def --env main [] {
|
|
if $env.ZELLIJ? == null {
|
|
if $env.WEZTERM_PANE? != null {
|
|
wezterm cli set-tab-title $"IDE (basename)"
|
|
}
|
|
let tmpdir = init
|
|
ci watch-bg
|
|
zellij --layout $ZELLIJ_LAYOUT --session (session-name)
|
|
rm -r $tmpdir
|
|
|
|
if $env.WEZTERM_PANE? != null {
|
|
wezterm cli set-tab-title ""
|
|
}
|
|
} else {
|
|
zellij action new-tab --layout $ZELLIJ_LAYOUT --name (tab-name)
|
|
}
|
|
}
|
|
|
|
|
|
export def open-file [path: string] {
|
|
if ($path | str starts-with "http") {
|
|
/usr/bin/xdg-open $path
|
|
return
|
|
}
|
|
match ($path | path parse | get extension | str downcase) {
|
|
"png" => { open-image $path }
|
|
"jpg" => { open-image $path }
|
|
"jpeg" => { open-image $path }
|
|
"webp" => { open-image $path }
|
|
_ => { open-editor $path }
|
|
}
|
|
}
|
|
|
|
export def floating-prompt [] {
|
|
task spawn -i {
|
|
zellij action new-pane --floating -- nu -c 'nu -e clear; zellij action close-pane';
|
|
}
|
|
zellij action close-pane
|
|
}
|
|
|
|
export def last-notification [] {
|
|
let notif = open $env.NOTIFY_FILE
|
|
|
|
if $notif == null {
|
|
return
|
|
}
|
|
let notif = $"(ansi {attr: bi})($notif.title)(ansi reset) ($notif.content)"
|
|
|
|
$env.NTFY_CHKSUM = (shasum $env.NOTIFY_FILE)
|
|
|
|
let group_name = $"notify-(basename)"
|
|
|
|
if not (task group exists $group_name) {
|
|
task group add $group_name -p 4
|
|
}
|
|
( task spawn -d 10sec -g $group_name {
|
|
if (shasum $env.NOTIFY_FILE) == $env.NTFY_CHKSUM {
|
|
"null" | save -f $env.NOTIFY_FILE
|
|
}
|
|
} | ignore )
|
|
|
|
return $notif
|
|
}
|
|
|
|
export def `doc-comment java-style` [] {
|
|
print `/**
|
|
*
|
|
*/`
|
|
}
|
|
|
|
export def `doc-comment rust-style` [] {
|
|
print `/// `
|
|
}
|
|
|
|
export def write-here [...chars: string] {
|
|
zellij ac write-chars ...$chars
|
|
}
|
|
|
|
def open-editor [path: string] {
|
|
zellij ac move-focus right
|
|
zellij ac write-chars $":open ($path)\r"
|
|
}
|
|
|
|
def open-image [path: string] {
|
|
zellij ac new-pane -f -- chafa -C on --scale max $path
|
|
}
|
|
|
|
def session-name [] {
|
|
let dirname = $env.PWD | path parse | get stem
|
|
let suffix = ( zellij list-sessions -s
|
|
| split row "\n"
|
|
| where $it =~ $"ide-($dirname)"
|
|
| get 0?
|
|
| default ""
|
|
| hash md5
|
|
| str substring 0..4
|
|
)
|
|
$"ide-($dirname)-($suffix)"
|
|
}
|
|
|
|
def tab-name [] {
|
|
let dirname = $env.PWD | path parse | get stem
|
|
$"Editor \(($dirname)\)"
|
|
}
|
|
|
|
def --env init [] {
|
|
let tmpdir = mktemp -d --suffix "-ide"
|
|
let tmpbin = ($tmpdir | path join "bin")
|
|
mkdir $tmpbin
|
|
$env.PATH = ($env.PATH | prepend $tmpbin)
|
|
create-xdg-open $tmpbin
|
|
create-notify-send $tmpdir $tmpbin
|
|
|
|
$tmpdir
|
|
}
|
|
|
|
def create-xdg-open [tmpbin: string] {
|
|
let new_open = ($tmpbin | path join "xdg-open")
|
|
("#!/bin/env nu
|
|
use ide.nu
|
|
def main [file: string] {
|
|
ide open-file $file
|
|
}
|
|
" | save -f $new_open)
|
|
chmod +x $new_open
|
|
}
|
|
|
|
def --env create-notify-send [tmpdir: string, tmpbin: string] {
|
|
$env.NOTIFY_FILE = ($tmpdir | path join "notifications.json")
|
|
touch $env.NOTIFY_FILE
|
|
|
|
let new_ntfy = ($tmpbin | path join "notify-send")
|
|
("#!/bin/env nu
|
|
def main [title: string, content: string] {
|
|
{title: $title, content: $content} | to json | save -f $env.NOTIFY_FILE
|
|
}
|
|
" | 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: $"(branch-name) "
|
|
icon: ""
|
|
bg: "blue"
|
|
fg: $ZELLIJ_BG
|
|
}
|
|
] | where $in != null)
|
|
render powerline $ZELLIJ_BG $elements --start ""
|
|
}
|
|
|
|
def branch-name [] {
|
|
let name = (git rev-parse --abbrev-ref HEAD)
|
|
let parts = ($name | split row "/")
|
|
|
|
if ($parts | length) > 1 {
|
|
$"(ansi {attr: i})($parts.0)/(ansi reset)(ansi {fg: $ZELLIJ_BG, bg: blue, attr: b})($parts | skip 1 | str join '/')"
|
|
} else {
|
|
$"(ansi {attr: b})($name)"
|
|
}
|
|
}
|
|
|
|
export def `zjstatus powerline_right` [] {
|
|
use ci.nu
|
|
let sys = (sys)
|
|
|
|
let elements = ([
|
|
(try { ci status } catch { null })
|
|
{
|
|
text: ($sys.cpu.cpu_usage | math avg | math round -p 2 | $"($in) % " | fill -a right -c ' ' -w 8)
|
|
icon: ""
|
|
bg: "cyan"
|
|
fg: $ZELLIJ_BG
|
|
}
|
|
{
|
|
text: ($"($sys.mem.used) " | fill -a right -c ' ' -w 8)
|
|
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 --separator "" --start "" --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
|
|
}
|
|
}
|
|
}
|