Skip to content

Commit

Permalink
feat(gsettings): backup favs + support distrobox backup
Browse files Browse the repository at this point in the history
  • Loading branch information
scottames committed Aug 5, 2023
1 parent dae9272 commit 67cf73f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
2 changes: 2 additions & 0 deletions home/.gsettings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ org.gnome.settings-daemon.plugins.media-keys:
name: '''wez'''
org.gnome.settings-daemon.plugins.power:
sleep-inactive-ac-type: '''nothing'''
org.gnome.shell:
favorite-apps: '[''firefox.desktop'', ''vivaldi-stable.desktop'', ''1password.desktop'', ''org.gnome.Software.desktop'', ''org.flameshot.Flameshot.desktop'', ''org.gnome.Nautilus.desktop'', ''org.wezfurlong.wezterm.desktop'']'
org.gnome.shell.extensions.nightthemeswitcher.gtk-variants:
day: '''Catppuccin-Frappe-Standard-Flamingo-dark'''
enabled: "true"
Expand Down
17 changes: 15 additions & 2 deletions magefiles/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"os"
"strings"
"time"

Expand All @@ -13,10 +14,22 @@ import (
)

const (
fs = "/"
dockerfile = "Dockerfile"
fs = "/"
dockerfile = "Dockerfile"
dockerEnv = "/.dockerenv"
containerEnv = "/run/.containerenv"
)

func isContainer() bool {
if _, err := os.Stat(containerEnv); err == nil {
return true
} else if _, err = os.Stat(dockerEnv); err == nil {
return true
}

return false
}

func dockerTagBase(org, proj, target string) string {
return org + fs + proj + fs + target
}
Expand Down
34 changes: 27 additions & 7 deletions magefiles/gsettings.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,27 @@ import (
)

const (
gs = "gsettings"
gsBackupFile string = "./home/.gsettings.yaml"
indent = 2
distroboxHostExec = "distrobox-host-exec"
gs = "gsettings"
gsBackupFile string = "./home/.gsettings.yaml"
indent = 2
)

// newDistroBoxCmd - returns a string slice with "distrobox-host-exec" prepended to the command
// if the command is being executed in a container and "distrobox-host-exec" is available in path.
func newDistroBoxCmd(cmd string) []string {
isContainer := isContainer()
cs := []string{}
if isContainer {
_, err := helpers.Which(distroboxHostExec)
if err == nil {
cs = append(cs, distroboxHostExec)
}
}
cs = append(cs, cmd)
return cs
}

// GSettings - maps to a schema: key:value.
type GSettings map[string]GSetting

Expand Down Expand Up @@ -125,13 +141,15 @@ func (Gs) Compileschemas() error {
}
}

return cmder.New("glib-compile-schemas", schemasDir).Silent().Run()
cmd := newDistroBoxCmd("glib-compile-schemas")
return cmder.New(cmd...).Args(schemasDir).Silent().Run()
}

// Get - retrieve the value for a schema & key
// returns the value and any possible error.
func (Gs) Get(schema string, key string) (string, error) {
val, err := cmder.New(gs, "get", schema, key).Silent().CombinedOutput()
gsCmd := newDistroBoxCmd(gs)
val, err := cmder.New(gsCmd...).Args("get", schema, key).Silent().CombinedOutput()
if err != nil {
return "", fmt.Errorf("err getting '%s' '%s'\n %s", schema, key, strings.TrimSpace(string(val)))
}
Expand Down Expand Up @@ -187,7 +205,8 @@ func (g Gs) getToGSetting(gs GSettings, schema string, key string) (GSettings, e
// ListKeys - lists the keys for the given schema
// returns the keys and any possible error.
func (Gs) ListKeys(schema string) ([]string, error) {
rawKeys, err := cmder.New(gs, "list-keys", schema).Silent().CombinedOutput()
gsCmd := newDistroBoxCmd(gs)
rawKeys, err := cmder.New(gsCmd...).Args("list-keys", schema).CombinedOutput()
if err != nil {
return nil, fmt.Errorf(string(rawKeys))
}
Expand Down Expand Up @@ -262,7 +281,8 @@ func (g Gs) Set(scope string, val string) error {
return err
}

out, err := cmder.New(gs, "set", schema, key, val).Silent().CombinedOutput()
gsCmd := newDistroBoxCmd(gs)
out, err := cmder.New(gsCmd...).Args("set", schema, key, val).Silent().CombinedOutput()
if err != nil {
return fmt.Errorf("err setting: '%s' '%s' '%s'\n '%s'", schema, key, val, strings.TrimSpace(string(out)))
}
Expand Down

0 comments on commit 67cf73f

Please sign in to comment.