more commands
This commit is contained in:
parent
9a6e9ee8a9
commit
83ed570569
34
main.go
34
main.go
@ -21,6 +21,9 @@ var cli struct {
|
|||||||
Top struct {
|
Top struct {
|
||||||
Purity string `arg:"" name:"purity" optional:"" help:"purity of results"`
|
Purity string `arg:"" name:"purity" optional:"" help:"purity of results"`
|
||||||
} `cmd:"" help:"random toplist wallpaper"`
|
} `cmd:"" help:"random toplist wallpaper"`
|
||||||
|
Img struct {
|
||||||
|
Path string `arg:"" name:"path" help:"path to image or directory." type:"path"`
|
||||||
|
} `cmd:"" help:"set from file"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -36,11 +39,32 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
case "img <path>":
|
||||||
|
err := setFromPath(cli.Img.Path)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
panic(ctx.Command())
|
panic(ctx.Command())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setFromPath(filePath string) error {
|
||||||
|
fileInfo, err := os.Stat(filePath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if fileInfo.IsDir() {
|
||||||
|
files, err := os.ReadDir(filePath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
file := files[rand.Intn(len(files))]
|
||||||
|
return setWallPaperAndRestartStuff(file.Name())
|
||||||
|
}
|
||||||
|
return setWallPaperAndRestartStuff(filePath)
|
||||||
|
}
|
||||||
|
|
||||||
func searchAndSet(query string) error {
|
func searchAndSet(query string) error {
|
||||||
seed := rand.NewSource(time.Now().UnixNano())
|
seed := rand.NewSource(time.Now().UnixNano())
|
||||||
r := rand.New(seed)
|
r := rand.New(seed)
|
||||||
@ -66,7 +90,7 @@ func searchAndSet(query string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
err = setWallPaperAndRestartStuff(result)
|
err = setWallPaperAndRestartStuff(result.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -100,21 +124,21 @@ func setTop(purity string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = setWallPaperAndRestartStuff(result)
|
err = setWallPaperAndRestartStuff(result.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func setWallPaperAndRestartStuff(result wallhaven.Wallpaper) error {
|
func setWallPaperAndRestartStuff(result string) error {
|
||||||
homedir, _ := os.UserHomeDir()
|
homedir, _ := os.UserHomeDir()
|
||||||
_, err := exec.Command("wal", "--cols16", "-i", path.Join(homedir, "Pictures/Wallpapers", path.Base(result.Path)), "-n", "-a", "85").
|
_, err := exec.Command("wal", "--cols16", "-i", path.Join(homedir, "Pictures/Wallpapers", path.Base(result)), "-n", "-a", "85").
|
||||||
Output()
|
Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = exec.Command("swww", "img", path.Join(homedir, "/Pictures/Wallpapers", path.Base(result.Path))).
|
_, err = exec.Command("swww", "img", path.Join(homedir, "/Pictures/Wallpapers", path.Base(result))).
|
||||||
Output()
|
Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user