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.

47 lines
1.1 KiB
Cheetah

11 months ago
#!/bin/env nu
def main [] {
if $env.ZELLIJ? == null {
zellij --layout {{dirs.config}}/zellij/development.toml --session (session-name)
} else {
zellij action new-tab --layout {{dirs.config}}/zellij/development.toml --name (tab-name)
}
11 months ago
}
def `main open-file` [path: string] {
match ($path | path parse | get extension | str downcase) {
"png" => { open-image $path }
"jpg" => { open-image $path }
"jpeg" => { open-image $path }
"webp" => { open-image $path }
11 months ago
_ => { 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)\)"
}