It probably comes as no surprise that I write a lot of PowerShell code. Like you, I'm usually working on several projects at the same time, most often using the PowerShell ISE. When I fire up the PowerShell ISE I often go to most recently edited files and re-open the files I was last working on. But sometimes my list of current projects gets pushed aside by other files I might open and edit. Because I like to be lazy (I mean efficient) I decided to come up with a solution to make it easy to open files I'm actively developing.
ManageEngine ADManager Plus - Download Free Trial
Exclusive offer on ADManager Plus for US and UK regions. Claim now!
In the PowerShell ISE you can easily load a file into the editor with the PSEDIT command.
Psedit $profile
So all I need is a way to store my active files. It is simple enough to use a text file. All the text file needs is a list of full file paths. Opening all the files can be as easy as this:
psedit (get-content .\currentWork.txt)
But how can I easily add a file to the list? I can use the PSISE object model to get the path for the currently active script file and add it to the file.
$psise.CurrentFile.FullPath | Out-File -FilePath .\currentwork.txt -Encoding ascii -Append
To remove a file from the list, it is probably easiest to simply open the current work list using PSEDIT and manually delete what I no longer need. I took these core commands and wrapped them in a set of functions. And of course, I don't want to have to type any more than I have to so it would be handy to add some shortcuts to the ISE Add-On menu.
$work.submenus.Add("Add current file to work",{Add-CurrentProject -List $currentProjectList},"CTRL+Alt+A") | Out-Null
$work.submenus.Add("Edit current work file",{Edit-CurrentProject -List $currentProjectList},"CTRL+Alt+E") | Out-Null
$work.submenus.Add("Open current work files",{Import-CurrentProject -List $currentProjectList},"CTRL+Alt+I") | Out-Null
I ended up creating a set of functions for these key operations and incorporated them into my ISE Scripting Geek module. The module exports a global variable for my work list.
$CurrentProjectList = Join-Path -Path $env:USERPROFILE\Documents\WindowsPowerShell -ChildPath "currentWork.txt"
Now when I open the ISE I can press Ctrl+Alt+I and have immediate access to everything I'm currently working on. This has already saved me a lot of time and frustration.
I have moved the ISE Scripting Geek module to GitHub so check it out here. Feel free to pick and choose what you want from the module or take my commands here and create your own solution for loading your active work files. The functions for this particular feature are in CurrentProjects.ps1.
Enjoy and let me know if this starts saving you some time.
This is awesome. Thanks. I usually have ps1 files all over the place in some state of incomplete. This will help. And it wouldn’t hurt to get a little more ruthless with stuff I know is junk.
This is exactly why I created this.