mirror of
https://github.com/lptstr/winfetch.git
synced 2026-09-28 01:46:03 -04:00
Generate default configuration by default (#63)
* Generate default configuration by default * Include config inside winfetch.ps1 * Update -genconf usage * Use backslashes for configPath * Add choice descriptions
This commit is contained in:
+85
-23
@@ -48,7 +48,7 @@
|
||||
.PARAMETER image
|
||||
Display a pixelated image instead of the usual logo. Imagemagick required.
|
||||
.PARAMETER genconf
|
||||
Download a configuration template. Internet connection required.
|
||||
Reset your configuration file to the default.
|
||||
.PARAMETER configpath
|
||||
Specify a path to a custom config file.
|
||||
.PARAMETER noimage
|
||||
@@ -99,17 +99,10 @@ if (-not $configPath) {
|
||||
$configPath = $env:WINFETCH_CONFIG_PATH
|
||||
} else {
|
||||
$configDir = $env:XDG_CONFIG_HOME, "${env:USERPROFILE}\.config" | Select-Object -First 1
|
||||
$configPath = "${configDir}/winfetch/config.ps1"
|
||||
$configPath = "${configDir}\winfetch\config.ps1"
|
||||
}
|
||||
}
|
||||
|
||||
$defaultconfig = 'https://raw.githubusercontent.com/lptstr/winfetch/master/lib/config.ps1'
|
||||
|
||||
# ensure configuration directory exists
|
||||
if (-not (Test-Path -Path $configPath)) {
|
||||
[void](New-Item -Path $configPath -Force)
|
||||
}
|
||||
|
||||
# ===== DISPLAY HELP =====
|
||||
if ($help) {
|
||||
if (Get-Command -Name less -ErrorAction Ignore) {
|
||||
@@ -120,18 +113,6 @@ if ($help) {
|
||||
exit 0
|
||||
}
|
||||
|
||||
# ===== GENERATE CONFIGURATION =====
|
||||
if ($genconf) {
|
||||
if ((Get-Item -Path $configPath).Length -gt 0) {
|
||||
Write-Host 'ERROR: configuration file already exists!' -f red
|
||||
exit 1
|
||||
}
|
||||
Write-Output "INFO: downloading default config to '$configPath'."
|
||||
Invoke-WebRequest -Uri $defaultconfig -OutFile $configPath -UseBasicParsing
|
||||
Write-Output 'INFO: successfully completed download.'
|
||||
exit 0
|
||||
}
|
||||
|
||||
|
||||
# ===== VARIABLES =====
|
||||
$cimSession = New-CimSession
|
||||
@@ -165,10 +146,91 @@ $baseConfig = @(
|
||||
"colorbar"
|
||||
)
|
||||
|
||||
if ((Get-Item -Path $configPath).Length -gt 0) {
|
||||
$config = . $configPath
|
||||
$defaultConfig = @'
|
||||
# ===== WINFETCH CONFIGURATION =====
|
||||
|
||||
# $image = "~/winfetch.png"
|
||||
# $noimage = $true
|
||||
|
||||
# Use legacy Windows logo
|
||||
# $legacylogo = $true
|
||||
|
||||
# Make the logo blink
|
||||
# $blink = $true
|
||||
|
||||
# Display all built-in info segments.
|
||||
# $all = $true
|
||||
|
||||
# Add a custom info line
|
||||
# function info_custom_time {
|
||||
# return @{
|
||||
# title = "Time"
|
||||
# content = (Get-Date)
|
||||
# }
|
||||
# }
|
||||
|
||||
# Configure which disks are shown
|
||||
# $ShowDisks = @("C:", "D:")
|
||||
# Show all available disks
|
||||
# $ShowDisks = @("*")
|
||||
|
||||
# Configure which package managers are shown
|
||||
# disabling unused ones will improve speed
|
||||
# $ShowPkgs = @("scoop", "choco")
|
||||
|
||||
|
||||
# Remove the '#' from any of the lines in
|
||||
# the following to **enable** their output.
|
||||
|
||||
@(
|
||||
"title"
|
||||
"dashes"
|
||||
"os"
|
||||
"computer"
|
||||
"kernel"
|
||||
"motherboard"
|
||||
# "custom_time" # use custom info line
|
||||
"uptime"
|
||||
"pkgs"
|
||||
"pwsh"
|
||||
"resolution"
|
||||
"terminal"
|
||||
# "theme"
|
||||
"cpu"
|
||||
"gpu"
|
||||
# "process" # takes some time
|
||||
"memory"
|
||||
"disk"
|
||||
# "battery"
|
||||
# "locale"
|
||||
# "local_ip"
|
||||
# "public_ip"
|
||||
"blank"
|
||||
"colorbar"
|
||||
)
|
||||
|
||||
'@
|
||||
|
||||
# generate default config
|
||||
if ($genconf -and (Test-Path $configPath)) {
|
||||
$choiceYes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", `
|
||||
"overwrite your configuration with the default"
|
||||
$choiceNo = New-Object System.Management.Automation.Host.ChoiceDescription "&No", `
|
||||
"do nothing and exit"
|
||||
$result = $Host.UI.PromptForChoice("Resetting your config to default will overwrite it.",
|
||||
"Do you want to continue?", ($choiceYes, $choiceNo), 1)
|
||||
if ($result -eq 0) { Remove-Item -Path $configPath } else { exit 1 }
|
||||
}
|
||||
|
||||
if (-not (Test-Path $configPath) -or ((Get-Item -Path $configPath).Length -eq 0)) {
|
||||
New-Item -Type File -Path $configPath -Value $defaultConfig -Force | Out-Null
|
||||
Write-Host "INFO: saved default config to '$configPath'."
|
||||
if ($genconf) { exit 0 }
|
||||
}
|
||||
|
||||
# load config file
|
||||
$config = . $configPath
|
||||
|
||||
if (-not $config -or $all) {
|
||||
$config = $baseConfig
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user