Skip to content

Instantly share code, notes, and snippets.

@eyalk11
Last active June 30, 2023 09:33
Show Gist options
  • Save eyalk11/0653f424f8a41a98da94a64fbf43caa2 to your computer and use it in GitHub Desktop.
Save eyalk11/0653f424f8a41a98da94a64fbf43caa2 to your computer and use it in GitHub Desktop.
Go into visited locations by fuzzy search
# 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
@eyalk11
Copy link
Author

eyalk11 commented Apr 21, 2023

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment