From 05a5f6523d8c28c1e26009fdd81dd03c80b69d5f Mon Sep 17 00:00:00 2001 From: F5T3 Date: Tue, 16 Jul 2024 10:23:50 +0200 Subject: [PATCH] Sent local PowerShell profile updates to GitHub --- .gitignore | 4 ++ Microsoft.PowerShell_profile.ps1 | 6 +- README.md | 20 ++++++ setup.ps1 | 120 +++++++++++++++++++++++++++++++ 4 files changed, 147 insertions(+), 3 deletions(-) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 setup.ps1 diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..15c9ab06 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ + +*.zip +*.ttf +oldprofile.ps1 diff --git a/Microsoft.PowerShell_profile.ps1 b/Microsoft.PowerShell_profile.ps1 index ca76d817..28919d93 100644 --- a/Microsoft.PowerShell_profile.ps1 +++ b/Microsoft.PowerShell_profile.ps1 @@ -108,10 +108,10 @@ function ff($name) { } # Network Utilities -function Get-PubIP { (Invoke-WebRequest http://ifconfig.me/ip).Content } +function PubIP { (Invoke-WebRequest http://ifconfig.me/ip).Content } # System Utilities -function uptime { +function Uptime { if ($PSVersionTable.PSVersion.Major -eq 5) { Get-WmiObject win32_operatingsystem | Select-Object @{Name='LastBootUpTime'; Expression={$_.ConverttoDateTime($_.lastbootuptime)}} | Format-Table -HideTableHeaders } else { @@ -119,7 +119,7 @@ function uptime { } } -function Sync-Profile { +function Sync { & "$PROFILE | Split-Path\sync.ps1" } diff --git a/README.md b/README.md new file mode 100644 index 00000000..972d26f0 --- /dev/null +++ b/README.md @@ -0,0 +1,20 @@ +# 🎨 PowerShell Profile (Pretty PowerShell) + +A stylish and functional PowerShell profile that looks and feels almost as good as a Linux terminal. + +## ⚡ One Line Install (Administrator PowerShell Recommended) + +Execute the following command in an elevated PowerShell window to install the PowerShell profile: + +``` +irm "https://github.com/F5T3/powershell-profile/raw/main/setup.ps1" | iex +``` + +## 🛠️ Fix the Missing Font + +After running the script, you'll find a downloaded `cove.zip` file in the folder you executed the script from. Follow these steps to install the required nerd fonts: + +1. Extract the `cove.zip` file. +2. Locate and install the nerd fonts. + +Now, enjoy your enhanced and stylish PowerShell experience! 🚀 diff --git a/setup.ps1 b/setup.ps1 new file mode 100644 index 00000000..95b0f421 --- /dev/null +++ b/setup.ps1 @@ -0,0 +1,120 @@ +# Ensure the script can run with elevated privileges +if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { + Write-Warning "Please run this script as an Administrator!" + break +} + +# Function to test internet connectivity +function Test-InternetConnection { + try { + $testConnection = Test-Connection -ComputerName www.google.com -Count 1 -ErrorAction Stop + return $true + } + catch { + Write-Warning "Internet connection is required but not available. Please check your connection." -ForegroundColor Yellow + return $false + } +} + +# Check for internet connectivity before proceeding +if (-not (Test-InternetConnection)) { + break +} + +# Profile creation or update +if (!(Test-Path -Path $PROFILE -PathType Leaf)) { + try { + # Detect Version of PowerShell & Create Profile directories if they do not exist. + $profilePath = "" + if ($PSVersionTable.PSEdition -eq "Core") { + $profilePath = "$env:userprofile\Documents\Powershell" + } + elseif ($PSVersionTable.PSEdition -eq "Desktop") { + $profilePath = "$env:userprofile\Documents\WindowsPowerShell" + } + + if (!(Test-Path -Path $profilePath)) { + New-Item -Path $profilePath -ItemType "directory" + } + + Invoke-RestMethod https://github.com/F5T3/powershell-profile/raw/main/Microsoft.PowerShell_profile.ps1 -OutFile $PROFILE + Write-Host "The profile @ [$PROFILE] has been created." -ForegroundColor Green + Write-Host "If you want to add any persistent components, please do so at [$profilePath\Profile.ps1] as there is an updater in the installed profile which uses the hash to update the profile and will lead to loss of changes" -ForegroundColor Yellow + } + catch { + Write-Error "Failed to create or update the profile. Error: $_" -ForegroundColor red + } +} +else { + try { + Get-Item -Path $PROFILE | Move-Item -Destination "oldprofile.ps1" -Force + Invoke-RestMethod https://github.com/F5T3/powershell-profile/raw/main/Microsoft.PowerShell_profile.ps1 -OutFile $PROFILE + Write-Host "The profile @ [$PROFILE] and has replace the old profile." -ForegroundColor Green + Write-Host "Please back up any persistent components of your old profile to [$HOME\Documents\PowerShell\Profile.ps1] as there is an updater in the installed profile which uses the hash to update the profile and will lead to loss of changes" -ForegroundColor Yellow + } + catch { + Write-Error "Failed to backup and update the profile. Error: $_" -ForegroundColor Red + } +} + +# Font Install +try { + [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") + $fontFamilies = (New-Object System.Drawing.Text.InstalledFontCollection).Families.Name + + if ($fontFamilies -notcontains "RobotoMono Nerd Font") { + $webClient = New-Object System.Net.WebClient + $webClient.DownloadFileAsync((New-Object System.Uri("https://github.com/ryanoasis/nerd-fonts/releases/download/v3.2.1/RobotoMono.zip")), ".\RobotoMono.zip") + + while ($webClient.IsBusy) { + Start-Sleep -Seconds 2 + } + + Expand-Archive -Path ".\RobotoMono.zip" -DestinationPath ".\RobotoMono" -Force + $destination = (New-Object -ComObject Shell.Application).Namespace(0x14) + Get-ChildItem -Path ".\RobotoMono" -Recurse -Filter "*.ttf" | ForEach-Object { + If (-not(Test-Path "C:\Windows\Fonts\$($_.Name)")) { + $destination.CopyHere($_.FullName, 0x10) + } + } + + Remove-Item -Path ".\RobotoMono" -Recurse -Force + Remove-Item -Path ".\RobotoMono.zip" -Force + } +} +catch { + Write-Error "Failed to download or install the Roboto Mono Nerd Font. Error: $_" -ForegroundColor Red +} + +# Final check and message to the user +if ((Test-Path -Path $PROFILE) -and (winget list --name "OhMyPosh" -e) -and ($fontFamilies -contains "RobotoMono Nerd Font")) { + Write-Host "Setup completed successfully. Please restart your PowerShell session to apply changes." -ForegroundColor Green +} else { + Write-Warning "Setup completed with errors. Please check the error messages above." +} +#Install packages +try { + $packages = @("Zoxide", "Starship", "Neovim", "Terminal-Icon", "Neofetch", "Everything", "EverythingToolbar", "Docker", "GlazeWM", "OhMyPosh", "Chocolatey", "Shell") + $missingPackages = @() + + foreach ($package in $packages) { + $packageInfo = winget list --id $package + + if (-not $packageInfo) { + $missingPackages += $package + } + } + + if ($missingPackages.Count -eq 0) { + Write-Host "The apps are already installed" -ForegroundColor Green + } else { + foreach ($packageName in $missingPackages) { + winget install --id $packageName + } + $installed = ($missingPackages -join ", ") -replace ",([^,]+)$"," and`$1" + Write-Host "The apps, $installed got installed" -ForegroundColor Green + } +} +catch { + Write-Error "Failed to download or install the apps. Error: $_" -ForegroundColor Red +}