Where I mention the shortcomings of today's console in Windows and what I
expect from a modern console. For easy reading I'll quote the blog in its
entirety below, but for the hypertext version with links and formatting I
recommend the link above.
"Searching for a good replacement for the old console in Windows.
My early impressions of PowerShell.
Lately I’ve been playing around with Microsoft’s PowerShell, which I’ve seen
referred to as PoSH on some sites. While the shell looks like the next-gen
technology when it comes to shell and scripting, I’m really dismayed that
Microsoft hasn’t improved the archaic cmd.exe terminal (In Windows
terminology referred to as a “console”). In the windows world we have been
using the same terminal like since Windows NT4?
Great shell. Poor terminal.
The thing that bugs me the most with cmd.exe is that you can’t freely resize
it horizontally. It also looks out of place on Windows XP OS’s because of
some to me unknown reason it still uses the Window manager frame from Windows
2000 (Or what the hell! Probably even NT4). At least the frame is fixed in
Vista!
What I expect from a terminal today.
Perhaps I’m sounding picky in the ears of long-time Windows admins, but when
you have used terminals for a long time on Unix and Linux systems then going
back to cmd.exe really feels like time-travelling backwards. A good example
from the Linux world is gnome-terminal; fully resizable, good possibilities
for configuring the font, tabs, easy copy and paste.
Problems with PowerShell and rxvt and xterm for Windows.
I could use the shell in cmd.exe with the terminals rxvt or xterm from
cygwin (a Linux-like environment for Windows) to make for a nice terminal
experience. Unfortunately PowerShell doesn’t work with either rxvt or xterm
:-( , the prompt never appears and I have to close the terminal.
A better one in the future?
However, even MS employees admits that the current terminal it somewhat
outdated. Don’t get me wrong, I’m sure that PowerShell will make even the
most hardcore Unix admin jealous. I’m just finding it sad that their first
impression of PowerShell won’t be as great because of the inferior terminal.
Hopefully a better one will show up in the future!"
Others opinions, recommendation of alternative consoles, or feedback on this
issue is highly appreciated!
----------------
This post is a suggestion for Microsoft, and Microsoft responds to the
suggestions with the most votes. To vote for this suggestion, click the "I
Agree" button in the message pane. If you do not see the button, follow this
link to open the suggestion in the Microsoft Web-based Newsreader and then
click "I Agree" in the message pane.
Best Regards,
Jeroen Vandezande
"John Ericson" <JohnE...@discussions.microsoft.com> wrote in message
news:149F9D47-A0A3-43DA...@microsoft.com...
http://blogs.msdn.com/powershell/archive/2006/07/01/653194.aspx
Cheers
"Jeroen Vandezande" <NoS...@NoSpam.be> wrote in message
news:eyXEyqqn...@TK2MSFTNGP05.phx.gbl...
You are not being picky. What you are asking for is perfectly reasonable.
We wanted to fix this for V1 but didn't have the bandwidth. Instead, we
exposed the interfaces necessary for a 3rd party to be able to deliver this
(Search for PowerShell Analyzer to see an example of what I mean).
Thanks for filing the feature request. Other people should vote on this so
that we know where to put it in our priorities.
--
Jeffrey Snover [MSFT]
Windows PowerShell Architect
Microsoft Corporation
This posting is provided "AS IS" with no warranties, no confers rights.
Visit the Windows PowerShell Team blog at:
http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at:
http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx
I was thinking of doing my first cmdlet exercise by building a cmdlet that
lets you hook a function to the console close event. If I am succesful and
there is interest, I'll post the solution here.
Greg
"Sean McLeod" <seanm...@newsgroups.nospam> wrote in message
news:%23XpUivq...@TK2MSFTNGP03.phx.gbl...
Cheers
"Greg Borota" <bor...@gmail.com> wrote in message
news:%23gN2$GrnGH...@TK2MSFTNGP03.phx.gbl...
Greg
"Sean McLeod" <seanm...@newsgroups.nospam> wrote in message
news:eTfGEAsn...@TK2MSFTNGP05.phx.gbl...
>What I would like the most is command history...
>In Unix when you log on again with a user and open a bash shell you can
>press arrow up and have your last used command from last time... even if the
>pc has been turned off...
>I hate it when I close a command prompt and open a new one that I lost my
>history....
>
>Best Regards,
>
>Jeroen Vandezande
Jeroen,
Are you assuming that a user will have only a single PowerShell window
open?
If multiple windows have been opened how would you want/expect a
command history (or histories) to work?
Andrew Watt MVP
>What I expect from a terminal today.
>Perhaps I’m sounding picky in the ears of long-time Windows admins, but when
>you have used terminals for a long time on Unix and Linux systems then going
>back to cmd.exe really feels like time-travelling backwards. A good example
>from the Linux world is gnome-terminal; fully resizable, good possibilities
>for configuring the font, tabs, easy copy and paste.
Easy copy and paste would get a vote from me.
John, why not post specific suggestions individually on Connect so we
can vote on the aspects that we feel are important?
Andrew Watt MVP
> John, why not post specific suggestions individually on Connect so we
> can vote on the aspects that we feel are important?
That's a good idea! I'll post some individual suggestions that I can think
of using "Console: [suggestion]" as subject lines, like "Console: Easy
horizontal resizing", "Console: Make it easier selecting text" and more.
Offtopic: Out of curiosity! What does MVP stand for?
> Are you assuming that a user will have only a single PowerShell window
> open?
My reply is not intended to be a reply for Jeroen Vandezande, but instead
for a guy coming from the Unix world.
History can work fine even if you have several consoles (PowerShell windows)
open at the same time.
> If multiple windows have been opened how would you want/expect a
> command history (or histories) to work?
I suggest bash as a good example of how history could work with multiply
windows. You can check it out by installing cygwin on a Windows box. bash
saves the history in the ~/.bash_history file on exit and loads it on start.
If you open two bash windows then both those windows will have the history,
but all the new commands inputted will only be available in the local history
in each window. When any window is closed its history is saved to
.bash_history and newly created bash windows will read it on startup.
So bash reads the history and then stores it locally and writes it back to
the .bash_history file on exit. No intercommunication of history exists
between bash sessions, the sessions are local.
In that case, doesn't each shell exit stomp the history of the shells that
exited before it? That is, if I have three shells running then the last one
exited is that one that gets its history persisted.
--
Keith
Most Valuable Professional. It is awarded to folks who participate a lot in
a particular Microsoft community especially in the area of helping others by
answering questions on MS technologies.
--
Keith
Greg
"Sean McLeod" <seanm...@newsgroups.nospam> wrote in message
news:eTfGEAsn...@TK2MSFTNGP05.phx.gbl...
> Yep, although I guess if there was a fairly easy way to catch the exit
> then Jeffrey would've used it.
>
> Cheers
>
> "Greg Borota" wrote in message
Ah, right! I just tested what you said with two cygwin bash shells and no,
the second shell doesn't stomp the history of the first one. Although the
cygwin bash shells must be closed with CTRL+D or the commands "exit" or
"logout", this could be a Windows thing I'm not sure. My test step by step:
1) Start two shells (two windows).
2) In the first shell I input "command1" and in the second "command2".
3) I close the first shell and then the second.
4) When I open a new shell and scroll back in the history by pressing the up
arrow key, I first get "command2" and then "command1".
"Greg Borota" <bor...@newsgroups.microsoft> wrote in message
news:%23ExroGz...@TK2MSFTNGP02.phx.gbl...
>I did a comprehensive blogging on this subject at the address:
>http://www.john.se/blog/2006/07/01/searching-for-a-good-replacement-for-the-old-console-in-windows/
[snip]
4NT (JPSoft) has provided a number of features that are lacking in PoSH,
like command and directory history between sessions, for a long time.
As for appearance, JPSoft has a public beta for a new product, Tabbed
Console Interface (TCI) which can be used to run any console application
(<http://www.jpsoft.com/download.htm>). I have no need for Tabbed
Consoles and have no experience with TCI, but many experienced console
users like it a lot.
(I have no interest in JPSoft, except that I couldn't do my job without
4NT.)
--
Michael Bednarek http://mbednarek.com/ "POST NO BILLS"
>"Andrew Watt [MVP]" wrote:
>
>> John, why not post specific suggestions individually on Connect so we
>> can vote on the aspects that we feel are important?
>
>That's a good idea! I'll post some individual suggestions that I can think
>of using "Console: [suggestion]" as subject lines, like "Console: Easy
>horizontal resizing", "Console: Make it easier selecting text" and more.
Ideally, give the link for each suggestion. Inertia means that doing
things that way will likely attract more votes! Human nature likes
inertia. :)
>Offtopic: Out of curiosity! What does MVP stand for?
MVP = Most Valuable Professional.
See https://mvp.support.microsoft.com/
Andrew Watt MVP
>Ah, right! I just tested what you said with two cygwin bash shells and no,
>the second shell doesn't stomp the history of the first one. Although the
>cygwin bash shells must be closed with CTRL+D or the commands "exit" or
>"logout", this could be a Windows thing I'm not sure. My test step by step:
>
>1) Start two shells (two windows).
>
>2) In the first shell I input "command1" and in the second "command2".
>
>3) I close the first shell and then the second.
>
>4) When I open a new shell and scroll back in the history by pressing the up
>arrow key, I first get "command2" and then "command1".
Thanks. That's interesting.
Andrew Watt MVP
I think there should be a possibility to write a custom shell exit handler
just like we can do with the custom prompt function.
--
greetings
dreeschkind
My understanding is that console signal handler (invoked when closing the
console) is invoked on a different thread, and that causes problems. Also
currently there doesn't seem to be any exit hook available. It's kind of
surprising but that's the way things seem to be.
You could have a convoluted hack, where a dialog pops up when the user
closes the console window asking to save history, but I personally don't
like that. Would people like something like that? That should work.
Greg
P.S. If you want I could post the code I wrote to capture console closing
"dreeschkind" <drees...@discussions.microsoft.com> wrote in message
news:65F8BA7A-9510-4285...@microsoft.com...
Let me know if you can come up with a solution. I personally gave up, I
don't think is quite possible. That's way I implemented the prompt solution.
I think this is a good example where PS current limitations come to bite
you.
****************************************************
$framework =
[System.Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory()
# credits to Jeffrey Snover
function Compile-Csharp ([string] $code, [Array]$References) {
# Get an instance of the CSharp code provider
$cp = New-Object Microsoft.CSharp.CSharpCodeProvider
$refs = New-Object Collections.ArrayList
$refs.AddRange( @("${framework}System.dll",
"${PsHome}\System.Management.Automation.dll",
"${PsHome}\Microsoft.PowerShell.ConsoleHost.dll",
"${framework}System.Windows.Forms.dll",
"${framework}System.Data.dll",
"${framework}System.Drawing.dll",
"${framework}System.XML.dll"))
if ($References.Count -ge 1) {
$refs.AddRange($References)
}
# Build up a compiler params object...
$cpar = New-Object System.CodeDom.Compiler.CompilerParameters
$cpar.GenerateInMemory = $true
$cpar.GenerateExecutable = $false
$cpar.IncludeDebugInformation = $false
$cpar.CompilerOptions = "/target:library"
$cpar.ReferencedAssemblies.AddRange($refs)
$cr = $cp.CompileAssemblyFromSource($cpar, $code)
if ( $cr.Errors.Count) {
$codeLines = $code.Split("`n");
foreach ($ce in $cr.Errors) {
write-host "Error: $($codeLines[$($ce.Line - 1)])"
$ce | out-default
}
Throw "INVALID DATA: Errors encountered while compiling code"
}
}
$cmd_code = '
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Management.Automation;
public class ConsoleHook
{
private static ScriptBlock scriptBlock = null;
public delegate Boolean HandlerRoutine(CtrlTypes CtrlType);
private static HandlerRoutine hr = new HandlerRoutine(consoleHandler);
[DllImport("Kernel32")]
private static extern Boolean SetConsoleCtrlHandler(HandlerRoutine
Handler, Boolean Add);
public enum CtrlTypes {
CTRL_C_EVENT = 0,
CTRL_BREAK_EVENT = 1,
CTRL_CLOSE_EVENT = 2,
CTRL_LOGOFF_EVENT = 5,
CTRL_SHUTDOWN_EVENT = 6
}
private static Boolean consoleHandler(ConsoleHook.CtrlTypes CtrlType) {
// Do something with scriptBlock, EventHandlers, throwing exception,
whatever if you can!
return true;
}
public static void SetExitHook(ScriptBlock code) {
scriptBlock = code;
SetConsoleCtrlHandler(hr, true);
}
}'
Compile-Csharp $cmd_code
[ConsoleHook]::SetExitHook({Get-History -Count 100 | Export-CSV
~\PowerShell\history.csv})
"dreeschkind" <drees...@discussions.microsoft.com> wrote in message
news:65F8BA7A-9510-4285...@microsoft.com...
Also, it would be nice if more.com worked like less does on Linux. i.e. you
can use the arrow keys to move up or down one line at a time. This goes for
all the PowerShell help commands too. The way it works now, it prompts you
and when you hit a key, the prompt is still there in the text. So, if you
are hitting enter to see one line at a time, you get the prompt for each
line. When you press a key it should erase the previous prompt.
Jon
"John Ericson" <JohnE...@discussions.microsoft.com> wrote in message
news:149F9D47-A0A3-43DA...@microsoft.com...
There is a potentially large group of us who have no current
interest in PS for interactive use because of all the missing
features critical for interactive use that are present in
virtually all Unix shells. Not being unreasonable people,
we do understand how software is developed, so we're
waiting patiently for PS V2 to see if we're being heard.
Many people, including yours truly, have put forth fine
examples of the missing features so I won't waste
time or space by doing so again here.
--
Jon Forrest
for...@ce.berkeley.edu
Computer Resources Manager
Civil and Environmental Engineering Dept.
305 Davis Hall
Univ. of Calif., Berkeley
Berkeley, CA 94720-1710
510-642-0904
"Jonathan Eric Miller" <jemi...@uchicago.edu> wrote in message
news:OG%23hKwGo...@TK2MSFTNGP03.phx.gbl...
"Jonathan Eric Miller" <jemi...@uchicago.edu> wrote in message
news:OG%23hKwGo...@TK2MSFTNGP03.phx.gbl...
"Jon Miller" <jemi...@uchicago.edu> wrote in message
news:OQaBVHSo...@TK2MSFTNGP05.phx.gbl...
Tab-completion that is ;-)
but yes it works on variables, and you can also customize it
I have an example here that does add some more tabhandling (multilevel
on variables, .NET types amongs others)
http://mow001.blogspot.com/2006/06/powershell-tab-completion-part-4.html
Greetings /\/\o\/\/
It seems to be possible to have a PsProvider run some code automatically
when the Runspace (console?) is closing. Maybe this is a solution.
However, I think you should post your basic approach again because the real
experts here might have missed it deep in this thread.
--
greetings
dreeschkind
"dreeschkind" <drees...@discussions.microsoft.com> wrote in message
news:7BA022F6-0B28-47B0...@microsoft.com...
> The "solution" provided to create a CmdletProvider has a too pungent hacking
> smell to me.
Well, the usage of a console signal handler and inline C# code also smelt a
little like hacking to me... :^)
The reason why I don't like to have so much code in my prompt function is
that I noticed it becoming slower and slower the more stuff I put into it.
Besides, this also doesn't smell right because it is not the main task of the
prompt function to save your history etc.
I filed the idea of a custom shell exit handler as a suggestion on connect
so please vote if you are still interested:
https://connect.microsoft.com/feedback/ViewFeedback.aspx?FeedbackID=158962&SiteID=99
--
greetings
dreeschkind
"dreeschkind" <drees...@discussions.microsoft.com> wrote in message
news:9F1777CB-D18E-46FD...@microsoft.com...
$hookCode = '
using System;
using System.Runtime.InteropServices;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
public class ConsoleHook
{
private static string script = null;
private static Runspace runspace = null;
public delegate Boolean HandlerRoutine(CtrlTypes ctrlType);
private static HandlerRoutine hr = new HandlerRoutine(consoleHandler);
[DllImport("Kernel32")]
private static extern Boolean SetConsoleCtrlHandler(HandlerRoutine
Handler, Boolean Add);
public enum CtrlTypes {
CTRL_C_EVENT = 0,
CTRL_BREAK_EVENT = 1,
CTRL_CLOSE_EVENT = 2,
CTRL_LOGOFF_EVENT = 5,
CTRL_SHUTDOWN_EVENT = 6
}
private static Boolean consoleHandler(CtrlTypes ctrlType) {
if (ctrlType != CtrlTypes.CTRL_C_EVENT) {
try {
Runspace.DefaultRunspace.Close();
} catch (Exception exc) {
Console.WriteLine(exc);
}
}
return false;
}
private static void HandleEvent(object sender, RunspaceStateEventArgs e) {
if (e.RunspaceStateInfo.State == RunspaceState.Closing) {
try {
RunspaceInvoke ri = new
RunspaceInvoke(runspace.RunspaceConfiguration);
ri.Invoke(script);
} catch (Exception exc) {
Console.WriteLine(exc);
}
}
}
public static void SetExitHook(string block) {
try {
script = block;
runspace = Runspace.DefaultRunspace;
runspace.StateChanged += new
EventHandler<RunspaceStateEventArgs>(HandleEvent);
SetConsoleCtrlHandler(hr, true);
} catch (Exception exc) {
Console.WriteLine(exc);
}
}
}'
Compile-Csharp $hookCode
[ConsoleHook]::SetExitHook("(Get-Location).Path | Out-File psTEST.txt")
"dreeschkind" <drees...@discussions.microsoft.com> wrote in message
news:9F1777CB-D18E-46FD...@microsoft.com...
(By the way there is a way in V1 to have command history saved, custom code
run, etc. when you close the console window, I'll post it one of these days,
probably tomorrow)
Greg
"Jon Miller" <> wrote in message
news:OarNY0Gp...@TK2MSFTNGP03.phx.gbl...
> (By the way there is a way in V1 to have command history saved, custom
> code run, etc. when you close the console window, I'll post it one of
> these days, probably tomorrow)
Greg, you'd better not be having a duel at dawn tomorrow. ;)
Jon
"Greg Borota" <bor...@newsgroups.microsoft> wrote in message
news:eNC1qRKp...@TK2MSFTNGP04.phx.gbl...