Skip to content

Instantly share code, notes, and snippets.

@cloudRoutine
Last active May 13, 2022 15:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cloudRoutine/39e403cbb4474c5955d6bdadd609f420 to your computer and use it in GitHub Desktop.
Save cloudRoutine/39e403cbb4474c5955d6bdadd609f420 to your computer and use it in GitHub Desktop.
Posh Profile for Portable Cmder with Vim Config Instructions
# NOTE - If there are weird character errors when trying to load this profile
# resave the file with the encoding `UTF-8 with BOM`
# ┌ ┐
# Setup Environment
# └ ┘
# change to codepage to display symbols properly
chcp 65001 | out-null
# Set the OutputEncoding to Unicode so that the λ renders properly
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
set-alias vim "$env:CMDER_ROOT\vendor\vim\vim74\vim.exe"
set-alias vi vim
$vimrc = "$env:CMDER_ROOT/config/_vimrc"
# Sets the process level envar for the posh profile
$profile = "$env:CMDER_ROOT/config/user-profile.ps1"
$scripts = "$env:CMDER_ROOT/config/posh_scripts"
# When using Cmder, PSGet should install modules into the portable dir
$PsGetDestinationModulePath = "$CmderModulePath"
$defaultModulePath = "$home/Documents/WindowsPowerShell/Modules"
<# Notes on setting up posh, cmder, & vim to play nicely
You must inlcude the following in your `_vimrc` file in $home
-------------------------------------------------------------
set term=xterm
set t_Co=256
" Enable ANSI for CMDER/CONEMU
if has('win32') && !has('gui_running') && !empty($CONEMUBUILD)
let &t_AB="\e[48;5;%dm"
let &t_AF="\e[38;5;%dm"
endif
" Enable Unicode
set encoding=utf-8
set termencoding=utf-8
set fileencoding=utf-8
-------------------------------------------------------------
You must enable these ConEmu/Cmder Settings
- On the Colours Page: TrueMod (24bit color) support
- On the Features Page: ANSI x3.64 / xterm 256 colors
- On the Features Page: Inject ConEmuHk
#>
# ┌ ┐
# Setup Prompt
# └ ┘
# Set up a Cmder prompt, adding the git prompt parts inside git repos
function global:prompt {
$realLASTEXITCODE = $LASTEXITCODE
# $Host.UI.RawUI.ForegroundColor = "White"
$Host.UI.RawUI.ForegroundColor = $GitPromptSettings.DefaultForegroundColor
Write-Host "$env:USERNAME@" -n -f DarkYellow
Write-Host "$env:COMPUTERNAME" -n -f Magenta
Write-Host " : " -n -f DarkGray
$loc = $pwd.ProviderPath
if($loc -ieq $home){ $loc = "~\" }
else { $loc = $loc -ireplace [regex]::Escape($home), "~" }
Write-Host $loc -n -f Green
Write-VcsStatus
write-host `r
Write-Host "λ»" -n -f DarkGray
$global:LASTEXITCODE = $realLASTEXITCODE
return " "
}
# ┌ ┐
# Imports
# └ ┘
if ($host.Name -eq 'ConsoleHost'){
import-module psget
import-module psurl
import-module PSColor
import-module TabExpansionPlusPlus
import-module ZLocation
select "$scripts/*.ps1" | %{.$_}
}
Set-PSReadLineOption -HistoryNoDuplicates
Set-PSReadLineOption -HistorySearchCursorMovesToEnd
Set-PSReadLineOption -HistorySaveStyle SaveIncrementally
Set-PSReadLineOption -MaximumHistoryCount 4000
# history substring search
Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward
# Tab completion
Set-PSReadlineKeyHandler -Chord 'Ctrl+Spacebar' -Function MenuComplete
# ┌ ┐
# Common Commands
# └ ┘
set-alias posh powershell
set-alias open Invoke-Item
set-alias props Get-Member
set-alias whereis where.exe
if(test-path -path "$home/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/GitHub") {
set-alias github "$home/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/GitHub, Inc/GitHub.appref-ms"
}
function repos { cd "$home/Github" }
function pics { cd "$home/Pictures" }
# color coded ls from script at "$CMDER_ROOT/config/profile.d/get-childItem-color.ps1"
Set-Alias l Get-ChildItem-Color -option AllScope
Set-Alias lw Get-ChildItem-Format-Wide -option AllScope
function Get-ChildItem-Force { l -Force }
set-alias la Get-ChildItem-Force -option AllScope
function filter-list ($filter){
ls | where -property name -match $filter
}
set-alias fls filter-list
# a more useful `cd` where `cd -` takes you to your previous location
function cddash {
if ($args[0] -eq '-'){ $pwd = $OLDPWD }
else { $pwd = $args[0] }
$tmp = pwd
if ($pwd){ set-location $pwd }
set-variable -Name OLDPWD -Value $tmp -Scope global
}
set-alias -Name cd -value cddash -Option AllScope
function findlock ($lockedFile){
Get-Process |
foreach { $processVar = $_;$_.Modules |
foreach { if($_.FileName -eq $lockedFile) { $processVar.Name + " PID:" + $processVar.id}}
}
}
function poshver { $PSVersionTable.PSVersion | write-host }
function reload-path {
write-host " `n Δ Reloading Environment Variables from PATH... " -foregroundcolor darkgreen
$env:Path = "$Env:CMDER_ROOT/bin;" +
[System.Environment]::GetEnvironmentVariable('Path','Machine') + ';' +
[System.Environment]::GetEnvironmentVariable('Path','User')
}
set-alias rpath reload-path
function delfr ($target){ del $target -force -recurse }
function dir ($dirName){ ni $dirName -type directory }
function delete-temp { Cmd /C 'rmdir /S /Q C %HOME%/AppData/Local/Temp' }
# ┌ ┐
# F# DEV
# └ ┘
function scaffoldfs ($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'
}
# ┌ ┐
# GIT HELPERS
# └ ┘
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 undo { reset HEAD~1 --mixed }
function softreset { git reset --soft HEAD~1 }
function pop-commit { git reset HEAD^ }
function remotes { git remote -v }
function set-remote ($remote, $url){ git remote set-url $remote $url }
function co ($branch){ git checkout $branch }
function ec { git config --global -e }
function cm ($commitMessage){ git add -A | git commit -m $commitMessage }
function gitdrop { git checkout -- . }
function discard-changes { git clean -df; git checkout -- . }
function tracking ($branch){ git ls-tree -r $branch --name-only }
function untrack ($file){ git rm --cached -f $file }
function amend-with ($commitMessage){
git commit -a --amend -m $commitMessage
}
function glog ($num){
if ([string]::IsNullOrEmpty($num)){
$num='--all'
} else {
$num="-$num"
}
git $args --no-pager log --oneline $num --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 wash {
git add -A
git commit -qm 'WIPE SAVEPOINT'
git reset HEAD~1 --hard
}
# ┌ ┐
# VISUAL STUDIO HELPERS
# └ ┘
set-alias msbuild4 'C:/Windows/Microsoft.NET/Framework64/v4.0.30319/MSBuild.exe'
function msbuild($num){
"C:/Program Files (x86)/MSBuild/$num.0/Bin/MSBuild.exe"
}
# Launch Visual Studio
function vs ($num){
"C:/Program Files (x86)/Microsoft Visual Studio $num.0/Common7/IDE/devenv.exe"
}
# Launch Visual Studio Experimental Instance
function vsexp($num){
& "C:/Program Files (x86)/Microsoft Visual Studio $num.0/Common7/IDE/devenv.exe" /RootSuffix Exp
}
# Reset Visual Studio Experimental Instance
function resetExp($num){
& "C:/Program Files (x86)/Microsoft Visual Studio $num.0/VSSDK/VisualStudioIntegration/Tools/Bin/CreateExpInstance" /Reset /VSInstance=$num.0 /RootSuffix=Exp
}
function cleanExp($num){
& "C:/Program Files (x86)/Microsoft Visual Studio $num.0/VSSDK/VisualStudioIntegration/Tools/Bin/CreateExpInstance" /Clean /VSInstance=$num.0 /RootSuffix=Exp
}
function load-templates ($year, $num){
write-host " `Δ loading visual studio 2015 templates from - $home/Documents/Visual Studio $year/Templates " -foregroundcolor darkgreen
vs $num /installvstemplates
}
function devenv($num){
& "C:/Program Files (x86)/Microsoft Visual Studio $num.0/Common7/IDE/devenv.exe"
}
# Chocolatey profile
$ChocolateyProfile = "$env:ChocolateyInstall/helpers/chocolateyProfile.psm1"
if (Test-Path($ChocolateyProfile)) {
import-module "$ChocolateyProfile"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment