ls-interactive
ls-interactive copied to clipboard
add `no-exec`/`-x` flag
Allows using lsi
to choose a file and open in your favorite CLI editor using the Enter key
see https://github.com/Araxeus/ls-interactive/tree/add-no-exec/-x-flags/scripts/cli-editor
Bash | sh | zsh
lsi() {
local output
if output=$(ls-interactive "$@" -x) && [[ $output ]]; then
if [ -f "$output" ]; then
vim "$output" # I use micro instead of vim
else
cd "$output"
fi
fi
}
Batch (Windows CMD)
@echo off
for /f "tokens=*" %%i in ('%~dp0\ls-interactive.exe -x "%*"') do set output=%%i
IF DEFINED output CALL :exec %output%
GOTO :EOF
:exec
SET file_attribute=%~a1
if "%file_attribute:~0,1%"=="d" (
cd %1
) else (
micro %1
)
PowerShell
function lsi {
$output = (ls-interactive -x "$args")
if (!$output) { return }
if (Test-Path -Path $output -PathType leaf) { micro $output }
else { Set-Location $output }
}
Fish
function lsi
set -l output
if output=(ls-interactive $argv -x); and [ -n "$output" ]
if test -f "$output"
micro "$output"
else
cd "$output"
end
end
end
Nushell
def-env lsi [...path: string] {
let output = (ls-interactive -x ($path | str join ' '))
if ($output | is-empty) { return }
if (($output | path type) == 'file') {
micro $output
} else { cd $output }
}