2017-10-21 18:00:10 +00:00
|
|
|
# Change working dir in powershell to last dir in lf on exit.
|
|
|
|
#
|
|
|
|
# You need to put this file to a folder in $ENV:PATH variable.
|
2020-12-23 22:21:35 +00:00
|
|
|
#
|
|
|
|
# You may also like to assign a key to this command:
|
|
|
|
#
|
2021-04-13 20:29:26 +00:00
|
|
|
# Set-PSReadLineKeyHandler -Chord Ctrl+o -ScriptBlock {
|
|
|
|
# [Microsoft.PowerShell.PSConsoleReadLine]::RevertLine()
|
|
|
|
# [Microsoft.PowerShell.PSConsoleReadLine]::Insert('lfcd.ps1')
|
|
|
|
# [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()
|
|
|
|
# }
|
2020-12-23 22:21:35 +00:00
|
|
|
#
|
2020-12-23 23:28:25 +00:00
|
|
|
# You may put this in one of the profiles found in $PROFILE.
|
|
|
|
#
|
2017-10-21 18:00:10 +00:00
|
|
|
|
|
|
|
$tmp = [System.IO.Path]::GetTempFileName()
|
|
|
|
lf -last-dir-path="$tmp" $args
|
2021-06-19 20:41:14 +00:00
|
|
|
if (Test-Path -PathType Leaf "$tmp") {
|
|
|
|
$dir = Get-Content "$tmp"
|
|
|
|
Remove-Item -Force "$tmp"
|
|
|
|
if (Test-Path -PathType Container "$dir") {
|
2017-10-21 18:00:10 +00:00
|
|
|
if ("$dir" -ne "$pwd") {
|
|
|
|
cd "$dir"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|