Last active
June 30, 2023 09:33
-
-
Save eyalk11/0653f424f8a41a98da94a64fbf43caa2 to your computer and use it in GitHub Desktop.
Go into visited locations by fuzzy search
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Depends on FZF | |
# Remove the default cd alias | |
Remove-Alias cd | |
# Create a new cd function | |
function MyCD { | |
Set-Location @args | |
$curtime =$(Get-Date -Format "yyyy-MM-dd HH:mm:ss") | |
$dict = @{ | |
Id = "30" | |
CommandLine = "cd $(Get-Location)" | |
ExecutionStatus = "Completed" | |
StartExecutionTime = $curtime | |
EndExecutionTime = $curtime | |
Duration = "00:00:00.0389011" | |
} | |
$historyObject = New-Object -TypeName PSObject -Property $dict | |
Add-History -InputObject $historyObject | |
} | |
# Set cd to use the new function | |
Set-Alias cd MyCD | |
# Function to get history of saved locations | |
function StupidHist { | |
$historyLocation = $(Get-PSReadLineOption).HistorySavePath | |
$all = Get-Content $historyLocation | select-string -Pattern "^cd .:" | %{ echo ($_ -replace "^cd (.*)","`$1") } | Sort-Object -Unique | |
return $all | Where-Object { Test-Path $($_) } | |
} | |
# Function to change to the last visited location | |
function CdLast { | |
$location = StupidHist | FZF | |
if ($location) { | |
Set-Location $location | |
} | |
} | |
# Create an alias for CdLast | |
Set-Alias q CdLast |
Author
eyalk11
commented
Apr 21, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment