Skip to content

Commit

Permalink
swap message for icon when checking for updates 💫 (#7)
Browse files Browse the repository at this point in the history
* add logic for setting an env var based on git

* test remote change

* fix bugs, update env var names

* clean up

* Update readme.md
  • Loading branch information
scottmckendry authored Feb 16, 2024
1 parent 766b733 commit 239785c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 51 deletions.
44 changes: 14 additions & 30 deletions Profile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -76,29 +76,7 @@ function Find-WindotsRepository {
$profileSymbolicLink = Get-ChildItem $ProfilePath | Where-Object FullName -EQ $PROFILE.CurrentUserAllHosts
return Split-Path $profileSymbolicLink.Target
}
function Get-LatestProfile {
<#
.SYNOPSIS
Checks the Github repository for the latest commit date and compares to the local version.
If the profile is out of date, instructions are displayed on how to update it.
#>

Write-Verbose "Checking for updates to the profile"
$currentWorkingDirectory = $PWD
Set-Location $ENV:WindotsLocalRepo
$gitStatus = git status

if ($gitStatus -like "*Your branch is up to date with*") {
Write-Verbose "Profile is up to date"
Set-Location $currentWorkingDirectory
return
}
else {
Write-Verbose "Profile is out of date"
Write-Host "Your PowerShell profile is out of date with the latest commit. To update it, run Update-Profile." -ForegroundColor Yellow
Set-Location $currentWorkingDirectory
}
}
function Start-AdminSession {
<#
.SYNOPSIS
Expand Down Expand Up @@ -137,7 +115,7 @@ function Update-Software {
#>
Write-Verbose "Updating software installed via Winget & Chocolatey"
Start-Process wezterm -Verb runAs -WindowStyle Hidden -ArgumentList "start -- pwsh -Command &{winget upgrade --all && choco upgrade all -y}"
$ENV:UpdatesPending = ''
$ENV:SOFTWARE_UPDATE_AVAILABLE = ""
}

function Find-File {
Expand Down Expand Up @@ -309,8 +287,17 @@ $ENV:STARSHIP_CONFIG = "$ENV:WindotsLocalRepo\starship\starship.toml"
$ENV:_ZO_DATA_DIR = $ENV:WindotsLocalRepo
$ENV:OBSIDIAN_PATH = "$HOME\iCloudDrive\iCloud~md~obsidian\Obsidian"

# Check for Git updates while prompt is loading
Start-Job -ScriptBlock { Set-Location $ENV:WindotsLocalRepo && git fetch --all } | Out-Null
# Check for Windots and software updates while prompt is loading
Start-ThreadJob -ScriptBlock {
Set-Location -Path $ENV:WindotsLocalRepo
$gitUpdates = git fetch && git status
if ($gitUpdates -match "behind") {
$ENV:DOTFILES_UPDATE_AVAILABLE = "`u{db86}`u{dd1b} "
}
else {
$ENV:DOTFILES_UPDATE_AVAILABLE = ""
}
} | Out-Null

Add-ProfileLogEntry -Message "Git fetch job started"

Expand All @@ -324,10 +311,10 @@ Start-ThreadJob -ScriptBlock {
$wingetUpdatesString = Start-Job -ScriptBlock { winget list --upgrade-available | Out-String } | Wait-Job | Receive-Job
$chocoUpdatesString = Start-Job -ScriptBlock { choco upgrade all --noop | Out-String } | Wait-Job | Receive-Job
if ($wingetUpdatesString -match "upgrades available" -or $chocoUpdatesString -notmatch "can upgrade 0/") {
$ENV:UpdatesPending = "`u{eb29} "
$ENV:SOFTWARE_UPDATE_AVAILABLE = "`u{eb29} "
}
else {
$ENV:UpdatesPending = ""
$ENV:SOFTWARE_UPDATE_AVAILABLE = ""
}
} | Out-Null

Expand All @@ -340,9 +327,6 @@ Invoke-Expression (& { ( zoxide init powershell --cmd cd | Out-String ) })

Add-ProfileLogEntry -Message "Prompt setup complete"

# Check for updates
Get-LatestProfile

$enableLog ? $stopwatch.Stop() : $null
Add-ProfileLogEntry -Message "Profile load complete"

8 changes: 4 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<p align="center">
<p align="center">
<a href="https://scottmckendry.tech">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://scottmckendry.tech/img/logo/icon2transparent.png">
Expand Down Expand Up @@ -27,9 +27,9 @@ My personal Windows-friendly dotfiles. Supports automatic installation of depend

## 🎉 Features
- **Automated Dependency Installation:** Utilises [Winget](https://learn.microsoft.com/en-us/windows/package-manager/winget/) and [Chocolatey](https://chocolatey.org/) for streamlined installation of required dependencies. Checks and notifies pending software updates with a 📦 icon in the prompt.
- **Automated Update Checks:** Regularly checks for updates using git. If updates are pending, a notification is displayed when starting a new PowerShell session.

![image](https://github.com/scottmckendry/Windots/assets/39483124/89598017-6315-4054-ae56-be1f827c32a4)
- **Automated Update Checks:** Regularly checks for updates using git. If updates are pending, an icon is displayed when starting a new PowerShell session.
![image](https://github.com/scottmckendry/Windots/assets/39483124/e84d0294-5662-4d7c-b1ae-88a1f26ca9fd)

- **Centralized Configuration:** Brings together scattered Windows configuration files into one organized location for easy access and management.
- **Tailored Colour Scheme:** Powered by my very own [CYBERDREAM](https://github.com/scottmckendry/cyberdream.nvim) colourscheme - high-contrast and vibrant for optimal _Eye Stimulation™_.
Expand Down
40 changes: 23 additions & 17 deletions starship/starship.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,38 @@
add_newline = false

[character]
success_symbol = "[❯](bold green)"
error_symbol = "[ ](bold red)"
success_symbol = "[❯](bold green)"
error_symbol = "[ ](bold red)"

[cmd_duration]
min_time = 200
show_milliseconds = true
min_time = 200
show_milliseconds = true

[golang]
symbol = ""
symbol = ""

[nodejs]
detect_extensions = []
detect_extensions = []

[git_metrics]
disabled = false
format = '(([ $added]($added_style)) ([ $deleted]($deleted_style)) )'
only_nonzero_diffs = true
disabled = false
format = '(([ $added]($added_style)) ([ $deleted]($deleted_style)) )'
only_nonzero_diffs = true

[line_break]
disabled = true
disabled = true

[jobs]
disabled = true

[env_var.UpdatesPending]
variable = 'UpdatesPending'
format = '[$env_value]($style)'
default = ''
style = 'bold cyan'
disabled = true

[env_var.SOFTWARE_UPDATE_AVAILABLE]
variable = 'SOFTWARE_UPDATE_AVAILABLE'
format = '[$env_value]($style)'
default = ''
style = 'bold cyan'

[env_var.DOTFILES_UPDATE_AVAILABLE]
variable = 'DOTFILES_UPDATE_AVAILABLE'
format = '[$env_value]($style)'
default = ''
style = 'bold cyan'

0 comments on commit 239785c

Please sign in to comment.