age stat, config reset flag
This commit is contained in:
parent
0aae0065be
commit
287c2895fd
4
PKGBUILD
4
PKGBUILD
@ -43,3 +43,7 @@ package() {
|
|||||||
chmod 755 "$pkgdir/usr/share/gogofetch/logos"
|
chmod 755 "$pkgdir/usr/share/gogofetch/logos"
|
||||||
chmod 644 "$pkgdir/usr/share/gogofetch/logos/"*.png
|
chmod 644 "$pkgdir/usr/share/gogofetch/logos/"*.png
|
||||||
}
|
}
|
||||||
|
|
||||||
|
post_upgrade() {
|
||||||
|
echo "! It is recommended to run 'gogofetch --reset-config' after upgrading gogofetch-git to get the latest config."
|
||||||
|
}
|
||||||
27
src/main.go
27
src/main.go
@ -10,6 +10,21 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
resetConfig := flag.Bool("reset-config", false, "Reset config to defaults")
|
||||||
|
width := flag.Int("w", 190, "Logo width in lines")
|
||||||
|
logoPath := flag.String("l", "", "Path to the logo")
|
||||||
|
logoPos := flag.String("p", "", "Logo position: left or right")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
if *resetConfig {
|
||||||
|
if err := providers.ResetConfig(); err != nil {
|
||||||
|
fmt.Printf("Error resetting config: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
fmt.Println("Config reset to defaults")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
conf, _ := providers.InitConfig()
|
conf, _ := providers.InitConfig()
|
||||||
|
|
||||||
if len(conf.Layout) == 0 {
|
if len(conf.Layout) == 0 {
|
||||||
@ -28,10 +43,12 @@ func main() {
|
|||||||
defaultLogo = providers.GetLogo(distID)
|
defaultLogo = providers.GetLogo(distID)
|
||||||
}
|
}
|
||||||
|
|
||||||
width := flag.Int("w", 190, "Logo width in lines")
|
if *logoPath == "" {
|
||||||
logoPath := flag.String("l", providers.GetAbsLogoPath(defaultLogo), "Path to the logo")
|
*logoPath = providers.GetAbsLogoPath(defaultLogo)
|
||||||
logoPos := flag.String("p", providers.NormalizeLogoPosition(conf.LogoPosition), "Logo position: left or right")
|
}
|
||||||
flag.Parse()
|
if *logoPos == "" {
|
||||||
|
*logoPos = providers.NormalizeLogoPosition(conf.LogoPosition)
|
||||||
|
}
|
||||||
position := providers.NormalizeLogoPosition(*logoPos)
|
position := providers.NormalizeLogoPosition(*logoPos)
|
||||||
|
|
||||||
type Info struct {
|
type Info struct {
|
||||||
@ -64,6 +81,8 @@ func main() {
|
|||||||
stats = append(stats, Info{"term", providers.GetTerminal()})
|
stats = append(stats, Info{"term", providers.GetTerminal()})
|
||||||
case "uptime":
|
case "uptime":
|
||||||
stats = append(stats, Info{"uptime", providers.GetUptime()})
|
stats = append(stats, Info{"uptime", providers.GetUptime()})
|
||||||
|
case "age":
|
||||||
|
stats = append(stats, Info{"age", providers.GetAge()})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -20,7 +20,10 @@ const (
|
|||||||
White = "\033[1;37m"
|
White = "\033[1;37m"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const ConfigVersion = 1
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
ConfigVersion int `toml:"config_version"`
|
||||||
Ascii bool `toml:"ascii"`
|
Ascii bool `toml:"ascii"`
|
||||||
Layout []string `toml:"layout"`
|
Layout []string `toml:"layout"`
|
||||||
CustomLogo string `toml:"custom_logo"`
|
CustomLogo string `toml:"custom_logo"`
|
||||||
@ -29,16 +32,27 @@ type Config struct {
|
|||||||
StatColor string `toml:"stat_color"`
|
StatColor string `toml:"stat_color"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func appendMissingConfigKeys(pathConf string, md toml.MetaData) error {
|
func ResetConfig() error {
|
||||||
var missing []string
|
pathConf, err := getConfigPath()
|
||||||
|
if err != nil {
|
||||||
if !md.IsDefined("ascii") {
|
return err
|
||||||
missing = append(missing, "# Set this to \"true\" if you like ascii more than images (i'm too lazy to add support for all distros though, so there's only arch, nixos and debian)\nascii = false")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !md.IsDefined("layout") {
|
if err := os.RemoveAll(pathConf); err != nil {
|
||||||
missing = append(missing, `# Stats layout: reorder or remove items to customize your fetch
|
return err
|
||||||
# Available: "dist", "host", "cpu", "kernel", "ram", "gpu", "de/wm", "pkgs", "shell", "terminal", "uptime"
|
}
|
||||||
|
|
||||||
|
if err := os.MkdirAll(filepath.Dir(pathConf), 0755); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultConfig := []byte(`config_version = 1
|
||||||
|
|
||||||
|
# Set this to "true" if you like ascii more than images (i'm too lazy to add support for all distros though, so there's only arch, nixos and debian)
|
||||||
|
ascii = false
|
||||||
|
|
||||||
|
# Stats layout: reorder or remove items to customize your fetch
|
||||||
|
# Available: "dist", "host", "cpu", "kernel", "ram", "gpu", "de/wm", "pkgs", "shell", "terminal", "uptime", "age"
|
||||||
layout = [
|
layout = [
|
||||||
"host",
|
"host",
|
||||||
"dist",
|
"dist",
|
||||||
@ -51,6 +65,54 @@ layout = [
|
|||||||
"shell",
|
"shell",
|
||||||
"terminal",
|
"terminal",
|
||||||
"uptime",
|
"uptime",
|
||||||
|
"age",
|
||||||
|
]
|
||||||
|
|
||||||
|
# Absolute path to a custom image or .txt file. Leave empty to use auto-detection.
|
||||||
|
custom_logo = ""
|
||||||
|
|
||||||
|
# Position of the logo block relative to the stats block: "left" or "right".
|
||||||
|
logo_position = "left"
|
||||||
|
|
||||||
|
# key symbol before stat (e.g. ->)
|
||||||
|
# default: "->"
|
||||||
|
key = ""
|
||||||
|
|
||||||
|
# color of the stat label, default is blue
|
||||||
|
# available: blue, green, red, yellow, purple, cyan, white
|
||||||
|
stat_color = ""
|
||||||
|
`)
|
||||||
|
|
||||||
|
return os.WriteFile(pathConf, defaultConfig, 0644)
|
||||||
|
}
|
||||||
|
|
||||||
|
func appendMissingConfigKeys(pathConf string, md toml.MetaData, currentVersion int) error {
|
||||||
|
var missing []string
|
||||||
|
|
||||||
|
if !md.IsDefined("config_version") || md.IsDefined("config_version") && currentVersion != ConfigVersion {
|
||||||
|
missing = append(missing, fmt.Sprintf("config_version = %d", ConfigVersion))
|
||||||
|
}
|
||||||
|
|
||||||
|
if !md.IsDefined("ascii") {
|
||||||
|
missing = append(missing, "# Set this to \"true\" if you like ascii more than images (i'm too lazy to add support for all distros though, so there's only arch, nixos and debian)\nascii = false")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !md.IsDefined("layout") {
|
||||||
|
missing = append(missing, `# Stats layout: reorder or remove items to customize your fetch
|
||||||
|
# Available: "dist", "host", "cpu", "kernel", "ram", "gpu", "de/wm", "pkgs", "shell", "terminal", "uptime", "age"
|
||||||
|
layout = [
|
||||||
|
"host",
|
||||||
|
"dist",
|
||||||
|
"cpu",
|
||||||
|
"kernel",
|
||||||
|
"ram",
|
||||||
|
"gpu",
|
||||||
|
"de/wm",
|
||||||
|
"pkgs",
|
||||||
|
"shell",
|
||||||
|
"terminal",
|
||||||
|
"uptime",
|
||||||
|
"age",
|
||||||
]`)
|
]`)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,7 +200,7 @@ func InitConfig() (Config, string) {
|
|||||||
ascii = false
|
ascii = false
|
||||||
|
|
||||||
# Stats layout: reorder or remove items to customize your fetch
|
# Stats layout: reorder or remove items to customize your fetch
|
||||||
# Available: "dist", "host", "cpu", "kernel", "ram", "gpu", "de/wm", "pkgs", "shell", "terminal", "uptime"
|
# Available: "dist", "host", "cpu", "kernel", "ram", "gpu", "de/wm", "pkgs", "shell", "terminal", "uptime", "age"
|
||||||
layout = [
|
layout = [
|
||||||
"host",
|
"host",
|
||||||
"dist",
|
"dist",
|
||||||
@ -151,6 +213,7 @@ layout = [
|
|||||||
"shell",
|
"shell",
|
||||||
"terminal",
|
"terminal",
|
||||||
"uptime",
|
"uptime",
|
||||||
|
"age",
|
||||||
]
|
]
|
||||||
|
|
||||||
# Absolute path to a custom image or .txt file. Leave empty to use auto-detection.
|
# Absolute path to a custom image or .txt file. Leave empty to use auto-detection.
|
||||||
@ -177,7 +240,8 @@ stat_color = ""
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error loading config at %s: %v\n", pathConf, err)
|
fmt.Printf("Error loading config at %s: %v\n", pathConf, err)
|
||||||
conf = Config{
|
conf = Config{
|
||||||
Layout: []string{"host", "dist", "cpu", "kernel", "ram", "gpu", "de/wm", "pkgs", "shell", "terminal", "uptime"},
|
ConfigVersion: ConfigVersion,
|
||||||
|
Layout: []string{"host", "dist", "cpu", "kernel", "ram", "gpu", "de/wm", "pkgs", "shell", "terminal", "uptime", "age"},
|
||||||
CustomLogo: "",
|
CustomLogo: "",
|
||||||
LogoPosition: "left",
|
LogoPosition: "left",
|
||||||
Key: "->",
|
Key: "->",
|
||||||
@ -186,7 +250,7 @@ stat_color = ""
|
|||||||
return conf, pathConf
|
return conf, pathConf
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := appendMissingConfigKeys(pathConf, md); err != nil {
|
if err := appendMissingConfigKeys(pathConf, md, conf.ConfigVersion); err != nil {
|
||||||
fmt.Printf("Warning: Could not update config at %s: %v\n", pathConf, err)
|
fmt.Printf("Warning: Could not update config at %s: %v\n", pathConf, err)
|
||||||
} else {
|
} else {
|
||||||
if _, err := toml.DecodeFile(pathConf, &conf); err != nil {
|
if _, err := toml.DecodeFile(pathConf, &conf); err != nil {
|
||||||
|
|||||||
@ -233,3 +233,19 @@ func GetShell() string {
|
|||||||
}
|
}
|
||||||
return strings.TrimSpace(string(out))
|
return strings.TrimSpace(string(out))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetAge() string {
|
||||||
|
out, err := exec.Command("stat", "-c", "%W", "/").Output()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error executing command: %v\n", err)
|
||||||
|
return "unknown"
|
||||||
|
}
|
||||||
|
birthTime := strings.TrimSpace(string(out))
|
||||||
|
if birthTime == "0" || birthTime == "-" {
|
||||||
|
return "unknown"
|
||||||
|
}
|
||||||
|
age, _ := strconv.Atoi(birthTime)
|
||||||
|
age = int(time.Now().Unix() - int64(age))
|
||||||
|
birth := age / 86400
|
||||||
|
return fmt.Sprintf("%d days", birth)
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user