use primitives/io/interface.nu [_ansi _print show_clip_to] use primitives/infra/init.nu [show_titles] export def run_on_selection [ select: string name: string item_path: string main_path: string root_path: string ] { if not ($item_path | path exists) { return } match $select { "edit" | "editor" | "ed" | "e" => { let cmd = ($env | get EDITOR? | default "vi") let full_cmd = $"($cmd) ($main_path)" ^($cmd) $main_path show_clip_to $full_cmd true }, "view" | "vw" | "v" => { let cmd = ($env | get PROVISIONING_FILEVIEWER? | default (if (^bash -c "type -P bat" | is-not-empty) { "bat" } else { "cat" })) let full_cmd = $"($cmd) ($main_path)" ^($cmd) $main_path show_clip_to $full_cmd true }, "list" | "ls" | "l" => { let full_cmd = $"ls -l ($item_path)" print (ls $item_path | each {|it| { name: ($it.name | str replace $root_path ""), type: $it.type, size: $it.size, modified: $it.modified }}) show_clip_to $full_cmd true }, "tree" | "tr" | "t" => { let full_cmd = $"tree -L 3 ($item_path)" ^tree -L 3 $item_path show_clip_to $full_cmd true }, "code" | "c" => { let full_cmd = $"code ($item_path)" ^code $item_path show_clip_to $full_cmd true }, "shell" | "sh" | "s" => { let full_cmd = $"($env.SHELL) -c " + $"cd ($item_path) ; ($env.SHELL)" print $"(_ansi default_dimmed)Use [ctrl-d] or 'exit' to end with(_ansi reset) ($env.SHELL)" ^($env.SHELL) -c $"cd ($item_path) ; ($env.SHELL)" show_titles _print "Command " (show_clip_to $full_cmd false) }, "nu"| "n" => { let full_cmd = $"($env.NU) -i -e " + $"cd ($item_path)" _print $"(_ansi default_dimmed)Use [ctrl-d] or 'exit' to end with(_ansi reset) nushell\n" ^($env.NU) -i -e $"cd ($item_path)" show_titles _print "Command " (show_clip_to $full_cmd false) }, "" => { _print $"($name): ($item_path)" show_clip_to $item_path false }, _ => { _print $"($select) ($name): ($item_path)" show_clip_to $item_path false } } }