XenoMorph616

profile.ps1

Jun 8th, 2023 (edited)
1,084
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Reference: https://stackoverflow.com/a/29806921/7753274
  2.  
  3. # Store the following code in $PROFILE.CurrentUserAllHosts
  4. # Note that the $PROFILE.CurrentUserAllHosts is different for VSCode and Terminal
  5. # Reference: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_profiles?view=powershell-7.3
  6.  
  7. # Run the following command once in PowerShell as Administrator before running this script for the first time
  8. # Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser
  9. # Reference: https://learn.microsoft.com/powershell/module/microsoft.powershell.security/set-executionpolicy?view=powershell-7.3
  10.  
  11. # Reference: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/set-alias?view=powershell-7.3
  12.  
  13. Function NPM-Run {
  14.     param (
  15.         [string]$env = "dev"
  16.     )
  17.     npm run $env
  18. }
  19. Set-Alias -Name run -Value NPM-Run -Description "User defined alias"
  20. Set-Alias -Name d -Value NPM-Run -Description "User defined alias"
  21.  
  22. Function NPM-Install-Prettier-Tailwind {
  23.     npm install -D prettier prettier-plugin-tailwindcss
  24. }
  25. Set-Alias -Name prettier-tailwind -Value NPM-Install-Prettier-Tailwind -Description "User defined alias"
  26.  
  27. Function Vite-Init {
  28.     param (
  29.         [Alias("n")][string]$projectName = ".",
  30.         [Alias("t")][string]$template,
  31.         [switch]$NoInstall
  32.     )
  33.  
  34.     if($template) {
  35.         npm init vite@latest $projectName -- --template $template
  36.     } else {
  37.         npm init vite@latest $projectName
  38.     }
  39.     if(-not $NoInstall) {
  40.         Set-Location $projectName
  41.         npm install
  42.         npm run dev
  43.     }
  44. }
  45. Set-Alias -Name vite -Value Vite-Init -Description "User defined alias"
  46.  
  47. # ============================================================
  48.  
  49. Function Git-Commit {
  50.     param (
  51.         [Parameter(Mandatory, HelpMessage="Enter the commit message.")][string]$message,
  52.         [string]$description = ""
  53.     )
  54.     if($description) {
  55.         git commit -m $message -m $description
  56.     } else {
  57.         git commit -m $message
  58.     }
  59. }
  60. Set-Alias -Name gco -Value Git-Commit -Description "User defined alias"
  61.  
  62. Function Git-Add-and-Commit {
  63.     git add *
  64.     Git-Commit
  65. }
  66. Set-Alias -Name gac -Value Git-Add-and-Commit -Description "User defined alias"
  67.  
  68. # ============================================================
  69.  
  70. Function Create-New-File {
  71.     param (
  72.         [Parameter(Mandatory, HelpMessage="Enter the file path.")][string]$filePath
  73.     )
  74.     if(Test-Path $filePath) {
  75.         Write-Host "$filePath already exists"
  76.     } else {
  77.         New-Item -Path $filePath -ItemType File -Force
  78.     }
  79. }
  80. Set-Alias -Name new -Value Create-New-File -Description "User defined alias"
  81.  
  82. # ============================================================
  83.  
  84. Write-Host "User defined aliases" -NoNewline
  85. $userDefinedAliases = Get-Alias | Where-Object {$_.Description -match "User defined alias"} | Select-Object -Property Name, Definition
  86. $userDefinedAliases
Advertisement
Add Comment
Please, Sign In to add comment