persona

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

setup.ps1 (8063B)


      1 <#
      2 .SYNOPSIS
      3     PCのセットアップを自動化します(Nushell + Alacritty環境用)。
      4 .DESCRIPTION
      5     このPowerShellスクリプトは、以下のセットアップ処理を実行します:
      6     - Windowsテーマのダークモードへの変更
      7     - パフォーマンス向上のための視覚効果の無効化
      8     - タスクバー時計への秒表示の有効化
      9     - 高速スタートアップの無効化
     10     - システムサウンドの無効化
     11     - 最新のwinget JSON構成ファイルを使ったアプリケーションのインストール
     12     - 外部設定リポジトリ(Nushell, Zed等)のクローンとセットアップ
     13 .NOTES
     14     このスクリプトは管理者権限で実行する必要があります。
     15     PowerShellプロファイルやshortcuts PATHの追加は、Nushellへの移行に伴い廃止されました。
     16 #>
     17 
     18 # スクリプトが管理者として実行されているか確認
     19 if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))
     20 {
     21     Write-Warning "このスクリプトは管理者権限が必要です。管理者として再起動します..."
     22     # 管理者としてスクリプトを再実行
     23     Start-Process pwsh -Verb RunAs -ArgumentList "-NoProfile -File `"$PSCommandPath`""
     24     exit
     25 }
     26 
     27 # スクリプトの場所を基準に動作するようにカレントディレクトリを変更
     28 $scriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
     29 Set-Location -Path $scriptRoot
     30 
     31 Write-Host "PCセットアップスクリプトを開始します..." -ForegroundColor Green
     32 Write-Host "------------------------------------------------------------"
     33 
     34 # 1. Set system and apps to Dark Mode
     35 try
     36 {
     37     Write-Host "[1/7] Windowsとアプリのテーマをダークモードに設定しています..." -ForegroundColor Cyan
     38     $regPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize"
     39     # 0 = Dark, 1 = Light
     40     Set-ItemProperty -Path $regPath -Name "AppsUseLightTheme" -Value 0 -ErrorAction Stop
     41     Set-ItemProperty -Path $regPath -Name "SystemUsesLightTheme" -Value 0 -ErrorAction Stop
     42     Write-Host "  テーマをダークモードに設定しました。"
     43 } catch
     44 {
     45     Write-Error "ダークモードへの設定に失敗しました: $_"
     46 }
     47 
     48 # 2. パフォーマンスのために視覚効果を無効化
     49 try
     50 {
     51     Write-Host "[2/7] 視覚効果をパフォーマンス優先に設定しています..." -ForegroundColor Cyan
     52     $regPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\VisualEffects"
     53     Set-ItemProperty -Path $regPath -Name "VisualFxSetting" -Value 2 -ErrorAction Stop
     54     Write-Host "  視覚効果を「パフォーマンスを優先する」に設定しました。"
     55 } catch
     56 {
     57     Write-Error "視覚効果の無効化に失敗しました: $_"
     58 }
     59 
     60 # 3. タスクバーの時計に秒を表示
     61 try
     62 {
     63     Write-Host "[3/7] タスクバーの時計に秒を表示する設定を有効にしています..." -ForegroundColor Cyan
     64     $regPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
     65     if (-not (Test-Path $regPath))
     66     {
     67         New-Item -Path $regPath -Force | Out-Null
     68     }
     69     Set-ItemProperty -Path $regPath -Name "ShowSecondsInSystemClock" -Value 1 -ErrorAction Stop
     70     Write-Host "  タスクバーの時計に秒が表示されるようになります。"
     71 } catch
     72 {
     73     Write-Error "時計の秒表示設定に失敗しました: $_"
     74 }
     75 
     76 # 4. 高速スタートアップを無効化
     77 try
     78 {
     79     Write-Host "[4/7] 高速スタートアップを無効化しています..." -ForegroundColor Cyan
     80     $regPath = "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Power"
     81     Set-ItemProperty -Path $regPath -Name "HiberbootEnabled" -Value 0 -ErrorAction Stop
     82     Write-Host "  高速スタートアップを無効化しました。"
     83 } catch
     84 {
     85     Write-Error "高速スタートアップの無効化に失敗しました: $_"
     86 }
     87 
     88 # 5. システムサウンドを無効化
     89 try
     90 {
     91     Write-Host "[5/7] システムサウンドを無効化しています..." -ForegroundColor Cyan
     92     $schemePath = "HKCU:\AppEvents\Schemes"
     93     Set-ItemProperty -Path $schemePath -Name "(Default)" -Value ".None" -ErrorAction Stop
     94     Write-Host "  サウンド設定を「サウンドなし」に変更しました。"
     95 } catch
     96 {
     97     Write-Error "システムサウンドの無効化に失敗しました: $_"
     98 }
     99 
    100 # 6. 最新のwinget JSONファイルからパッケージをインストール
    101 try
    102 {
    103     Write-Host "[6/7] Wingetによるアプリケーションのインストールを開始します..." -ForegroundColor Cyan
    104     $latestWingetFile = Get-ChildItem -Path ".\winget" -Filter "winget-*.json" | Sort-Object Name -Descending | Select-Object -First 1
    105     if ($latestWingetFile)
    106     {
    107         Write-Host "  最新の構成ファイルが見つかりました: $($latestWingetFile.Name)"
    108         Write-Host "  インポートを開始します。完了まで時間がかかる場合があります..."
    109         winget import -i $latestWingetFile.FullName --accept-package-agreements --accept-source-agreements
    110     } else
    111     {
    112         Write-Warning "  'winget-*.json' ファイルが見つかりませんでした。アプリケーションのインストールをスキップします。"
    113     }
    114 } catch
    115 {
    116     Write-Error "Wingetでのアプリケーションインストールに失敗しました: $_"
    117 }
    118 
    119 # 7. 外部設定リポジトリのセットアップ
    120 try
    121 {
    122     Write-Host "[7/7] 外部設定リポジトリ(Nushell / Zed等)をセットアップしています..." -ForegroundColor Cyan
    123 
    124     # gh (GitHub CLI) がインストールされているか確認
    125     if (-not (Get-Command gh -ErrorAction SilentlyContinue))
    126     {
    127         Write-Warning "  gh CLIが見つかりません。Wingetでのインストールを先に完了させてください。"
    128     } else
    129     {
    130         $configRepos = @(
    131             @{ Name = "zed"; Path = "$env:APPDATA\Zed"; Branch = "main" },
    132             @{ Name = "nushell"; Path = "$env:APPDATA\nushell"; Branch = "main" },
    133             @{ Name = "alacritty"; Path = "$env:APPDATA\alacritty"; Branch = "windows" },
    134             @{ Name = "starship"; Path = "$env:HOME\.config\starship"; Branch = "main" },
    135             @{ Name = "zellij"; Path = "$env:APPDATA\zellij"; Branch = "main" },
    136             @{ Name = "helix"; Path = "$env:APPDATA\helix"; Branch = "windows" }
    137         )
    138 
    139         foreach ($repo in $configRepos)
    140         {
    141             if (-not (Test-Path $repo.Path))
    142             {
    143                 Write-Host "  $($repo.Name) をクローンしています..."
    144                 gh repo clone "minerva-jupiter/$($repo.Name)" $repo.Path
    145 
    146                 # 指定のブランチに切り替え
    147                 if (Test-Path $repo.Path)
    148                 {
    149                     Push-Location $repo.Path
    150                     git switch $($repo.Branch)
    151                     Pop-Location
    152                     Write-Host "  $($repo.Name) ($($repo.Branch) branch) のセットアップが完了しました。"
    153                 }
    154             } else
    155             {
    156                 Write-Host "  $($repo.Name) は既に存在します。スキップします。" -ForegroundColor Yellow
    157             }
    158         }
    159     }
    160 } catch
    161 {
    162     Write-Error "リポジトリのセットアップ中にエラーが発生しました: $_"
    163 }
    164 
    165 Write-Host "------------------------------------------------------------"
    166 Write-Host "セットアップスクリプトが完了しました。" -ForegroundColor Green
    167 Write-Host "UI関連の変更を適用するためにExplorerを再起動します。" -ForegroundColor Yellow
    168 Stop-Process -Name explorer -Force
    169 Write-Host "すべての変更を確実に適用するために、コンピューターの再起動を推奨します。" -ForegroundColor Yellow