Skip to content

Instantly share code, notes, and snippets.

@markembling
Last active May 25, 2023 07:07
Show Gist options
  • Save markembling/8213df3c802b7a0470a549caad2ade60 to your computer and use it in GitHub Desktop.
Save markembling/8213df3c802b7a0470a549caad2ade60 to your computer and use it in GitHub Desktop.
Current Powershell Profile
#########################################
# Convenient PowerShell Alias functions #
#########################################
# Open the given directory in Explorer
# Usage: open .
function open {
explorer $args
}
# Sublime Text
Set-Alias subl 'C:\Program Files\Sublime Text 3\sublime_text.exe'
# 'git status' alias function
function gs {
git status $args
}
# Python commands
# Use the python 3.x launcher to launch the latest python 2.x and
# the latest python 3.x versions.
function python2 { py -2 $args }
function python3 { py -3 $args }
function python {
# If we're in a venv, just execute whatever python we should
# otherwise launch the latest python 2 using the launcher
if (Test-Path variable:global:VIRTUAL_ENV) {
python.exe $args
} else {
python2 $args
}
}
# Simulate the touch command from *nix
# Usage: touch foo.txt
function touch {
[void](new-item -type file $args)
}
# Create a dummy file with the given name of the given size in MB
# Usage: dummy test.foo 5 -- Create a file of 5MB called test.foo.
function dummy {
$size = $args[1] * 1024 * 1024
fsutil file createnew $args[0] $size
}
Push-Location (Split-Path -Path $MyInvocation.MyCommand.Definition -Parent)
# Load posh-git module from current directory
Import-Module ./posh-git/posh-git
$global:GitPromptSettings.ShowStatusWhenZero = $FALSE
$global:GitPromptSettings.BeforeText = '(git) '
$global:GitPromptSettings.AfterText = ' '
# Set up a simple prompt, adding the git prompt parts inside git repos
function prompt {
$path = $pwd | Get-Item
$currentDateTime = (Get-Date).ToString('dd/MM/yyyy HH:mm:ss')
$userLocation = $env:username + '@' + [System.Environment]::MachineName + ' ' + $path
Write-Host($currentDateTime) -foregroundcolor DarkGray #DarkGreen
Write-Host($userLocation) -foregroundcolor DarkGray #Green
# Git Prompt
Write-VcsStatus
# Set the title
$host.UI.RawUi.WindowTitle = $path.Name
$global:LASTEXITCODE = $realLASTEXITCODE
Write-Host('>') -nonewline -foregroundcolor Green
return " "
}
Enable-GitColors
Start-SshAgent -Quiet
# Include aliases
. ./aliases.ps1
Pop-Location
# Path stuff
$env:PATH += ';' + $env:HOME + '\Documents\My Dropbox\Scripts'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment