Skip to content

Instantly share code, notes, and snippets.

@maksha
Last active July 25, 2017 07:48
Show Gist options
  • Save maksha/cff3de229c4a2df201af5ac1bbabbd91 to your computer and use it in GitHub Desktop.
Save maksha/cff3de229c4a2df201af5ac1bbabbd91 to your computer and use it in GitHub Desktop.
Posh-Git PowerShell Prompt
# Import module posh-git
Import-Module -Name posh-git
# Setup awesome PS prompt
function Test-Administrator {
$user = [Security.Principal.WindowsIdentity]::GetCurrent();
(New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
# Chocolatey profile
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
if (Test-Path($ChocolateyProfile)) {
Import-Module "$ChocolateyProfile"
}
function prompt {
$realLASTEXITCODE = $LASTEXITCODE
Write-Host
# Reset color, which can be messed up by Enable-GitColors
$Host.UI.RawUI.ForegroundColor = $GitPromptSettings.DefaultForegroundColor
if (Test-Administrator) { # Use different username if elevated
Write-Host "(Elevated) " -NoNewline -ForegroundColor White
}
Write-Host " $ENV:USERNAME " -NoNewline -ForegroundColor White -BackgroundColor DarkGray
if ($s -ne $null) { # color for PSSessions
Write-Host " (`$s: " -NoNewline -ForegroundColor DarkGray
Write-Host "$($s.Name)" -NoNewline -ForegroundColor Yellow
Write-Host ") " -NoNewline -ForegroundColor DarkGray
}
Write-Host "" $($(Get-Location) -replace ($env:USERPROFILE).Replace('\','\\'), "~") "" -NoNewline -ForegroundColor Black -BackgroundColor Gray
$global:LASTEXITCODE = $realLASTEXITCODE
Write-Host
Write-Host " " ($([char]0x2192)) " " -NoNewline -BackgroundColor DarkGray
Write-VcsStatus
return "> "
}
@maksha
Copy link
Author

maksha commented Dec 23, 2016

Note

OOT: Get Public IP Address using PowerShell

The powershell command below will get our public IP address from https://api.ipify.org in JSON format.

#
# Tested using PowerShell 5.1.14393.576
#
C:\> ((Invoke-WebRequest https://api.ipify.org?format=json).Content.Trim() | ConvertFrom-Json).psobject.Properties

MemberType      : NoteProperty
IsSettable      : True
IsGettable      : True
Value           : 10.10.10.10   # This is your public IP address
TypeNameOfValue : System.String
Name            : ip
IsInstance      : True


# Get the Value and copy it to clipboard
C:\> ((Invoke-WebRequest https://api.ipify.org?format=json).Content.Trim() | ConvertFrom-Json).psobject.Properties.Value | clip

@maksha
Copy link
Author

maksha commented Dec 23, 2016

Custom PowerShell prompt with Git status:

image

@maksha
Copy link
Author

maksha commented Jan 4, 2017

rm -fr in PowerShell

To delete all files and folders (including subfolders) in .\node_modules\:

  1. Delete files in folder and subfolders: Get-ChildItem -Path .\node_modules\ -Recurse | Remove-Item -force -recurse
  2. Delete folders and subfolders: Remove-Item .\node_modules\ -Force

@maksha
Copy link
Author

maksha commented Jan 12, 2017

LICEcap

http://www.cockos.com/licecap/

A simple animated screen captures * LICEcap can capture an area of your desktop and save it directly to .GIF.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment