|
|
|
#!/bin/env nu
|
|
|
|
|
|
|
|
def --env main [] {
|
|
|
|
if $env.ZELLIJ? == null {
|
|
|
|
let tmpdir = init
|
|
|
|
zellij --layout {{dirs.config}}/zellij/development.toml --session (session-name)
|
|
|
|
rm -r $tmpdir
|
|
|
|
} else {
|
|
|
|
zellij action new-tab --layout {{dirs.config}}/zellij/development.toml --name (tab-name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def `main 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 }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
let new_open = ($tmpbin | path join "xdg-open")
|
|
|
|
"#!/bin/bash\nnu {{dirs.data}}/scripts/ide.nu open-file $*\n" | save -f $new_open
|
|
|
|
chmod +x $new_open
|
|
|
|
$env.PATH = ($env.PATH | prepend $tmpbin)
|
|
|
|
|
|
|
|
$tmpdir
|
|
|
|
}
|