diff --git a/README.org b/README.org index 2527765..379849a 100644 --- a/README.org +++ b/README.org @@ -104,6 +104,28 @@ By symlinking you can easily update Chemacs with a =git pull=. Chemacs is not available on ELPA/MELPA because its special position in the Emacs boot process would cause a chicken and egg problem. +There's a similar script for Windows called =install.sh=. + +#+BEGIN_SRC powershell +$ git clone https://github.com/plexus/chemacs.git +$ cd chemacs +$ .\install.ps1 +OK copying file to ~/.emacs +#+END_SRC + +The Windows script copies the ~/.emacs file rather than symlinking it, as +symlinks in Windows require elevated privileges. To update the file, run +=install.ps1= a second time, if necessary - it uses hashing to detect +changes and prompts for conformation before overwriting + +#+BEGIN_SRC powershell +$ .\install.ps1 +WARN content is different between C:\Users\Me\.emacs and C:\Users\Me\repos\chemacs\.emacs +WARN chemacs may already be installed OR something else may be in the way +Do you want to overwrite C:\Users\Me\.emacs?: y +OK updated chemacs files successfully. +#+END_SRC + ** Usage Chemacs adds an extra command line option to Emacs, =--with-profile=. Profiles diff --git a/install.ps1 b/install.ps1 new file mode 100644 index 0000000..6d34756 --- /dev/null +++ b/install.ps1 @@ -0,0 +1,57 @@ +param( + [switch] $Confirm = $True +) + +$ErrorActionPreference = "Stop" + +$ChemacsPath = Join-Path (Split-Path $PSCommandPath) ".emacs" + +Try { + Set-Variable -Scope global EmacsPath $( + Join-Path $(Get-Variable -Scope global HOME).Value ".emacs" + ) + +} Catch { + # If $HOME hasn't been defined by the user, then emacs will default to this + # directory on modern versions of Windows. Older versions of Windows probably + # don't even have PowerShell installed, so I make no effort to support them. + Set-Variable -Scope global EmacsPath $( + Resolve-Path "~/AppData/roaming/.emacs" + ) +} + +If (-Not (Test-Path -Path $EmacsPath)) { + # In Windows, symlinks require admin privileges, so we copy the + # file wholesale instead. + Write-Host "OK copying file to ~/.emacs..." + + Copy-Item $ChemacsPath $EmacsPath +} Else { + # Because we copied the file instead of symlinking it, we have to try to + # detect changes with hashing instead... + If ((Get-FileHash $ChemacsPath).Hash -Eq (Get-FileHash $EmacsPath).Hash) { + Write-Host "OK chemacs appears to already be copied over, you're all good." + } Else { + Write-Host ("WARN content is different between {0} and {1}" -f @($EmacsPath, $ChemacsPath)) + + $should_write = $False + + If ($Confirm) { + Write-Host "WARN chemacs may already be installed OR something else may be in the way" + $ans = Read-Host ("Do you want to overwrite {0}?" -f $EmacsPath) + + If (@("y", "yes", "Y", "YES").Contains($ans)) { + $should_write = $True + } + } Else { + $should_write = $True + } + + If ($should_write) { + Copy-Item $ChemacsPath $EmacsPath + Write-Host "OK updated chemacs files successfully." + } Else { + Write-Host "WARN took no action." + } + } +} \ No newline at end of file