|
@@ -0,0 +1,86 @@
|
|
|
+#!/usr/bin/env pwsh
|
|
|
+param (
|
|
|
+ [Parameter(Mandatory=$true)][string]$Action,
|
|
|
+ [Parameter(Mandatory=$true)][string]$Package,
|
|
|
+ [string]$Target
|
|
|
+)
|
|
|
+
|
|
|
+$ErrorActionPreference = "Stop"
|
|
|
+
|
|
|
+
|
|
|
+$stow = "Write-Output" # For debugging
|
|
|
+#$stow = "./park.ps1"
|
|
|
+
|
|
|
+# Default to current directory if not set
|
|
|
+$DOTFILES_DIR = $env:DOTFILES_DIR
|
|
|
+if (-not $DOTFILES_DIR) {
|
|
|
+ $DOTFILES_DIR = (Get-Location).Path
|
|
|
+}
|
|
|
+
|
|
|
+function ActionToArg {
|
|
|
+ param ([string]$action)
|
|
|
+ switch ($action) {
|
|
|
+ "remove" { return "--delete" }
|
|
|
+ "update" { return "--restow" }
|
|
|
+ "apply" { return "--stow" }
|
|
|
+ default { return $null }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function TargetToDest {
|
|
|
+ param ([string]$target)
|
|
|
+ switch ($target) {
|
|
|
+ "user" { return $env:HOME }
|
|
|
+ "system" { return "/" }
|
|
|
+ default { return $null }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function Invoke-Stow {
|
|
|
+ param (
|
|
|
+ [string]$StowDir,
|
|
|
+ [string]$TargetDir,
|
|
|
+ [string]$StowAction,
|
|
|
+ [string]$StowPackage
|
|
|
+ )
|
|
|
+ & $stow -d $StowDir -t $TargetDir $StowAction $StowPackage
|
|
|
+}
|
|
|
+
|
|
|
+$actionArg = ActionToArg $Action
|
|
|
+if (-not $actionArg) {
|
|
|
+ Write-Host "No such action: $Action"
|
|
|
+ exit 1
|
|
|
+}
|
|
|
+
|
|
|
+if ($Target) {
|
|
|
+ $packageTargetPath = Join-Path -Path "$DOTFILES_DIR/$Package" -ChildPath $Target
|
|
|
+ if (Test-Path $packageTargetPath -PathType Container) {
|
|
|
+ $dest = TargetToDest $Target
|
|
|
+ Invoke-Stow -StowDir "$DOTFILES_DIR/$Package" -TargetDir $dest -StowAction $actionArg -StowPackage $Target
|
|
|
+ }
|
|
|
+ elseif ($Target -ne "user") {
|
|
|
+ Write-Host "Target '$Target' does not exist for package '$Package'"
|
|
|
+ exit 1
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $dest = TargetToDest "user"
|
|
|
+ Invoke-Stow -StowDir $DOTFILES_DIR -TargetDir $dest -StowAction $actionArg -StowPackage $Package
|
|
|
+ }
|
|
|
+}
|
|
|
+else {
|
|
|
+ $any = $false
|
|
|
+ foreach ($t in "user", "system") {
|
|
|
+ $path = "$DOTFILES_DIR/$Package/$t"
|
|
|
+ if (Test-Path $path -PathType Container) {
|
|
|
+ $any = $true
|
|
|
+ $dest = TargetToDest $t
|
|
|
+ Invoke-Stow -StowDir "$DOTFILES_DIR/$Package" -TargetDir $dest -StowAction $actionArg -StowPackage $t
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (-not $any) {
|
|
|
+ $dest = TargetToDest "user"
|
|
|
+ Invoke-Stow -StowDir $DOTFILES_DIR -TargetDir $dest -StowAction $actionArg -StowPackage $Package
|
|
|
+ }
|
|
|
+}
|
|
|
+
|