Skip to content

Instantly share code, notes, and snippets.

@remccormick
Forked from i-e-b/A_Profile_BJSS.ps1
Created November 20, 2019 21:37
Show Gist options
  • Save remccormick/198c54d78302da2e47a0ca8227c25554 to your computer and use it in GitHub Desktop.
Save remccormick/198c54d78302da2e47a0ca8227c25554 to your computer and use it in GitHub Desktop.
My sample Powershell profile script
Set-PSReadlineOption -BellStyle None
Import-Module 'C:\Gits\posh-git\src\posh-git.psd1'
set-executionpolicy Unrestricted process
$baseDir = Split-Path -parent $MyInvocation.MyCommand.Definition
#. "$baseDir\hand.ps1"
# General actions
function edit ($file) { & "${env:ProgramFiles(x86)}\Notepad++\notepad++.exe" $file }
function vim () { & "${env:ProgramFiles}\Vim\vim80\gvim.exe" $args }
function sln { ls -Filter "*.sln" | select -first 1 | %{& ".\$_"} }
function explore { "explorer.exe `"$(pwd)`"" | iex }
function wipe { $Host.UI.RawUI.ForegroundColor = "white"; $Host.UI.RawUI.BackgroundColor = "black"; clear; }
function touch ($file) { echo "" >> $file; }
#
# Shell environment
#
function swapd() { # swap between two directories (recreates "pushd +1" from *nix)
if ((Get-Location -Stack).Count -eq 0) {return}
$swapd_a = pwd; popd; $swapd_b = pwd;
cd $swapd_a; pushd $swapd_b
}
set-alias which where.exe
# Prompt with directory stack
function prompt {
$prompt_dir_stack = ""
$prompt_cd = "$(Get-Location)"
$host.ui.rawui.WindowTitle = $prompt_cd
$stackStr = ""
$timeStr = (Get-Date).ToLongTimeString()
if ((Get-Location -Stack).Count -gt 0) {
$stackStr = "$((Get-Location -Stack).Peek()) +$((Get-Location -Stack).Count - 1)"
}
Write-Host "$timeStr $stackStr" -fore "darkgray"
"$(get-location)> "
}
# Git helpers
function gti() { echo "Vrooom!"; iex "git $args" }
function ga() { git add -A }
function gs() { git status }
function gas() { git add -A; git status }
function gresetunstaged() { git stash -k -u; git stash drop }
function gcp($msg) { git commit -m "$msg"; git push }
function get() { git pull --ff-only }
function upmaster() { git checkout master; git pull --ff-only }
function glog() { clear; git --no-pager log --oneline --graph -n 20 --all --format=format:"%<(60,trunc)%s %Cgreen%<(40,ltrunc)%d%Creset" --date-order; echo "`n" }
function gf() { git fetch --all --prune; glog }
function clean_node() { git clean -xdf -e "node_modules" -e "bower_components" }
function gco($branch) { git checkout --track -b "$branch" "origin/$branch" }
function rev($branch) {
$currentBranch = git rev-parse --abbrev-ref HEAD
if (-not ($currentBranch -eq "master")) { echo "Not on master"; return }
git merge --no-ff --no-commit "origin/$branch"
}
function pullrev($reference){ # Review code in a Gerrit system
if ([string]::IsNullOrEmpty($reference)) {
echo "Reference needed. From Gerrit URL 92115/3 -> refs/changes/15/92115/3`nABCDE -> DE/ABCDE/rev"
return
}
$currentBranch = git rev-parse --abbrev-ref HEAD;
if (-not ($currentBranch -eq "master")) { echo "You need to be on 'master' to review"; return }
git fetch origin $reference;
git merge --no-ff --no-commit FETCH_HEAD;
}
function pushrev() { # send a commit for gerrit review
git push origin HEAD:refs/for/master
}
# Git maintainance
function gdelete_local_merged() {git branch --merged | ?{-not ($_ -like "*master")} | ?{-not ($_.StartsWith("*"))} | %{git branch -d $_.trim()}}
function gdelete_remote_merged($remote) {
git branch -r --merged "$remote/master" |
%{$_.trim()} |
?{$_.StartsWith($remote)} |
?{-not ($_ -match "master")} |
?{-not ($_ -match "HEAD")} |
%{$_.split("/")[1]} |
%{ git push $remote :"$_" }
}
# Nodejs helpers
function cover() { istanbul cover C:\Users\iainb\AppData\Roaming\npm\node_modules\mocha\bin\_mocha -- -R spec }
function buildSingle($moduleName) { gulp compile -p !$moduleName}
function buildTree($moduleName) { gulp compile -p $moduleName}
#Enable-GitColors
$Host.UI.RawUI.ForegroundColor = "white"; $Host.UI.RawUI.BackgroundColor = "black";
cd /
#$__old_path = $env:path
#$env:path += ";${env:ProgramFiles}\Git\bin;${env:ProgramFiles}\Git\usr\bin;" # temp add git-bin to path
#Start-SshAgent -Quiet
#$env:path = $__old_path
#Remove-Variable __old_path
# Chocolatey profile
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
if (Test-Path($ChocolateyProfile)) {
Import-Module "$ChocolateyProfile"
}
# Iain Ballard's profile script for 7digital working.
set-executionpolicy Unrestricted process
Import-Module posh-git
$baseDir = Split-Path -parent $MyInvocation.MyCommand.Definition
. "$baseDir\hand.ps1"
function edit ($file) { & "${env:ProgramFiles(x86)}\Notepad++\notepad++.exe" $file }
function vi ($file) { & "${env:ProgramFiles(x86)}\Vim\vim73\gvim.exe" $file }
function vim ($file) { & "${env:ProgramFiles(x86)}\Vim\vim73\gvim.exe" $file }
function sln { ls -Filter "*.sln" | select -first 1 | %{& ".\$_"} }
function download ($url, $file) {(new-object Net.WebClient).DownloadFile($url, $file)}
function wget ($url) {(new-object Net.WebClient).DownloadString("$url")}
function explore { "explorer.exe $(pwd)" | iex }
function rollback { git reset --hard HEAD; git clean -fd;}
function nuke { git reset --hard HEAD; git reset --hard origin/master; git clean -xdf;}
function sql { runas /netonly /user:7digital\iainb "C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\Ssms.exe"; }
function up() {cd ..;}
function c($loc) {cd $loc; ls;}
function swapd() { # swap between two directories (recreates "pushd +1" from *nix)
if ((Get-Location -Stack).Count -eq 0) {return}
$swapd_a = pwd; popd; $swapd_b = pwd;
cd $swapd_a; pushd $swapd_b
}
# Prompt with directory stack
function prompt {
$prompt_dir_stack = ""
$prompt_cd = "$(Get-Location)"
$host.ui.rawui.WindowTitle = $prompt_cd
if ((Get-Location -Stack).Count -gt 0) {
Write-Host "$((Get-Location -Stack).Peek()) +$((Get-Location -Stack).Count - 1)" -fore gray
}
"$(get-location)> "
}
# Git helpers
function ga() { git add -A }
function gs() { git status }
function gas() { git add -A; git status }
function gcp($msg) { git commit -m "$msg"; git push }
function get() { git pull }
Enable-GitColors
$Host.UI.RawUI.ForegroundColor = $GitPromptSettings.DefaultForegroundColor
$__old_path = $env:path
$env:path += ";${env:ProgramFiles}\Git\bin;${env:ProgramFiles(x86)}\Git\bin" # temp add git-bin to path
Start-SshAgent -Quiet
$env:path = $__old_path
Remove-Variable __old_path
get-psprovider filesystem | %{ $_.Home = "c:\work\" }
cd ~
# Sigma profile
Import-Module W:\Gits\posh-git\posh-git.psm1
set-executionpolicy Unrestricted process
$baseDir = Split-Path -parent $MyInvocation.MyCommand.Definition
. "$baseDir\hand.ps1"
# General actions
function edit ($file) { & "${env:ProgramFiles(x86)}\Notepad++\notepad++.exe" $file }
function vim () { & "${env:ProgramFiles(x86)}\Vim\vim74\gvim.exe" $args }
function sln { ls -Filter "*.sln" | select -first 1 | %{& ".\$_"} }
function explore { "explorer.exe `"$(pwd)`"" | iex }
function wipe { $Host.UI.RawUI.ForegroundColor = "white"; $Host.UI.RawUI.BackgroundColor = "black"; clear; }
function touch ($file) { echo "" >> $file; }
function work { cd "W:\work" }
function love { w:\love\love.exe . }
# Project specific
function plugs { W:\work\Workspaces\PPM\Plugins\Source\PPM.sln }
function dev_ppm { W:\work\Workspaces\PPM\Development\Source\PPMWeb.sln }
function dev_ppm_full { W:\work\Workspaces\PPM\Development\Source\PPM.sln }
function main_ppm { W:\work\Workspaces\PPM\Main\Source\PPMWeb.sln }
function main_cpq { W:\work\Workspaces\CPQ\Main\Source\CPQ.sln }
function dev_mgmt { W:\work\Workspaces\Tribold\SharedServices\Management\Development\Management.sln }
function dev_ident { W:\work\Workspaces\Tribold\SharedServices\Identity\Development\IdentityProvider.sln }
function dev_share_5 { & "W:\work\Workspaces\Shared Code\5.0\Source\Utility\Tribold.Common.sln" }
function dev_share_5srv { & "W:\work\Workspaces\Shared Code\5.0\Source\Service Interface\Tribold.Services\Tribold.Services.sln" }
function dev_inst { W:\work\Workspaces\Tribold\Installers\Installers.sln }
#
# Shell environment
#
function swapd() { # swap between two directories (recreates "pushd +1" from *nix)
if ((Get-Location -Stack).Count -eq 0) {return}
$swapd_a = pwd; popd; $swapd_b = pwd;
cd $swapd_a; pushd $swapd_b
}
set-alias which where.exe
# Prompt with directory stack
function prompt {
$prompt_dir_stack = ""
$prompt_cd = "$(Get-Location)"
$host.ui.rawui.WindowTitle = $prompt_cd
$stackStr = ""
$timeStr = (Get-Date).ToLongTimeString()
if ((Get-Location -Stack).Count -gt 0) {
$stackStr = "$((Get-Location -Stack).Peek()) +$((Get-Location -Stack).Count - 1)"
}
Write-Host "$timeStr $stackStr" -fore "darkgray"
"$(get-location)> "
}
# Git helpers
function gti() { echo "Vrooom!"; iex "git $args" }
function ga() { git add -A }
function gs() { git status }
function gas() { git add -A; git status }
function gresetunstaged() { git stash -k -u; git stash drop }
function gcp($msg) { git commit -m "$msg"; git push }
function get() { git pull --ff-only }
function glog() { clear; git --no-pager log --oneline --graph -n 20 --all --format=format:"%<(60,trunc)%s %Cgreen%<(40,ltrunc)%d%Creset" --date-order; echo "`n" }
function gf() { git fetch --all --prune; glog }
function clean_node() { git clean -xdf -e "node_modules" -e "bower_components" }
function gco($branch) { git checkout --track -b "$branch" "origin/$branch" }
function rev($branch) {
$currentBranch = git rev-parse --abbrev-ref HEAD
if (-not ($currentBranch -eq "master")) { echo "Not on master"; return }
git merge --no-ff --no-commit "origin/$branch"
}
function pullrev($reference){ # Review code in a Gerrit system
if ([string]::IsNullOrEmpty($reference)) {
echo "Reference needed. From Gerrit URL 92115/3 -> refs/changes/15/92115/3`nABCDE -> DE/ABCDE/rev"
return
}
$currentBranch = git rev-parse --abbrev-ref HEAD;
if (-not ($currentBranch -eq "master")) { echo "You need to be on 'master' to review"; return }
git fetch origin $reference;
git merge --no-ff --no-commit FETCH_HEAD;
}
function pushrev() { # send a commit for gerrit review
git push origin HEAD:refs/for/master
}
# Git maintainance
function gdelete_local_merged() {git branch --merged | ?{-not ($_ -like "*master")} | ?{-not ($_.StartsWith("*"))} | %{git branch -d $_.trim()}}
function gdelete_remote_merged($remote) {
git branch -r --merged "$remote/master" |
%{$_.trim()} |
?{$_.StartsWith($remote)} |
?{-not ($_ -match "master")} |
?{-not ($_ -match "HEAD")} |
%{$_.split("/")[1]} |
%{ git push $remote :"$_" }
}
# Nodejs helpers
function cover() { istanbul cover C:\Users\iainb\AppData\Roaming\npm\node_modules\mocha\bin\_mocha -- -R spec }
function buildSingle($moduleName) { gulp compile -p !$moduleName}
function buildTree($moduleName) { gulp compile -p $moduleName}
Enable-GitColors
$Host.UI.RawUI.ForegroundColor = "white"; $Host.UI.RawUI.BackgroundColor = "black";
$__old_path = $env:path
$env:path += ";${env:ProgramFiles}\Git\bin;${env:ProgramFiles}\Git\usr\bin;" # temp add git-bin to path
Start-SshAgent -Quiet
$env:path = $__old_path
Remove-Variable __old_path
set-executionpolicy Unrestricted process
get-psprovider filesystem | %{ $_.Home = "c:\projects\twofour.mediafreedom\" }
cd ~
function edit ($file) { & "C:\Program Files (x86)\Notepad++\notepad++.exe" $file }
function vi ($file) { & "C:\Program Files (x86)\Vim\vim73\vim.exe" $file }
function plat_build { ~\Build\PlatformBuild.bat }
function copy_ingest_files { c:\projects\twofour.mediafreedom\platform\storage\copyexampleingestfiles.bat }
function con_sln { c:\projects\twofour.mediafreedom\platform\contracts\source\contracts.sln }
function man_sln { c:\projects\twofour.mediafreedom\platform\management\source\management.sln }
function pdk_sln { c:\projects\twofour.mediafreedom\platform\services\pdk\source\pdk.sln }
function com_sln { c:\projects\twofour.mediafreedom\platform\admin\command\source\command.sln }
function qry_sln { c:\projects\twofour.mediafreedom\platform\admin\query\source\query.sln }
function dis_sln { c:\projects\twofour.mediafreedom\platform\content\discovery\source\discovery.sln }
function del_sln { c:\projects\twofour.mediafreedom\platform\content\delivery\source\delivery.sln }
function sdk_sln { c:\projects\twofour.mediafreedom\client\sdk\dotnet\source\sdk.sln }
function web_sln { c:\projects\twofour.mediafreedom\client\admin\web\source\web.sln }
function syn_sln { c:\projects\twofour.mediafreedom\client\content\syndication\source\syndication.sln }
$con_dir = "c:\projects\twofour.mediafreedom\platform\contracts\source"
$man_dir = "c:\projects\twofour.mediafreedom\platform\management\source"
$pdk_dir = "c:\projects\twofour.mediafreedom\platform\services\pdk\source"
$com_dir = "c:\projects\twofour.mediafreedom\platform\admin\command\source"
$qry_dir = "c:\projects\twofour.mediafreedom\platform\admin\query\source"
$dis_dir = "c:\projects\twofour.mediafreedom\platform\content\discovery\source"
$del_dir = "c:\projects\twofour.mediafreedom\platform\content\delivery\source"
$sdk_dir = "c:\projects\twofour.mediafreedom\client\sdk\dotnet\source"
$web_dir = "c:\projects\twofour.mediafreedom\client\admin\web\source"
$syn_dir = "c:\projects\twofour.mediafreedom\client\content\syndication\source"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment