mirror of
https://github.com/khodges42/nightShift.git
synced 2026-06-14 10:08:37 +00:00
Add installers and fix path
This commit is contained in:
parent
3616c1155a
commit
71e65a1df4
17
setup.ps1
17
setup.ps1
|
|
@ -31,14 +31,16 @@ function Add-UserPath {
|
||||||
$current = [Environment]::GetEnvironmentVariable("Path", "User")
|
$current = [Environment]::GetEnvironmentVariable("Path", "User")
|
||||||
$parts = @()
|
$parts = @()
|
||||||
if (-not [string]::IsNullOrWhiteSpace($current)) {
|
if (-not [string]::IsNullOrWhiteSpace($current)) {
|
||||||
$parts = $current -split ";" | Where-Object { -not [string]::IsNullOrWhiteSpace($_) }
|
$parts = @($current -split ";" | Where-Object { -not [string]::IsNullOrWhiteSpace($_) })
|
||||||
}
|
}
|
||||||
if ($parts -contains $Directory) {
|
$normalizedParts = @($parts | ForEach-Object { $_.TrimEnd("\") })
|
||||||
|
$normalizedDirectory = $Directory.TrimEnd("\")
|
||||||
|
if ($normalizedParts -contains $normalizedDirectory) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
$newPath = if ($parts.Count -gt 0) { ($parts + $Directory) -join ";" } else { $Directory }
|
$newPath = if ($parts.Count -gt 0) { ($parts + $Directory) -join ";" } else { $Directory }
|
||||||
[Environment]::SetEnvironmentVariable("Path", $newPath, "User")
|
[Environment]::SetEnvironmentVariable("Path", $newPath, "User")
|
||||||
$env:Path = ($env:Path + ";" + $Directory)
|
$env:Path = [Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [Environment]::GetEnvironmentVariable("Path", "User")
|
||||||
}
|
}
|
||||||
|
|
||||||
$repoRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
|
$repoRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||||
|
|
@ -57,12 +59,19 @@ Write-Host "Python: $pythonVersion"
|
||||||
Write-Host "Installing NightShift in editable mode..."
|
Write-Host "Installing NightShift in editable mode..."
|
||||||
python -m pip install -e .
|
python -m pip install -e .
|
||||||
|
|
||||||
$scriptsDir = python -c "import sysconfig; print(sysconfig.get_path('scripts'))"
|
$scriptsDir = python -c "import sysconfig; print(sysconfig.get_path('scripts', scheme='nt_user') or sysconfig.get_path('scripts'))"
|
||||||
$pathParts = $env:Path -split ";" | Where-Object { -not [string]::IsNullOrWhiteSpace($_) }
|
$pathParts = $env:Path -split ";" | Where-Object { -not [string]::IsNullOrWhiteSpace($_) }
|
||||||
if ($pathParts -notcontains $scriptsDir) {
|
if ($pathParts -notcontains $scriptsDir) {
|
||||||
if (Ask-YesNo "Add Python scripts directory to your user PATH so 'nightshift' works in new terminals? $scriptsDir") {
|
if (Ask-YesNo "Add Python scripts directory to your user PATH so 'nightshift' works in new terminals? $scriptsDir") {
|
||||||
Add-UserPath $scriptsDir
|
Add-UserPath $scriptsDir
|
||||||
|
$persistedUserPath = [Environment]::GetEnvironmentVariable("Path", "User")
|
||||||
|
if (($persistedUserPath -split ";" | ForEach-Object { $_.TrimEnd("\") }) -contains $scriptsDir.TrimEnd("\")) {
|
||||||
Write-Host "Added to user PATH: $scriptsDir"
|
Write-Host "Added to user PATH: $scriptsDir"
|
||||||
|
} else {
|
||||||
|
Write-Host "Tried to add PATH entry, but it was not visible in the persisted user PATH."
|
||||||
|
Write-Host "Manual command:"
|
||||||
|
Write-Host "[Environment]::SetEnvironmentVariable('Path', [Environment]::GetEnvironmentVariable('Path','User') + ';$scriptsDir', 'User')"
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Write-Host "Skipped PATH update. You can still run: python -m nightshift.cli"
|
Write-Host "Skipped PATH update. You can still run: python -m nightshift.cli"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
setup.sh
2
setup.sh
|
|
@ -53,7 +53,7 @@ echo "Python: $($PYTHON -c 'import sys; print(f"{sys.version_info.major}.{sys.ve
|
||||||
echo "Installing NightShift in editable mode..."
|
echo "Installing NightShift in editable mode..."
|
||||||
$PYTHON -m pip install -e .
|
$PYTHON -m pip install -e .
|
||||||
|
|
||||||
scripts_dir=$($PYTHON -c 'import sysconfig; print(sysconfig.get_path("scripts"))')
|
scripts_dir=$($PYTHON -c 'import sysconfig, os; print(sysconfig.get_path("scripts", scheme="posix_user") or sysconfig.get_path("scripts"))')
|
||||||
case ":$PATH:" in
|
case ":$PATH:" in
|
||||||
*":$scripts_dir:"*)
|
*":$scripts_dir:"*)
|
||||||
echo "PATH already includes Python scripts directory."
|
echo "PATH already includes Python scripts directory."
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user