andy-s
10/23/2017 - 7:21 PM

Powershell Profile for use with Cmder

# Use this file to run your own startup commands

## Prompt Customization
<#
.SYNTAX
    <PrePrompt><CMDER DEFAULT>
    λ <PostPrompt> <repl input>
.EXAMPLE
    <PrePrompt>N:\Documents\src\cmder [master]
    λ <PostPrompt> |
#>

# [ScriptBlock]$PrePrompt = {

# }

# # Replace the cmder prompt entirely with this.
# # [ScriptBlock]$CmderPrompt = {}

# [ScriptBlock]$PostPrompt = {

# }

## <Continue to add your own

# If this script is throwing an error near a Unicode symbol try resaving the file as UTF-8 with BOM
$psmodules = ";~\Documents\WindowsPowerShell\Modules"
# sometimes the module paths has been fucked before posh loads, but that won't stop us
$env:PSModulePath = $env:PSModulePath + $psmodules

# Set the OutputEncoding to Unicode so that the λ renders properly
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8


# The Host check is necessary if you don't want these to load in `Windows PowerShell ISE Host`

if ($host.Name -eq 'ConsoleHost')
{
    Import-Module psget
    Import-Module PSReadline
    # Import-Module posh-ssh
    Import-Module posh-git
    Import-Module powerls
    Import-Module PSColor
    Import-Module TabExpansionPlusPlus



    # Load all of the scripts in the script repository 
    select "${psmodules}\script-repo\*.ps1" | %{.$_} 


    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 ' '
    }
    Pop-Location
    Start-SshAgent -Quiet

}

#   ┌                 ┐
#     posh management
#   └                 ┘

function poshver { $PSVersionTable.PSVersion | write-host }

$cmderProfile = 'C:\tools\cmder\config\user-profile.ps1'

 # Call with `. rlp` to reload profile
function rprof  {   write-host " `n Δ Reloading Profile...      " -foregroundcolor darkgreen
                    . $cmderProfile
                }

function rpath  {   write-host " `n Δ Reloading Environment Variables from PATH...      " -foregroundcolor darkgreen
                    $env:Path = ""
                    $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" +
                                [System.Environment]::GetEnvironmentVariable("Path","User")
                }

function rfd    {   Param($target)
                    Invoke-Expression "&cmd.exe /c rd /s /q $target"
                }
                
function d      {  Param($target)
                   cd $target 
                }

function touch   {  Param($target)
                    ni $target -ItemType File
                 }

function tail   { Param($target) 
                  get-content -Path $target -Wait 
                }

#Set-Alias github    "~\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\GitHub, Inc\GitHub.appref-ms"

function sliksvn  {cd "~\Projects\sliksvn"}
function github   {cd  "~\Projects\github"   }
function bucket   {cd  "~\Projects\bitbucket"}
function t88      {cd  "~\Projects\288Group"}
function gitlab   {cd "~\Projects\gitlab"}
function Edit-Profile { code $cmderProfile }
Set-Alias ep    Edit-Profile

Set-Alias open      Invoke-Item
Set-Alias ll        Get-ChildItem
Set-Alias l         Get-ChildItem
function projects  { cd     '~\Projects'    }

function dropbox   { cd     '~\Dropbox'     }

function downloads { cd     '~\Downloads'   }

#   ┌        ┐
#     C# DEV
#   └        ┘

Set-Alias msbuild4  "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe"
Set-Alias msbuild14 "C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe"
Set-Alias vs        "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv.exe"
Set-Alias vs12      "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe"

function  load-templates { write-host " `Δ loading visual studio 2017 templates from - C:\Users\andys\Documents\Visual Studio 2017\Templates       " -foregroundcolor darkgreen
                            vs14 /installvstemplates }

# function scaffoldfs {   Param($projectName)
#                         git clone "https://github.com/fsprojects/ProjectScaffold.git"
#                         cd ProjectScaffold
#                         echo "`nRemoving original .git folder..."
#                         Remove-Item ".git" -force -recurse
#                         echo " done.`n"
#                         cd ..
#                         if ($projectName -eq "") {$projectName = "fsharp_oss_project"}
#                         echo "`nRenaming project $projectName `n"
#                         Rename-Item ProjectScaffold $projectName
#                         cd $projectName
#                         git init
#                         & ".\build.cmd"
#                     }

# function scaffold-into {  ($directory)
#                         mkdir "temp_scaffold" | cd "temp_scaffold"
#                         echo "`n Cloning Project Scaffold"
#                         git clone "https://github.com/fsprojects/ProjectScaffold.git"
#                         cd ProjectScaffold | Remove-Item ".git" -force -recurse
#                         cd .. | echo "`n Copying Scaffold files into " + $directory
#                         Copy-Item ProjectScaffold\* $directory
#                         cd ..
#                         echo "`n Cleaning up temporary scaffold files " + $directory
#                         Remove-Item "temp_scaffold" -Force -Recurse
#                         echo "`n COMPLETE! You can run the Scaffold setup with '.\build.cmd' "
#                     }



#   ┌             ┐
#     GIT HELPERS
#   └             ┘

function glog   {   git $args --no-pager log --oneline --all --graph --decorate `
                    --pretty=format:"%C(yellow)%h%Creset | %C(magenta)%ad%Creset | %Cred%d%Creset %Creset%s  %C(green dim) < %cn > %Creset " `
                    --date=short                 }

function update {   git pull --rebase --prune $@
                    git submodule update --init --recursive
                }
function save   {   git add -A
                    git commit -m 'SAVEPOINT'
                }
function wipe   {   git add -u
                    git commit -m "WIPE"
                }
function amend  {   git commit -a --amend --no-edit  }

function amend-with
                {   Param($commitMessage)
                    git commit -a --amend -m $commitMessage   }

function undo   {   reset HEAD~1 --mixed    }

function softreset { git reset --soft HEAD~1 }

function wash   {   git add -A
                    git commit -qm 'WIPE SAVEPOINT'
                    git reset HEAD~1 --hard }

function pop-commit { git reset HEAD^ }


function git-remotes
  {  git remote -v }

function set-remote  ($remote, $url)
    {  git remote set-url $remote  $url     }

function gco     {   Param($branch)
                    git checkout $branch           }

function ec     {   git config --global -e  }

function gcm     {   Param($commitMessage)
                    git add -A | git commit -m $commitMessage }

function gst     { git status }
function gitdrop { git checkout -- . }

function tracking { Param($branch)
    git ls-tree -r $branch --name-only
}

function untrack {  Param($file)
    git rm --cached -f $file
}

function untag { Param($tag)
    git push --delete origin $tag
    git tag -d $tag
}

function tag { Param($tag)
    git tag $tag
    git push --tags origin master
}

function tags { git tag }

function clone { Param($repo)
    git clone $repo
}