8000 Execute profile commands with out-default by andyleejordan · Pull Request #3 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Execute profile commands with out-default #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Microsoft.PowerShell.Linux.Host/PSL_profile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,13 @@ function prompt
invoke-expression $str
}
}

function banner
{
"`nPowerShell for Linux interactive console"
"========================================"
"- Type 'get-help' for help"
"- Type 'exit' to exit`n"
}

banner
39 changes: 27 additions & 12 deletions src/Microsoft.PowerShell.Linux.Host/main.cs
F6F3
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,6 @@ public static void Main(string[] args)
// only run if there was no script file passed in
if (initialScript == null)
{
// Display the welcome message.
Console.WriteLine();
Console.WriteLine("PowerShell for Linux interactive console");
Console.WriteLine("========================================");
Console.WriteLine();
Console.WriteLine("Current status:");
Console.WriteLine("- Type 'exit' to exit");
Console.WriteLine("- Utility and Management cmdlet modules are loadable");
Console.WriteLine();

listener.Run();
}
}
Expand Down Expand Up @@ -176,8 +166,7 @@ public Listener(string initialScript)
PSCommand[] profileCommands = HostUtilities.GetProfileCommands("PSL");
foreach (PSCommand command in profileCommands)
{
this.currentPowerShell.Commands = command;
this.currentPowerShell.Invoke();
RunCommand(command);
}
}
finally
Expand Down Expand Up @@ -225,6 +214,32 @@ public string Prompt(Runspace rs)
return returnVal;
}

/// <summary>
/// Runs individual commands
/// </summary>
/// <param name="command">command to run</param>
internal void RunCommand(PSCommand command)
{
if (command == null)
{
return;
}

command.AddCommand("out-default");
command.Commands[0].MergeMyResults(PipelineResultTypes.Error, PipelineResultTypes.Output);

this.currentPowerShell.Commands = command;

try
{
this.currentPowerShell.Invoke();
}
catch (RuntimeException e)
{
this.ReportException(e);
}
}

/// <summary>
/// A helper class that builds and executes a pipeline that writes
/// to the default output path. Any exceptions that are thrown are
Expand Down
0