Skip to content

Instantly share code, notes, and snippets.

@byBretema
Created August 17, 2020 07:34
Show Gist options
  • Save byBretema/0c307a740e69294ea51dd30651680a58 to your computer and use it in GitHub Desktop.
Save byBretema/0c307a740e69294ea51dd30651680a58 to your computer and use it in GitHub Desktop.
Microsoft PowerShell Profile
# Write with <3 by Dac (@cambalamas)
Import-Module posh-git
Import-Module oh-my-posh
Set-Theme Zash
# ENV
$PERSONALPATH = "${env:SystemDrive}\dac"
$DEVPATH = "$PERSONALPATH\dev"
$env:PATH += ";`
${env:ProgramFiles}\VCG\MeshLab\;`
${env:userprofile}\scoop\apps\xming\current;`
${env:ProgramFiles(x86)}\Google\Chrome` Dev\Application;`
${env:SystemDrive}\Qt\5.14.2\msvc2017_64\bin;`
$PERSONALPATH\.bin;`
"
# Remove aliases of 'gow' (https://github.com/bmatzelle/gow)
@("awk", "basename", "bash", "bc", "bison", "bunzip2", "bzip2", "bzip2recover", "cat", "chgrp", "chmod", "chown", "chroot", "cksum", "clear", "cp", "csplit", "curl", "cut", "dc", "dd", "df", "diff", "diff3", "dirname", "dos2unix", "du", "egrep", "env", "expand", "expr", "factor", "fgrep", "flex", "fmt", "fold", "gawk", "gfind", "gow", "grep", "gsar", "gsort", "gzip", "head", "hostid", "hostname", "id", "indent", "install", "join", "jwhois", "less", "lesskey", "ln", "ls", "m4", "make", "md5sum", "mkdir", "mkfifo", "mknod", "mv", "nano", "ncftp", "nl", "od", "pageant", "paste", "patch", "pathchk", "plink", "pr", "printenv", "printf", "pscp", "psftp", "putty", "puttygen", "pwd", "rm", "rmdir", "scp", "sdiff", "sed", "seq", "sftp", "sha1sum", "shar", "sleep", "split", "ssh", "su", "sum", "sync", "tac", "tail", "tar", "tee", "test", "touch", "tr", "uname", "unexpand", "uniq", "unix2dos", "unlink", "unrar", "unshar", "uudecode", "uuencode", "vim", "wc", "wget", "whereis", "which", "whoami", "xargs", "yes", "zip") | ForEach-Object { if (Test-Path alias:$_) { Remove-Item -Force alias:$_ } }
Remove-Item alias:cls
function clear { Clear-Host }
# MOVE
function dev { Set-Location "$DEVPATH" }
function k { Clear-Host; Get-ChildItem $args }
function ho { Set-Location $env:userprofile }
remove-item alias:md
function md { New-Item -ItemType Directory $args[0]; Set-Location $args[0] }
function b ([int]$jumps) { for ( $i = 0; $i -lt $jumps; $i++) { Set-Location .. } }
function oo { if ($args) { explorer $args[0] } else { explorer (Get-Location).Path } }
function lns([string]$to, [string]$from) { New-Item -Path "$to" -ItemType SymbolicLink -Value "$from" -Force }
# SYS
# remove-item alias:rm
function l { ls -ALph $args }
function ll { ls -ALphog $args }
function hrm { Remove-Item -Force -Recurse }
function devices { mmc devmgmt.msc }
function me { net user ${env:UserName} }
function ke { Stop-Process (Get-Process explorer).id }
function noff { shutdown /a }
function off { shutdown /hybrid /s /t $($args[0] * 60) }
function bitLock { sudo manage-bde.exe -lock $args[0] }
function bitUnlock { sudo manage-bde.exe -unlock $args[0] -pw }
function bg { Start-Process powershell -NoNewWindow "-Command $args" }
function iconFind ([String]$icon) { for ($i = 0; $i -le 65535; $i++) { if ( [char]$i -eq $icon ) { Write-Host $i } } }
function top {
Clear-Host
$saveY = [console]::CursorTop
$saveX = [console]::CursorLeft
while ($true) {
Get-Process | Sort-Object -Descending CPU | Select-Object -First 30
Start-Sleep -Seconds 2
[console]::setcursorposition($saveX, $saveY + 3)
}
}
function du {
Get-ChildItem $pwd | ForEach-Object {
$name = $_
Get-ChildItem -r $_.FullName | measure-object -property length -sum |
Select-Object `
@{ Name = "Name"; Expression = { $name } },
@{ Name = "Sum (MB)"; Expression = { "{0:N3}" -f ($_.sum / 1MB) } },
@{ Name = "Sum(Bytes)"; Expression = { $_.sum } }
} | Sort-Object "Sum(Bytes)" -desc
}
function sudop {
sudo powershell
}
# NET
function s { Start-Process "https://www.google.com/search?q=$($args -join '+')" }
function netinfo {
$pub = $(curl.exe -s icanhazip.com)
$privW = $((Get-NetAdapter "Wi-Fi" | Get-NetIPAddress).IPAddress[1])
Write-Host "IP (U/R): $pub / $privW"
Write-Host "(8.8.8.8) time: $((ping 8.8.8.8)[11])"
Write-Host "(www.google.es) time: $((ping www.google.es)[11])"
Write-Host "(www.google.com) time:$((ping www.google.com)[11])"
}
# ========================================================================== #
# DOCKER
function x11 { xming -ac -multiwindow -clipboard }
function whale { if ($args) { x11; docker run -v "$((Get-Location).path):/app" -e DISPLAY=$(display) -it $args } }
function display { (Get-NetAdapter "vEthernet (DockerNAT)" | Get-NetIPAddress -AddressFamily "IPv4").IPAddress + ":0" 2> $null }
# GIT
function gst { git status -sb }
function glg { git log --graph --oneline --decorate }
function qgp { if ($args) { git add -A; git commit -m "$args"; git push } }
function qgfp { git init; git add -A; git commit -m "first commit"; git remote add origin $args[0]; git push -u origin master }
function loc { if ($args[0]) { (Get-ChildItem * -recurse -include *.$($args[0]) | Get-Content | Measure-Object -Line).Lines } }
# ========================================================================== #
# FIX UPDATES
function fixWindowsUpdate {
#* Tasks
@("usbceip", "microsoft", "consolidator", "silentcleanup",
"dmclient", "scheduleddefrag", "office", "adobe") | ForEach-Object {
$(Get-ScheduledTask -TaskName "*$_*") | ForEach-Object {
Disable-ScheduledTask $_ 2> $null
}
}
#* Services
@("DiagTrack", "PcaSvc", "dmwappushservice") | ForEach-Object {
Set-Service $_ -StartupType Disabled
}
#* Not allow telemetry
New-ItemProperty -path "hklm:\SOFTWARE\Policies\Microsoft\Windows\DataCollection" -name "AllowTelemetry " -PropertyType DWORD -value 0 -Force
}
# ========================================================================== #
# Avoid duplicates
Set-PSReadLineOption -HistoryNoDuplicates:$True
# Do not use UserProfile as main folder
if ($PWD.Path -eq ${env:UserProfile}) { Set-Location "$env:SystemDrive\dac" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment