I have this file called Local_Paths.txt . Its just a text file full of paths:
C:\Temp\README.md
C:\Temp\README.md
C:\Temp\object_lifetime_management.md
C:\Temp\object_reference.md
...
...
...
The paths are being logged there, in real time as I interact with folders and files, in file manager and other tools.
The purpose of this Local_Paths.txt is for a module I made in powershell. For example I can quicly call up Terminal and pipe the 5 most recent .Md files into this module.
I have the file loaded into a variable in my $Profile:
cls
$LocalPaths = Get-Content "C:\Users\...\Documents\Local_Paths.txt"
On the rare case I have to boot up Powershell, this works fine. The problem I have is that I always have a Powershell session minimised on the taskbar.
So I am constantly either . $Profile my entire profile, which is quite a heavy file. or just declaring a $LocalPaths = Get-Content "C:\Users\...\Documents\Local_Paths.txt".
This proccess just kills the purpose of my module (Less hand wringling, more automation)
I am wondering is there a way to inject powershell code into the current session through a .Ps1 script or even through the wt command?
so that when I press the hotkey to focus Powershell this script to load the txt file gets executed first.
I did go through the Windows Terminal page for the Actions command. This is still user simulation though.
I have taken the liberty to cross post this question on other forums as well. Any help or just pointing me in the right direction would appreciated.
Set-PSReadLineKeyHandler. Something like this should work for youSet-PSReadLineKeyHandler -Chord "Ctrl+j" -ScriptBlock {$Global:LocalPaths = C:\Users\...\Documents\Local_Paths.txt"}. If you add that to your profile it will be available each session and easy to quickly do anytime you need. You might want to double-check that whatever key chord you choose is not in use first usingGet-PSReadLineKeyHandler