Skip to content

Instantly share code, notes, and snippets.

@watamario15
Last active November 9, 2023 04:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save watamario15/df219d6d51e7772f144d01d773c4e34a to your computer and use it in GitHub Desktop.
Save watamario15/df219d6d51e7772f144d01d773c4e34a to your computer and use it in GitHub Desktop.
Minimal PowerShell settings.
chcp 65001
[console]::outputEncoding=[text.encoding]::getEncoding("utf-8")
function prompt {
if ($? -eq $true) {
write-host '✓ ' -foregroundColor cyan -noNewline
} else {
write-host '× ' -foregroundColor red -noNewline
}
write-host $env:COMPUTERNAME -foregroundColor green -noNewline
write-host ':' -noNewline
$cwd = $(get-location).providerPath
if ($cwd.startsWith($env:USERPROFILE)) {
$cwd = '~' + $cwd.substring(($env:USERPROFILE).length)
}
$i = $cwd.length - 1
$cnt = 0
while ($true) {
if ($i -lt 0) {
write-host $cwd -foregroundColor blue -noNewline
return '$ '
}
if ($cwd[$i] -eq '/' -or $cwd[$i] -eq '\') {
++$cnt
if ($cnt -ge 2) {
if ($i -gt 0) {
$result=$cwd.substring($i)
break;
}
}
}
--$i
}
$j = 0
$cnt = 0
if (($cwd[0] -eq '\' -and $cwd[1] -eq '\') -or ($cwd[0] -eq '/' -and $cwd[1] -eq '/')) {
$j = 1
}
while ($true) {
if ($j -ge $i) {
write-host $cwd -foregroundColor blue -noNewline
return '$ '
}
if ($cwd[$j] -eq '/' -or $cwd[$j] -eq '\') {
++$cnt
if ($cnt -ge 2) {
if ($j -lt $i) {
write-host ($cwd.substring(0, $j + 1) + "..." + $result) -foregroundColor blue -noNewline
return '$ '
}
}
}
++$j
}
}
remove-item alias:gc -force 2> $null
remove-item alias:gm -force 2> $null
remove-item alias:gp -force 2> $null
remove-item alias:gps -force 2> $null
function ga() { git add $args }
function gd() { git diff $args }
function gr() { git rebase $args }
function gs() { git status $args }
function gpl() { git pull origin $args }
function gps() {
$result = @()
$isForcePush = $false
foreach ($item in $args) {
if ($item -eq "-f") {
$isForcePush = $true
} else {
$result += $item
}
}
if ($isForcePush) {
write-host "Invoking 'git push --force-if-includes --force-with-lease $result'"
$key = (read-host "Are you sure? [y/N]")
if ($key -ne "y") { return }
git push --force-if-includes --force-with-lease $result
} else {
git push origin $result
}
}
function gb() { git branch $args }
function gsw() { git switch $args }
function grs() { git restore $args }
function gf() { git fetch origin $args }
function gc() { git commit $args }
function gm() { git merge $args }
function gt() { git log --graph --all --format='%as %C(cyan bold)%an%Creset %C(yellow)%h%Creset %C(green reverse)%d%Creset %s' }
function ..() { set-location ../ }
function ...() { set-location ../.. }
function ....() { set-location ../../.. }
function pkgi() { winget install $args }
function pkgr() { winget uninstall $args }
function pkgu() { winget upgrade $args }
function pkgs() { winget search $args }
function pkgif() { winget show $args }
function editrc() { code $profile.currentUserAllHosts }
function pwdc() { set-clipboard $(get-location) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment