Skip to content

Instantly share code, notes, and snippets.

@NONONOexe
Last active May 25, 2025 00:20
Show Gist options
  • Select an option

  • Save NONONOexe/0492efc0de90f34eb6bb158dc199e0ee to your computer and use it in GitHub Desktop.

Select an option

Save NONONOexe/0492efc0de90f34eb6bb158dc199e0ee to your computer and use it in GitHub Desktop.
My PowerShell settings
#--------------------------------------------------------------------------
# PowerShell Profile Settings
#--------------------------------------------------------------------------
# This file is located at '~/OneDrive/documents/PowerShell/Microsoft.PowerShell_profile.ps1'
# (typically pointed to by the $PROFILE variable in a standard PowerShell console).
# By placing settings here and using OneDrive, they can be loaded when
# PowerShell is launched and shared across multiple devices.
#--------------------------------------------------------------------------
# Custom Aliases
#--------------------------------------------------------------------------
# Alias: grep
# Purpose: Provides grep-like text searching functionality.
# Maps to: Select-String (PowerShell's native text search cmdlet).
# Usage: grep "pattern" file.txt
# Get-Content file.txt | grep "pattern"
# Note: By default, Select-String is case-insensitive.
# Use 'grep "Pattern" file.txt -CaseSensitive' for case-sensitive search.
Set-Alias -Name grep -Value Select-String -Description "Alias for Select-String (grep-like)" -Option AllScope
# Alias: ogp (Open Git Page)
# Purpose: Opens the remote repository URL of the current Git directory.
# Maps to: Function 'Open-GitPage'.
Set-Alias -Name ogp -Value Open-GitPage -Description "Opens the remote Git repository page (Open-GitPage)" -Option AllScope
# Alias: ep (Edit Profile)
# Purpose: Opens this PowerShell profile script for editing.
# Maps to: Function 'Edit-Profile'.
Set-Alias -Name ep -Value Edit-Profile -Description "Opens the current PowerShell profile for editing" -Option AllScope
#--------------------------------------------------------------------------
# Custom Functions
#--------------------------------------------------------------------------
# Function: Open-GitPage
# Purpose: Opens the remote repository URL of the current Git directory in the default web browser.
function Open-GitPage {
try {
$remoteUrl = git remote get-url origin
if ($remoteUrl) {
Start-Process $remoteUrl
} else {
Write-Warning "Could not determine remote 'origin' URL. Are you in a Git repository with a remote configured?"
}
}
catch {
Write-Warning "Error executing 'git remote get-url origin'. Make sure Git is installed and you are in a Git repository."
}
}
# Function: Edit-Profile
# Purpose: Opens the PowerShell profile script in the preferred editor.
function Edit-Profile {
edit $PROFILE
}
#--------------------------------------------------------------------------
# Shell Customization (Oh My Posh)
#--------------------------------------------------------------------------
# Initializes Oh My Posh for a customized prompt.
# Ensure Oh My Posh is installed and the theme path is correct.
oh-my-posh --init --shell pwsh --config ~/AppData/Local/Programs/oh-my-posh/themes/peru.omp.json | Invoke-Expression
#--------------------------------------------------------------------------
# Profile Load Confirmation
#--------------------------------------------------------------------------
Write-Host "Custom PowerShell profile loaded successfully." -ForegroundColor Green
Write-Host "Available custom commands include: 'grep', 'ep' (Edit-Profile), 'ogp' (Open-GitPage)." -ForegroundColor Cyan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment