Skip to content

Commit

Permalink
Add the ability to run powershell script files directly from the "Exe…
Browse files Browse the repository at this point in the history
…cute File" context menu (#58)
  • Loading branch information
Naim Hammadi authored and madskristensen committed Jun 12, 2017
1 parent 89b2ceb commit 1a04f45
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/OpenCommandLine/OpenCommandLinePackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void BeforeExeQuery(object sender, EventArgs e)
if (!VsHelpers.IsValidFileName(path))
return;

string[] allowed = { ".CMD", ".BAT" };
string[] allowed = { ".CMD", ".BAT", ".PS1" };
string ext = Path.GetExtension(path);
bool isEnabled = allowed.Contains(ext, StringComparer.OrdinalIgnoreCase) && File.Exists(path);

Expand All @@ -79,7 +79,16 @@ private void ExecuteFile(object sender, EventArgs e)
string path = item.FileNames[1];
string folder = Path.GetDirectoryName(path);

StartProcess(folder, "cmd.exe", "/k \"" + Path.GetFileName(path) + "\"");
string ext = Path.GetExtension(path);

if (!string.IsNullOrEmpty(ext) && ext.ToLower() == ".ps1")
{
StartProcess(folder, "powershell.exe", "-ExecutionPolicy Bypass -NoExit -File \"" + Path.GetFileName(path) + "\"");
}
else
{
StartProcess(folder, "cmd.exe", "/k \"" + Path.GetFileName(path) + "\"");
}
}

private void BeforeQueryStatus(object sender, EventArgs e)
Expand Down

0 comments on commit 1a04f45

Please sign in to comment.