~robertgzr/xap

1b9b83ef8e5eb4321f23f34a409f0ce8aabbbd93 — Robert Günzler 2 years ago a038b68 master
support loading additional default flags from file
1 files changed, 22 insertions(+), 4 deletions(-)

M command/player/run.go
M command/player/run.go => command/player/run.go +22 -4
@@ 6,6 6,7 @@ import (
	"io/ioutil"
	"os"
	"os/exec"
	"path/filepath"
	"strconv"
	"strings"



@@ 57,13 58,30 @@ var runCommand = &cli.Command{
		},
	},
	Action: func(ctx *cli.Context) error {
		args := append(ctx.Args().Slice(),
			fmt.Sprintf("--input-ipc-server=%s", ctx.String("socket")),
			"--idle",
		)
		var args []string
		// use anything after -- as mpv args
		// putting it here means anything we set overwrites
		args = ctx.Args().Slice()
		// try loading args from a file
		xdgdir, err := os.UserConfigDir()
		if err == nil {
			data, err := ioutil.ReadFile(filepath.Join(xdgdir, "xap", "default-mpv-flags"))
			if err == nil {
				content := string(data)
				// trim away the final newline
				content = strings.TrimRight(content, "\n")
				args = append(args, strings.Split(content, "\n")...)
			}
		}
		// some nice defaults
		if !ctx.Bool("no-defaults") {
			args = append(args, defaultMpvFlags...)
		}
		// mandatory args for xap to work
		args = append(args,
			fmt.Sprintf("--input-ipc-server=%s", ctx.String("socket")),
			"--idle",
		)

		pid, err := ioutil.ReadFile(pidFile)
		if err == nil {