Skip to content

Instantly share code, notes, and snippets.

@vitormateusalmeida
Last active September 2, 2025 20:54
Show Gist options
  • Save vitormateusalmeida/9ebc1c3c5b1e489d2270981934a03388 to your computer and use it in GitHub Desktop.
Save vitormateusalmeida/9ebc1c3c5b1e489d2270981934a03388 to your computer and use it in GitHub Desktop.
Powershell profile with custom functions
# Import the Chocolatey Profile that contains the necessary code to enable
# tab-completions to function for `choco`.
# Be aware that if you are missing these lines from your profile, tab completion
# for `choco` will not function.
# See https://ch0.co/tab-completion for details.
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
if (Test-Path($ChocolateyProfile)) {
Import-Module "$ChocolateyProfile"
}
$MaximumHistoryCount = 20000
Import-Module posh-git
Import-Module PSReadLine
Import-Module Get-ChildItemColor
Import-Module Terminal-Icons
Import-Module DockerCompletion
# Uses tab for autocompletion
Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete
# History definitions
$HistoryFilePath = Join-Path ([Environment]::GetFolderPath('UserProfile')) .ps_history
Register-EngineEvent PowerShell.Exiting -Action { Get-History | Export-Clixml $HistoryFilePath } | out-null
if (Test-path $HistoryFilePath) { Import-Clixml $HistoryFilePath | Add-History }
Set-PSReadLineOption -HistorySearchCursorMovesToEnd
Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward
Set-PSReadLineOption -ShowToolTips
Set-PSReadLineOption -PredictionSource History
oh-my-posh init pwsh --config ~\oh-my-posh-themes\rudolfs-dark.omp.json | Invoke-Expression
Import-Module -Name Terminal-Icons
### Go to folder functions #######################################
function GoToProjectsFolder {cd 'C:\projects\'}
New-Alias -Force -Name cdproj -Value GoToProjectsFolder
function GoToCredzFolder {cd 'C:\projects\credz\'}
New-Alias -Force -Name cdcredz -Value GoToCredzFolder
function GoToAnimaFolder {cd 'C:\projects\anima\'}
New-Alias -Force -Name cdanima -Value GoToAnimaFolder
function GoToAnimaFrontFolder {cd 'C:\projects\anima\aprendizagem\servico-novo-extensao-frontend\'}
New-Alias -Force -Name cdanimafront -Value GoToAnimaFrontFolder
function GoToAnimaExercer {cd 'C:\projects\anima\exercer\'}
New-Alias -Force -Name cdexercer -Value GoToAnimaExercer
function GoToAnimaUlife {cd 'C:\GitUlife\'}
New-Alias -Force -Name cdulife -Value GoToAnimaUlife
##################################################################
function GitStatus {git status}
New-Alias -Force -Name gst -Value GitStatus
function GitRemote {git remote -v}
New-Alias -Force -Name remote -Value GitRemote
New-Alias -Force -Name gr -Value GitRemote
function GitCheckoutDevelop {git checkout develop}
New-Alias -Force -Name checkdev -Value GitCheckoutDevelop
function GitCheckoutDevelop {git checkout develop}
New-Alias -Force -Name checkdev -Value GitCheckoutDevelop
function DeleteFolder([string]$folder)
{
Remove-Item "$folder" -Force -Recurse
Write-Host "Directory " -ForegroundColor DarkGreen -NoNewline
Write-Host "$folder" -BackgroundColor DarkGreen -ForegroundColor Black -NoNewline
Write-Host " removed" -ForegroundColor DarkGreen
}
New-Alias -Force -Name rm -Value DeleteFolder
function PrettyPrintJson {
param(
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
$json
)
$json | ConvertFrom-Json | ConvertTo-Json -Depth 100
}
New-Alias -Force -Name format-json -Value PrettyPrintJson
function CopyItem([string]$origFolder, [string]$destFolder) {
Copy-Item -Path "$origFolder" -Destination "$destFolder" -Force -Verbose -Recurse
}
New-Alias -Force -Name cpy -Value CopyItem
function GitAdd([string]$path) {
git add --verbose $path
}
New-Alias -Force -Name ga -Value GitAdd
function GitRestoreStaged([string]$path) {
git restore --staged $path
}
New-Alias -Force -Name grs -Value GitRestoreStaged
New-Alias -Force -Name restore -Value GitRestoreStaged
function GitRestoreDiscard([string]$path) {
git restore $path
}
New-Alias -Force -Name grd -Value GitRestoreDiscard
function GitCommitMessage([string]$message) {
git commit -m $message
}
function CommtWithCommitzen() {
git cz
}
New-Alias -Force -Name commit -Value CommtWithCommitzen
function NPMBuild([string]$mode = "desenvolvimento") {
npx vue-tsc --build --force && npx vite build -m $mode
}
New-Alias -Force -Name buildproj -Value NPMBuild
New-Alias -Force -Name buildthis -Value NPMBuild
# Dracula readline configuration. Requires version 2.0, if you have 1.2 convert to `Set-PSReadlineOption -TokenType`
Set-PSReadlineOption -Color @{
"Command" = [ConsoleColor]::Green
"Parameter" = [ConsoleColor]::Gray
"Operator" = [ConsoleColor]::Magenta
"Variable" = [ConsoleColor]::White
"String" = [ConsoleColor]::Yellow
"Number" = [ConsoleColor]::Blue
"Type" = [ConsoleColor]::Cyan
"Comment" = [ConsoleColor]::DarkCyan
}
# Dracula Prompt Configuration
Import-Module posh-git
$GitPromptSettings.DefaultPromptPrefix.Text = "$([char]0x2192) " # arrow unicode symbol
$GitPromptSettings.DefaultPromptPrefix.ForegroundColor = [ConsoleColor]::Green
$GitPromptSettings.DefaultPromptPath.ForegroundColor =[ConsoleColor]::Cyan
$GitPromptSettings.DefaultPromptSuffix.Text = "$([char]0x203A) " # chevron unicode symbol
$GitPromptSettings.DefaultPromptSuffix.ForegroundColor = [ConsoleColor]::Magenta
# Dracula Git Status Configuration
$GitPromptSettings.BeforeStatus.ForegroundColor = [ConsoleColor]::Blue
$GitPromptSettings.BranchColor.ForegroundColor = [ConsoleColor]::Blue
$GitPromptSettings.AfterStatus.ForegroundColor = [ConsoleColor]::Blue
Set-Alias notepad++ "C:\Program Files\Notepad++\notepad++.exe"
######################################################################################################
# Function para deletar branchs a partir de um prefixo
function Remove-GitBranchesByPrefix {
[CmdletBinding(SupportsShouldProcess=$true)]
param(
[Parameter(Mandatory = $true, Position=0)]
[string]$Prefix,
# Usa git branch -D (forçado). Sem isso usa -d (seguro).
[switch]$Force,
# Inclui a branch atual na remoção (por padrão, pula a atual).
[switch]$IncludeCurrent
)
# Lista todas as branches locais
$branches = git for-each-ref --format="%(refname:short)" refs/heads/
# Filtra as que começam com o prefixo informado (independente de ter / ou não)
$branches = $branches | Where-Object { $_ -like "$Prefix*" }
if (-not $branches -or $branches.Count -eq 0) {
Write-Host "Nenhuma branch local iniciando com '$Prefix' encontrada."
return
}
$current = (git rev-parse --abbrev-ref HEAD).Trim()
$toDelete = @()
foreach ($b in $branches) {
if (-not $IncludeCurrent -and $b -eq $current) {
Write-Host "Pulando a branch atual '$b'."
continue
}
$toDelete += $b
}
if (-not $toDelete -or $toDelete.Count -eq 0) {
Write-Host "Nada para deletar."
return
}
Write-Host "Branches a remover:"
$toDelete | ForEach-Object { Write-Host " - $_" }
$flag = ($Force.IsPresent) ? "-D" : "-d"
foreach ($b in $toDelete) {
if ($PSCmdlet.ShouldProcess("branch '$b'", "git branch $flag $b")) {
Write-Host "Removendo '$b'..."
git branch $flag $b
}
}
Write-Host "Concluído."
}
# Atalho
New-Alias -Force -Name gdelprefix -Value Remove-GitBranchesByPrefix
# Ver só o que seria deletado:
# gdelprefix feature/ -WhatIf
# Deletar de forma segura (usa -d, falha se não estiver mergeada):
# gdelprefix feature/
# Deletar de forma forçada:
# gdelprefix feature/ -Force
# Incluir a branch atual na remoção (cuidado!):
# gdelprefix feature/ -Force -IncludeCurrent
######################################################################################################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment