Skip to content

Instantly share code, notes, and snippets.

@manualbashing
Last active December 14, 2020 09:40
Show Gist options
  • Save manualbashing/e521490eddd8e05306bbc7a17a6c16d3 to your computer and use it in GitHub Desktop.
Save manualbashing/e521490eddd8e05306bbc7a17a6c16d3 to your computer and use it in GitHub Desktop.
Use ranger running in wsl from Windows PowerShell session
function Start-Ranger {
    
    [CmdletBinding()]
    param (
        [Parameter()]
        [string]
        $Path = $pwd.Path
    )
    try {
        $Path = [System.IO.Path]::GetFullPath($Path).TrimEnd('\')
        $wslCommand = 'ranger --choosedir=$HOME/.rangerdir $(wslpath "{0}")' -f $Path
        wsl -- eval $wslCommand
    }
    finally {
        # Navigate the local PowerShell session to the last folder that was opened in ranger.
        $lastDir = wsl -- eval 'wslpath -w $(cat $HOME/.rangerdir)'
        Set-Location $lastDir
    }
}
published: false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment