Skip to content

Instantly share code, notes, and snippets.

@mrreband
Last active April 29, 2023 02:42
Show Gist options
  • Save mrreband/ab9f362b25a19fd59bab2b62b2696141 to your computer and use it in GitHub Desktop.
Save mrreband/ab9f362b25a19fd59bab2b62b2696141 to your computer and use it in GitHub Desktop.
##################################################################
# standard directory functions
function mcd ($path) {
mkdir $path
chdir $path
}
function rmrf ($path) {
rm -r -force $path
}
##################################################################
# virtualenv stuff
Remove-Item alias:\cd
function cd ($path) {
if ($path -eq "..")
{
if (test-path ".\venv\Scripts\activate.ps1") {
echo "deactivating"
deactivate
}
}
chdir $path
if (test-path ".\venv\Scripts\activate.ps1") {
echo "activating"
& ".\venv\Scripts\activate.ps1"
}
}
function find_venv ($path) {
if ((resolve-path($path)).Path.length -eq 3) { return "" }
if (!(test-path($path))) { return "" }
if (test-path("$path\venv"))
{
$files = (ls -R $path venv)
return $files[0]
}
else
{
return find_venv("$path\..")
}
}
function activate {
$venv_path = (find_venv(".")).FullName
if (test-path ($venv_path)) { &"$venv_path\Scripts\activate.ps1" } else { echo "no venv" }
}
function deactivate {./venv/Scripts/Deactivate}
##################################################################
# repo stuff
function gitrepo () {
$gitConfigUrl = git config --get remote.origin.url
start chrome.exe $gitConfigUrl
}
function github () { gitrepo }
function gists () { start chrome.exe "https://gist.github.com/mrreband" }
function gitprofile () { start chrome.exe "https://github.com/mrreband" }
function gb() {
$branch = git branch --show-current
git branch --set-upstream-to=origin/$branch $branch
}
function gitmaster() {
git checkout master
$pullOutput = git pull --prune
echo "pullOutput: "
echo $pullOutput
$deletedBranches = $pullOutput | Select-String "deleted"
foreach($deletedBranchLine in $deletedBranches)
{
$deletedBranchContent = $deletedBranchLine -split "\"
$deletedBranch = $deletedBranchContent[1]
git branch -d $deletedBranch
}
}
function gitmain() {
git checkout main
git pull --prune
}
##################################################################
# app alias
new-alias -Name "psql" "${env:ProgramFiles}\PostgreSQL\12\bin\psql.exe"
new-alias -Name "conda" "c:\users\mr\MiniConda3\Scripts\conda.exe"
new-alias -Name "openssl" "D:\OneDrive\Programs\openssl-1.0.2q-x64_86-win64\openssl.exe"
new-alias -Name ".." "cd .."
function rmnode {
rmrf .\node_modules
if ( test-path("yarn.lock") ) { rm yarn.lock }
if ( test-path("package-lock.json")) { rm package-lock.json}
}
function np ($file) { & "notepad.exe" $file }
function npp ($file) { & "${env:ProgramFiles}\Notepad++\Notepad++.exe" $file }
function pc { & "${env:ProgramFiles}\JetBrains\PyCharm 2020.2.1\bin\pycharm64.exe ." }
function charm { & "${env:ProgramFiles}\JetBrains\PyCharm 2020.2.1\bin\pycharm64.exe ." }
function e { explorer.exe . }
function c { code . }
function psql($params) { & "${env:ProgramFiles}\PostgreSQL\12\bin\psql.exe" $params }
function gccp ($filePath) { & gsutil -m cp gs://thearthouse-webapp.appspot.com/$filePath . }
##################################################################
# node scripts
function livesite () { firebase open hosting:site }
function fbl {
clear
firebase functions:log -n 68
}
function fbs {
clear
npm run serve
}
function fbd {
clear
npm run deploy
}
function yd {
clear
yarn windev
}
function yl {
clear
yarn winlocal
}
function ys {
clear
yarn serve
}
##################################################################
# hue stuff
function hue ($group, $scene) {
if ($group -eq "lr") { $groups = 1,4 }
else { $groups = ,$group }
$infoItems = "lights", "scenes"
$test = $scene -as [int]
foreach ($grp in $groups) {
if ($infoItems -like $scene) {
python C:\Users\mr\source\repos\hue4u\hue4u\cmd-hue4u.py --group $grp --info $scene
} elseif ($test -ne $null) {
python C:\Users\mr\source\repos\hue4u\hue4u\cmd-hue4u.py --group $grp --bri $scene
}
else {
python C:\Users\mr\source\repos\hue4u\hue4u\cmd-hue4u.py --group $grp --scene $scene
}
}
}
##################################################################
# path alias
$OneDriveRoot = "D:\OneDrive"
function onedrive { set-location $OneDriveRoot }
function reaper { set-location "$OneDriveRoot\Music\Reaper Projects" }
function nasa { set-location "$OneDriveRoot\NASA" }
$UserRoot = "C:\Users\mr"
function mr { set-location $UserRoot }
function docs { set-location "$UserRoot\Documents" }
function soundcloud { set-location "D:\OneDrive\Music\Mr. Reband\Soundcloud" }
# repo shortcuts
$RepoRoot = "$UserRoot\source\repos"
function repos {
cd $RepoRoot
ls
}
function proto { cd "$RepoRoot\prototype" }
function rsc { cd "$RepoRoot\react\reactsc" }
function robinhood { cd "$RepoRoot\puzzles and parsing\robinhood" }
function azul { cd "$RepoRoot\azul" }
function art { cd "$RepoRoot\thearthouse_us" }
function artpy { cd "$RepoRoot\thearthouse_us\arthouse_resources" }
function artapi { cd "$RepoRoot\thearthouse_us\thearthouse_api" }
function artapp { cd "$RepoRoot\thearthouse_us\thearthouse_app" }
function cpmidi { cd "$RepoRoot\puzzles and parsing\cp-midi" }
function hue4u { cd "$RepoRoot\hue4u" }
function vmp { cd "$RepoRoot\magnetic-poetry" }
function fonts { cd "$OneDriveRoot\Programs\fonts" }
# config shortcuts
function profile { npp "$UserRoot\Documents\WindowsPowershell\Microsoft.PowerShell_profile.ps1" }
function psprofile { npp "$UserRoot\Documents\WindowsPowershell\Microsoft.PowerShell_profile.ps1" }
function psconfig { npp "$UserRoot\Documents\WindowsPowershell\Microsoft.PowerShell_profile.ps1" }
function ahk { np "$UserRoot\Documents\AutoHotKey.ahk" }
function gitconfig { npp "$UserRoot\.gitconfig" }
function hosts { npp "c:\windows\system32\drivers\etc\hosts" }
# import modules
Import-Module posh-git
# recursive grep
function grep ($filter, $searchstring) { ls -r $filter | select-string $searchstring }
# touch
function touch {set-content -Path ($args[0]) -Value ($null)}
# misc
function kill-process ($procName) {
$process = Get-Process procName -ErrorAction SilentlyContinue
if ($process) {
# try gracefully first
$process.CloseMainWindow()
# kill after five seconds
Sleep 5
if (!$process.HasExited) {
$process | Stop-Process -Force
}
}
}
function get-special-folders {
$SpecialFolders = @{}
$names = [Environment+SpecialFolder]::GetNames([Environment+SpecialFolder])
foreach($name in $names)
{
if($path = [Environment]::GetFolderPath($name)){
$SpecialFolders[$name] = $path
}
}
echo($SpecialFolders)
}
function sql-connect ($server, $database, $pscred)
{
if (!$pscred) { Get-Credential }
$userName = $pscred.UserName
$password = $pscred.GetNetworkCredential().Password
$connectionString = 'Data Source={0};database={1};User ID={2};Password={3}' -f $ServerName,$DatabaseName,$userName,$password
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection $connectionString
return $sqlConnection
}
function restart-explorer {
taskkill /f /im explorer.exe
explorer.exe
}
# init
clear-host
$ErrorActionPreference = "Stop"
# not sure why, but cmder is not honoring this path even though it's set in system environment variables
$Env:path += ";C:\Windows\system32;C:\Windows;C:\Windows\system32\WindowsPowerShell\v1.0\"
# 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