diff --git a/README.md b/README.md index 7d63f25..b185dda 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ ## Usage Hotkeys are case-insensitive, with this syntax: `modifier1-modifier2-...-key`. For more info on this, check [this link](https://pkg.go.dev/github.com/alex11br/xgbutil@v0.0.0-20211225011412-f2944427ac98/keybind#hdr-Key_sequence_format) of the underlaying library. Note that, for this moment, controling for the lock (Caps Lock) and the mod2 (Num Lock) modifiers isn't allowed. -The app uses by default some config files: `/etc/gxhkrc` and `$XDG_CONFIG_HOME/gxhk/gxhkrc`. Using the `-C` flag, they can be ignored, and with the `-c` flag, new ones can be specified. Using the `-s` flag, a different socket besides the default `/tmp/gxhk.sock` can be specified. +The app uses by default some config files: `/etc/gxhkrc` and `$XDG_CONFIG_HOME/gxhk/gxhkrc`. Using the `-C` flag, they can be ignored, and with the `-c` flag, new ones can be specified. Using the `-s` flag, a different socket besides the default `/tmp/gxhk$DISPLAY.sock` can be specified. Here are some examples: ```sh diff --git a/common/args.go b/common/args.go index c2ba78c..b82a055 100644 --- a/common/args.go +++ b/common/args.go @@ -1,6 +1,11 @@ package common -import "github.com/alexflint/go-arg" +import ( + "fmt" + "os" + + "github.com/alexflint/go-arg" +) type BindCmd struct { Released bool `arg:"-r" help:"bind the HOTKEY on its release instead of its press"` @@ -19,7 +24,7 @@ type InfoCmd struct { } type Args struct { - SocketPath string `arg:"-s,--socket" help:"use the given SOCKET file" default:"/tmp/gxhk.sock" json:"-"` + SocketPath string `arg:"-s,--socket" help:"use the given SOCKET file instead of the default one" json:"-"` ConfigFiles []string `arg:"-c,--config,separate" help:"use the given CONFIG file, besides all the others" json:"-"` NoDefaultConfigs bool `arg:"-C,--no-default-configs" help:"ignore the default config files" json:"-"` @@ -28,8 +33,16 @@ type Args struct { Info *InfoCmd `arg:"subcommand:info" help:"show infos about the bound keys and their commands" json:",omitempty"` } +// ParseArgs gives us an Args structure based on the passed command-line flags. +// If its SocketPath is not set, we'll set it for our convenience to the default value, +// which must be computed on the spot using the $DISPLAY environment variable. +// Besides that, the resulting arg.Parser is also returned for our convenience. func ParseArgs() (Args, *arg.Parser) { var args Args p := arg.MustParse(&args) + + if args.SocketPath == "" { + args.SocketPath = fmt.Sprintf("/tmp/gxhk%s.sock", os.Getenv("DISPLAY")) + } return args, p } diff --git a/gxhk.1 b/gxhk.1 index 2713bdd..190cdce 100644 --- a/gxhk.1 +++ b/gxhk.1 @@ -27,7 +27,7 @@ is a hotkey daemon for X, something like \fBsxhkd\fR. What makes it special is t Display some help information. .TP .BR \-s ", " \-\-socket " " \fIpath -Use \fIpath\fR as the socket path instead of the default \fI/tmp/gxhk.sock\fR. +Use \fIpath\fR as the socket path instead of the default \fI/tmp/gxhk$DISPLAY.sock\fR. .SS Daemon-start-only options .TP