Skip to content

Commit

Permalink
Merge pull request #154 from szymonos/dev
Browse files Browse the repository at this point in the history
Merge dev to main
  • Loading branch information
szymonos authored Apr 29, 2024
2 parents 5137062 + 555b292 commit 6ff423c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 10 deletions.
37 changes: 35 additions & 2 deletions .assets/config/pwsh_cfg/profile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,46 @@ try {
[Environment]::SetEnvironmentVariable('VIRTUAL_ENV_DISABLE_PROMPT', $true)
} catch {
function Prompt {
$split = $($PWD.Path.Replace($HOME, '~').Replace('Microsoft.PowerShell.Core\FileSystem::', '') -replace '\\$').Split([IO.Path]::DirectorySeparatorChar, [StringSplitOptions]::RemoveEmptyEntries)
$execStatus = $?
# get execution time of the last command
if (Get-Command Format-Duration -CommandType Function -ErrorAction SilentlyContinue) {
$executionTime = (Get-History).Count -gt 0 ? (Format-Duration -TimeSpan (Get-History)[-1].Duration) : $null
}
# build current prompt path
$pathString = $PWD.Path.Replace($HOME, '~').Replace('Microsoft.PowerShell.Core\FileSystem::', '') -replace '\\$'
$split = $pathString.Split([IO.Path]::DirectorySeparatorChar, [StringSplitOptions]::RemoveEmptyEntries)
$promptPath = if ($split.Count -gt 3) {
[string]::Join('/', $split[0], '..', $split[-1])
} else {
[string]::Join('/', $split)
}
return "`e[1;32m{0}@{1}`e[0m: `e[1;34m$promptPath`e[0m> " -f $env:USER, ($env:HOSTNAME ?? $env:WSL_DISTRO_NAME)
# run elevated indicator
if ((id -u) -eq 0) {
[Console]::Write("`e[91m#`e[0m ")
}
# write last execution time
if ($executionTime) {
[Console]::Write("[`e[93m$executionTime`e[0m] ")
}
# write last execution status
[Console]::Write("$($PSStyle.Bold){0}`u{2192} ", $execStatus ? $PSStyle.Foreground.BrightGreen : $PSStyle.Foreground.BrightRed)
# write prompt path
[Console]::Write("`e[1;94m$promptPath`e[0m ")
# write git branch/status
if ($GitPromptSettings) {
# get git status
$gitStatus = @(git status -b --porcelain=v2 2>$null)[1..4]
if ($gitStatus) {
# get branch name and upstream status
$branch = $gitStatus[0].Split(' ')[2] + ($gitStatus[1] -match 'branch.upstream' ? $null : " `u{21E1}")
# format branch name color depending on working tree status
[Console]::Write(
"`e[38;2;232;204;151m({0}$branch`e[38;2;232;204;151m) ",
($gitStatus | Select-String -Pattern '^(?!#)' -Quiet) ? "`e[38;2;255;146;72m" : "`e[38;2;212;170;252m"
)
}
}
return '{0}{1} ' -f ($PSStyle.Reset, '>' * ($nestedPromptLevel + 1))
}
}
#endregion
4 changes: 2 additions & 2 deletions .assets/scripts/linux_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ for sc in ${scope_arr[@]}; do
done
# install powershell modules
if [ -f /usr/bin/pwsh ]; then
cmd="Import-Module (Resolve-Path './modules/InstallUtils'); Invoke-GhRepoClone -OrgRepo 'szymonos/ps-modules'"
cloned=$(pwsh -nop -c $cmd)
cmnd="Import-Module (Resolve-Path './modules/InstallUtils'); Invoke-GhRepoClone -OrgRepo 'szymonos/ps-modules'"
cloned=$(pwsh -nop -c $cmnd)
if [ $cloned -gt 0 ]; then
printf "\e[96minstalling ps-modules...\e[0m\n"
# install do-common module for all users
Expand Down
10 changes: 6 additions & 4 deletions modules/InstallUtils/Functions/git.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,26 @@ function Invoke-GhRepoClone {
Function for updating current git branch from remote.
#>
function Update-GitRepository {
[CmdletBinding()]
param ()
# perform check if the repository has remote
$remote = git remote 2>$null
if ($remote) {
# fetch updates from remote
Write-Host "fetching $remote..."
Write-Verbose "fetching $remote..."
git fetch --tags --prune --prune-tags --force $remote
# check if current branch is behind remote
$branch = git branch --show-current
if ((git rev-parse HEAD) -ne (git rev-parse "$remote/$branch")) {
Write-Host "$branch branch is behind the $remote, performing hard reset"
Write-Verbose "$branch branch is behind the $remote, performing hard reset"
git reset --hard "$remote/$branch"
return 2
} else {
Write-Host "$branch branch is up to date"
Write-Verbose "$branch branch is up to date"
return 1
}
} else {
Write-Host 'Not a git repository.'
Write-Warning 'Not a git repository.'
return 0
}
}
2 changes: 1 addition & 1 deletion modules/InstallUtils/InstallUtils.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'InstallUtils.psm1'

# Version number of this module.
ModuleVersion = '0.3.0'
ModuleVersion = '0.3.1'

# Supported PSEditions
CompatiblePSEditions = @('Core', 'Desk')
Expand Down
3 changes: 2 additions & 1 deletion wsl/wsl_setup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,15 @@ process {
zsh { $scopes.Add('shell') | Out-Null }
}
# determine 'oh_my_posh' scope
if ($chk.omp -or $OmpTheme) {
if ($lx.Version -eq 2 -and ($chk.omp -or $OmpTheme)) {
@('oh_my_posh', 'shell').ForEach({ $scopes.Add($_) | Out-Null })
}
# remove scopes unavailable in WSL1
if ($lx.Version -eq 1) {
$scopes.Remove('distrobox') | Out-Null
$scopes.Remove('docker') | Out-Null
$scopes.Remove('k8s_ext') | Out-Null
$scopes.Remove('oh_my_posh') | Out-Null
}
# display distro name and installed scopes
Write-Host "`n`e[95;1m${Distro}$($scopes.Count ? " :`e[0;90m $($scopes -join ', ')`e[0m" : "`e[0m")"
Expand Down

0 comments on commit 6ff423c

Please sign in to comment.