Skip to content
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

Configure Powershell to match CMD #294

Closed
cloudRoutine opened this issue Oct 22, 2014 · 1 comment
Closed

Configure Powershell to match CMD #294

cloudRoutine opened this issue Oct 22, 2014 · 1 comment

Comments

@cloudRoutine
Copy link

I'm not sure where this would go as a part of cmder, but this script will configure powershell to
closely resemble the cmd and match more of the hotkeys.

Some differences
the » will change its color to red to indicate invalid syntax.
gl can't be aliased over, so I used glog instead.

Also the .ps1 file had to be saved as UTF-8 with BOM for the λ to display properly in the prompt

 # install psget
if (!(Get-Module -ListAvailable | ? { $_.name -like 'psget' })) {
    write-host "Installing PsGet ..." -foregroundcolor green
    (new-object Net.WebClient).DownloadString("http://psget.net/GetPsGet.ps1") | iex
 }

if (!(Get-Module -ListAvailable | ? { $_.name -like 'psreadline' })) {
        write-host "Installing PsReadLine..." -foregroundcolor cyan
        Install-Module PsReadLine
    }

if (!(Get-Module -ListAvailable | ? { $_.name -like 'posh-git' } )) {
        write-host "Installing Posh-Git..." -foregroundcolor cyan
        Install-Module posh-git
    }

if ($host.Name -eq 'ConsoleHost')
{
    Import-Module PSReadline
    Import-Module posh-git

    if ($host.Name -eq 'ConsoleHost') {
        Set-PSReadlineKeyHandler -Key Ctrl+Delete    -Function KillWord
        Set-PSReadlineKeyHandler -Key Ctrl+Backspace -Function BackwardKillWord
        Set-PSReadlineKeyHandler -Key Shift+Backspace -Function BackwardKillWord
        Set-PSReadlineKeyHandler -Key UpArrow        -Function HistorySearchBackward
        Set-PSReadlineKeyHandler -Key DownArrow      -Function HistorySearchForward
        Set-PSReadlineKeyHandler -Key Tab            -Function Complete

        $Host.PrivateData.ErrorBackgroundColor   = $Host.UI.RawUI.BackgroundColor
        $Host.PrivateData.WarningBackgroundColor = $Host.UI.RawUI.BackgroundColor
        $Host.PrivateData.VerboseBackgroundColor = $Host.UI.RawUI.BackgroundColor

        Push-Location (Split-Path -Path $MyInvocation.MyCommand.Definition -Parent)

        function prompt 
        {
            $g = [ConsoleColor]::Green
            $h = [ConsoleColor]::DarkGray

            $realLASTEXITCODE = $LASTEXITCODE
            $Host.UI.RawUI.ForegroundColor = $GitPromptSettings.DefaultForegroundColor
            $loc = $(Get-Location) 

            Write-Host `r
            Write-Host $loc -n -f $g
            Write-VcsStatus
            Write-Host `r
            Write-Host "λ»" -n -f $h

            $global:LASTEXITCODE = $realLASTEXITCODE
            Return ' '
        }
        Enable-GitColors
        Pop-Location
        Start-SshAgent -Quiet
    }
}
function glist {   return git $args --no-pager log --oneline --all --graph --decorate  }
Set-Alias -name glog -value glist
@LeoColomb
Copy link
Contributor

Almost already done with #271. Needs #273 and new release to be completed.
For the tip, don't force a module installation in a profile.
Also, the gl alias can be set it in git directly.
😃

@MartiUK Can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants