diff --git a/install.ps1 b/install.ps1 index 3636e67..7ab7a6b 100644 --- a/install.ps1 +++ b/install.ps1 @@ -679,38 +679,94 @@ function Copy-CustomFiles() { } $customFileApplied = $false +$customMethod = "" +$customReset = $false +$customAppend = $false function Apply-CustomFile() { Param ( [Parameter(Mandatory=$true, Position=0)] - [string] $targetFile, + [string] $gitDir, [Parameter(Mandatory=$true, Position=1)] + [string] $targetFile, + [Parameter(Mandatory=$true, Position=2)] [string] $customFile, - [Parameter(Position=2)] + [Parameter(Position=3)] [string] $otherCustom = "" ) if ( Test-Path -Path "${customFile}" -PathType leaf ) { $global:customFileApplied = $true - # Apply without duplication - if ( -not (Write-Output "$(Write-Output $(Get-Content -Path "${targetFile}"))" | Select-String -Pattern "$(Write-Output $(Get-Content -Path "${customFile}"))" -SimpleMatch -Quiet) ) { - Get-Content -Path "${customFile}" | Out-File -FilePath "${targetFile}" -Append + if ( "${customMethod}" -eq "" ) { + $local:menuAppend="Append - Maintain changes in existing files and apply custom" + $local:menuOverwrite="Overwrite - After initializing the change, apply only custom" + $local:menuNone="None - Maintain changes in existing files" + $local:menuReset="Reset- Reset to pure lepton theme without custom" + + Write-Host "Select custom method" + while ( $true ) { + $local:selected = $false + $local:applyMethod = Menu @("${menuAppend}", "${menuOverwrite}", "${menuNone}", "${menuReset}") + switch ( $applyMethod ) { + "${menuAppend}" { + $global:customMethod = "Append" + $global:customAppend = $true + $selected = $true + } + "${menuOverwrite}" { + $global:customMethod = "Overwrite" + $global:customReset = $true + $global:customAppend = $true + $selected = $true + } + "${menuNone}" { + $global:customMethod = "None" + $selected = $true + } + "${menuReset}" { + $global:customMethod = "Reset" + $global:customReset = $true + $selected = $true + } + default { Write-Host "Invalid option, reselect please." } + } + + if ( $selected -eq $true ) { + break + } + } + + Lepton-OKMessage "Selected ${customMethod}" + } + + if ( "${customReset}" -eq $true ) { + git --git-dir "${gitDir}" reset --hard HEAD + } + if ( "${customAppend}" -eq $true ) { + # Apply without duplication + if ( -not (Write-Output "$(Write-Output $(Get-Content -Path "${targetFile}"))" | Select-String -Pattern "$(Write-Output $(Get-Content -Path "${customFile}"))" -SimpleMatch -Quiet) ) { + Get-Content -Path "${customFile}" | Out-File -FilePath "${targetFile}" -Append + } } } elseif ( "${otherCustom}" -ne "" ) { - Apply-CustomFile "${targetFile}" "${otherCustom}" + Apply-CustomFile "${gitDir}" "${targetFile}" "${otherCustom}" } } function Apply-CustomFiles() { foreach ( $profilePath in $global:firefoxProfilePaths ) { + $local:LEPTONGITPATH="${profilePath}\chrome\.git" foreach ( $customFile in $global:customFiles ) { $local:targetFile = $customFile.Replace("-overrides", "") if ( "${customFile}" -eq "user-overrides.js" ) { - Apply-CustomFile "${profilePath}\${targetFile}" "${profilePath}\user-overrides.js" "${profilePath}\chrome\user-overrides.js" + $local:targetPath = "${profilePath}\${targetFile}" + $local:customPath = "${profilePath}\user-overrides.js" + $local:otherCustomPath = "${profilePath}\chrome\user-overrides.js" + Apply-CustomFile "${LEPTONGITPATH}" "${targetPath}" "${customPath}" "${otherCustomPath}" } else { - Apply-CustomFile "${profilePath}\chrome\${targetFile}" "${profilePath}\chrome\${customFile}" + Apply-CustomFile "${LEPTONGITPATH}" "${profilePath}\chrome\${targetFile}" "${profilePath}\chrome\${customFile}" } } } diff --git a/install.sh b/install.sh index 1374422..ac22ab5 100755 --- a/install.sh +++ b/install.sh @@ -658,31 +658,77 @@ copy_custom_files() { } customFileApplied="" +customMethod="" +customReset="" +customAppend="" apply_custom_file() { - local targetFile=$1 - local customFile=$2 - local otherCustom=$3 + local gitDir=$1 + local targetFile=$2 + local customFile=$3 + local otherCustom=$4 if [ -f "${customFile}" ]; then customFileApplied="true" - # Apply without duplication - if ! grep -Fq "$(echo $(cat "${customFile}"))" <(echo "$(echo $(cat "${targetFile}"))"); then - cat "${customFile}" >> "${targetFile}" + if [ -z "${customMethod}" ]; then + local menuAppend="Append - Maintain changes in existing files and apply custom" + local menuOverwrite="Overwrite - After initializing the change, apply only custom" + local menuNone="None - Maintain changes in existing files" + local menuReset="Reset- Reset to pure lepton theme without custom" + + echo "Select custom method" + select applyMethod in "${menuAppend}" "${menuOverwrite}" "${menuNone}" "${menuReset}"; do + case "${applyMethod}" in + "${menuAppend}") + customMethod="Append" + customAppend="true" + break;; + "${menuOverwrite}") + customMethod="Overwrite" + customReset="true" + customAppend="true" + break;; + "${menuNone}") + customMethod="None" + break;; + "${menuReset}") + customMethod="Reset" + customReset="true" + break;; + *) + echo "Invalid option, reselect please.";; + esac + done + + lepton_ok_message "Selected ${customMethod}" + fi + + if [ "${customReset}" == "true" ]; then + git --git-dir "${gitDir}" reset --hard HEAD + fi + if [ "${customAppend}" == "true" ]; then + # Apply without duplication + if ! grep -Fq "$(echo $(cat "${customFile}"))" <(echo "$(echo $(cat "${targetFile}"))"); then + cat "${customFile}" >> "${targetFile}" + fi fi elif [ -n "${otherCustom}" ]; then - apply_custom_file "${targetFile}" "${otherCustom}" + apply_custom_file "${gitDir}" "${targetFile}" "${otherCustom}" fi } apply_custom_files() { for profilePath in "${firefoxProfilePaths[@]}"; do + local LEPTONGITPATH="${profilePath}/chrome/.git" for customFile in "${customFiles[@]}"; do local targetFile="${customFile//-overrides/}" if [ "${customFile}" == "user-overrides.js" ]; then - apply_custom_file "${profilePath}/${targetFile}" "${profilePath}/user-overrides.js" "${profilePath}/chrome/user-overrides.js" + local targetPath="${profilePath}/${targetFile}" + local customPath="${profilePath}/user-overrides.js" + local otherCustomPath="${profilePath}/chrome/user-overrides.js" + apply_custom_file "${LEPTONGITPATH}" "${targetPath}" "${customPath}" "${otherCustomPath}" else - apply_custom_file "${profilePath}/chrome/${targetFile}" "${profilePath}/chrome/${customFile}" + apply_custom_file "${LEPTONGITPATH}" "${profilePath}/chrome/${targetFile}" "${profilePath}/chrome/${customFile}" fi done done