Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Better PowerShell hosts than powershell.exe?

Tags:

powershell

I've been trying to switch over to PowerShell from my old favorite 4NT. It's missing a lot of niceties that 4NT has been adding over the last 20 years (I'm an old 4DOS user).

For example, in 4NT if you type a few letters then hit up/down, then the history list is filtered by what you typed. Page up/down does a popup with all matches and you can cursor through them. All in the console window space, no GUI. This is a big time-saver that I miss. There are many other things like this missing from powershell.exe.

Are there any alternatives to powershell.exe that perhaps have features like this, that really take advantage of the console environment? I realize there are a lot of GUI-based tools that embed PowerShell as a pane, but I'm really interested in a cmd.exe/4nt.exe replacement that stays as a 100% console application (except for maybe an options dialog or whatever).

like image 567
scobi Avatar asked Jan 25 '10 04:01

scobi


4 Answers

Joshua already mentioned F7. You can also do partial history matches in Powershell.exe by typing some of the command and pressing F8 - repeat F8 to cycle through matches (see about_history). There are also a few more line editing features than folks typically know about. These are documented in the about_line_editing help topic. Still, line editing in the PowerShell console host leaves something to be desired. FWIW all of the other hosts I'm aware of are GUI based.

BTW I was a 4NT user for years (as well as Korn shell user). Even with a few missing amenities found in 4NT, I find PowerShell a much more capable shell and, as a developer, all the "language" bits are pretty easy to adapt to and use. I never really liked the Korn shell if / fi and case / esac statements - just rubbed my sense of aethestics the wrong way. :-) Plus in PowerShell you can do cool stuff with your history like:

# Search history using regex
PS> get-history -count 999 | select-string '\b(fl|ft)\b'

# Look at your shell usage pattern by hour of day - Name column is hour of day
PS> ghy | group {$_.StartExecutionTime.Hour}

Count Name       Group
----- ----       -----
   30 21         {$allargs, echoargs -arg $allArgs, echoargs $a
    2 22         {ghy | group {$_.StartExecutionTime.Hour}, ls}

# Look at commands in terms of execution time (sorted descending)
PS> ghy | Select CommandLine,Id,`
      @{n='ExecutionTime';e={$_.EndExecutionTime - $_.StartExecutionTime}} | 
      Sort ExecutionTime -Desc 

CommandLine                                        Id ExecutionTime
-----------                                        -- -------------
ls C:\Windows\System32 ...                         94 00:00:06.0233445
ls C:\Windows\System32\...                         93 00:00:01.1360650
gps | fl                                           89 00:00:00.5780330
dir                                                80 00:00:00.0950054
ls                                                 83 00:00:00.0870050
ghy | Select CommandLin...                         92 00:00:00.0810046
dir                                                67 00:00:00.0750042
ghy | Select CommandLin...                         95 00:00:00.0580034
ghy | Select CommandLin...                         96 00:00:00.0570032
ghy | Select CommandLin...                         97 00:00:00.0540031
dir                                                76 00:00:00.0500029
get-history -count 999 ...                         88 00:00:00.0420024
like image 157
Keith Hill Avatar answered Sep 23 '22 09:09

Keith Hill


It is also possible to tab through your command history by using #.

One of the disadvantages of using F8 is that it is case sensitive and it only matches the beginning of a command. Using #<partial match><tab> is case insensitive and will match text at any position in the previous commands.

If you have the following command history:

# 1
$np = Start-Process notepad -PassThru
# 2
$np| get-process
# 3
$np| Stop-Process

Typing #pr then tab repeatedly will cycle through 1, 2 and 3.

Typing #st then tab repeatedly will cycle through 1 and 3.

Using only # will match all history.

# can also be used after entering part of a command. If your history is:

'notepad'
select *

You can type Get-Process #n<tab>| #s<tab> to get Get-Process 'notepad'| select *

like image 23
Rynant Avatar answered Sep 20 '22 09:09

Rynant


Check out PowerTab. It is a great (and free) add-on that gives you some really nice tab-completion features.

UPDATE

PowerTab has a new host.

like image 30
aphoria Avatar answered Sep 20 '22 09:09

aphoria


Hey, you have the same history as me. I'm an old 4dos/4nt user too. I'm not a fan of the new fangled hosts that completely replace the console subsystem for input and that's why I like PowerShell Plus - at its core it's still the NT console but has many modern graphical features that can be pared back as desired.

http://www.idera.com/Products/PowerShell/PowerShell-Plus/

There's a 30 day trial available and the author Tobias Weltner is very responsive to help requests/suggestions.

-Oisin

like image 34
x0n Avatar answered Sep 20 '22 09:09

x0n