Powershell_ise does not update the modification outside

How to update Powershell_ise for content modified outside of the IDE.

In most cases, I would open both Powershell_ise and Notepad ++

If I make changes to Powershell_ise, notepad ++ asks for a reboot, but if I change in notepad ++, there is no way to update in Powershell_ise.

Is there any way to update the content, or am I overlooking any function that provides this?

+6
source share
3 answers

PowerShell ISE does not support updating updated files automatically. It is not even in ISE v3.

There is a connection offer on this topic: https://connect.microsoft.com/PowerShell/feedback/details/711915/open-ise-files-should-update-when-edited-externally

However, this can be done using the PowerShell ISE Object Model and PowerShell eventing. Explore the $ psise.CurrentFile and $ psise.CurrentPowerShellTab.Files collection. This should give you enough information to write your own simple add-on.

+3
source

This post is old, but I decided that I would post it, since Google brought me here with the same problem.

In the end, I just wrote this little function that doesn't do what the OP wanted, but maybe other search engines will find this useful:

function Build { #Reload file $CurrentFile = $psise.CurrentFile $FilePath = $CurrentFile.FullPath $PsISE.CurrentPowerShellTab.Files.remove($CurrentFile) $PsISE.CurrentPowerShellTab.Files.add($FilePath) iex $PsISE.CurrentPowerShellTab.Files.Editor.Text } $psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Clear() $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("Reload file and run",{Build},'f4') 

This is not ideal, but for me it is good enough. All this is creating a key binding that closes, opens again, and then executes the current file. It is a little annoying because when you start it, you will lose the current cursor position when the file is closed and reopened. I'm sure you could keep the column and row position of the cursor and restore it on reboot, but I'm too lazy to worry about it at the moment.

Edit: I accidentally posted an old non-working version of my code. Updated with working version.

+3
source

Here is a great response to the red888 script:

 function Reload { $CurrentFile = $psise.CurrentFile $FilePath = $CurrentFile.FullPath $lineNum = $psise.CurrentFile.Editor.CaretLine $colNum = $psise.CurrentFile.Editor.CaretColumn $PsISE.CurrentPowerShellTab.Files.remove($CurrentFile) > $null $newFile = $PsISE.CurrentPowerShellTab.Files.add($FilePath) $newfile.Editor.SetCaretPosition($lineNum,$colNum) } $psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Clear() $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("Reload File",{Reload},'f4') > $null 

It restores the position of the carriage after a reboot. I deleted the line

 iex $PsISE.CurrentPowerShellTab.Files.Editor.Text 

Since I do not need this, and it also does not coincide with running the script (and therefore leads to strange behavior of operators like $script:MyInvocation.MyCommand.Path ).

By the way, if you put this code in your ISE profile, it will automatically run the first time ISE boots up. An ISE profile is just a powershell script whose location is set by the $profile variable.

Here are a few commands that create a profile if it does not exist, and then opens it. Run it from within ISE:

 if (!(Test-Path (Split-Path $profile))) { mkdir (Split-Path $profile) } ; if (!(Test-Path $profile)) { New-Item $profile -ItemType file } ; notepad $profile 
+2
source

Source: https://habr.com/ru/post/905525/


All Articles