Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add no-exec/-x flag #57

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

add no-exec/-x flag #57

wants to merge 2 commits into from

Conversation

Araxeus
Copy link
Owner

@Araxeus Araxeus commented Apr 15, 2023

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 }
}

@Araxeus Araxeus force-pushed the add-no-exec/-x-flags branch from 8989616 to 7eb07b4 Compare April 16, 2023 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant