Skip to content

Instantly share code, notes, and snippets.

@yzorg
Last active Feb 2, 2020
Embed
What would you like to do?
Added $gitbin
echo "START [$($MyInvocation.MyCommand.Name)] $(get-date -f yyyyMMdd.HHmmss.ff)"
try {
#$env:Path += ";.\node_modules\.bin" # use npmx instead (v8.2+ / npm 5.3+)
sal code "C:\Program Files\Microsoft VS Code\Code.exe"
# cd to the first directory in the path that contains a program, script, or file
filter goWhere { where.exe $args | select -first 1 | Split-Path -Parent | pushd }
#filter goWhereCD { where.exe $args | select -first 1 | Split-Path -Parent | cd }
filter up { cd "../$args" }
filter up2 { cd "../../$args" }
filter up3 { cd "../../../$args" }
filter up4 { cd "../../../../$args" }
filter pup { pushd "../$args" }
filter pup2 { pushd "../../$args" }
filter pup3 { pushd "../../../$args" }
filter pup4 { pushd "../../../../$args" }
filter yz-GetLocationStack { Get-Location -Stack }
sal dirs yz-GetLocationStack
filter pops { Write-Warning '--- OBSOLETE ---, use `dirs` instead'; dirs $args }
sal w where.exe # powershell pre-defines where to be 'SQL-like' where for filtering sets or streams,
sal which where.exe # *nix-friendly
# https://ss64.com/ps/syntax-elevate.html
# returns true/false
function ss64-IsAdmin {
([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
}
sal isadmin ss64-IsAdmin
# Admin starts at C:\Windows\System32, try to fix that
if (isadmin) { pushd ~; return; }
$gitbin = 'C:\Program Files\Git\usr\bin'
if (Test-Path -PathType Container $gitbin) {
echo " adding git aliases at $gitbin"
$global:gitbin = $gitbin
# TODO: convert to list (DRY: don't repeat code)
sal du.exe $gitbin\du.exe
# use: `file.exe --mime-encoding *`
sal file.exe $gitbin\file.exe
sal tail.exe $gitbin\tail.exe
} else {
Write-Warning "git aliases skipped b/c git bin not at $gitbin"
Remove-Variable gitbin
}
# `pushd` to a folder at startup, usually the project I'm actively working on...
# echo 'pushd D:\user-Chris.Tracy\MarketMaking-js-test' >> $PROFILE.CurrentUserAllHosts\..\profile_pushd.ps1
$optionalPsScript="$PSScriptRoot\profile_pushd.ps1"
if (!(Test-Path $optionalPsScript)) { return; }
. $optionalPsScript
}
finally {
echo "END [$($MyInvocation.MyCommand.Name)] $(get-date -f yyyyMMdd.HHmmss.ff)"
}
return;
#
# # Links
#
# timestamps for filenames / comments, my Gist (yzorg)
# http://htmlpreview.github.io/?https://gist.github.com/yzorg/bbffec29c7d350d2635b/raw
#
# to search just your own Gists on github:
# user:yzorg profile
# https://gist.github.com/search?q=user%3Ayzorg+profile&ref=searchresults
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment