Skip to content

Commit a9eb571

Browse files
feat: add --from alias, shell completion, and config file support (v1.4.0)
1 parent 5952bad commit a9eb571

3 files changed

Lines changed: 50 additions & 7 deletions

File tree

server/guga/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.3.0"
1+
__version__ = "1.4.0"

server/guga/cli.py

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
import time
2323
import urllib.request
2424
import urllib.error
25+
import configparser
26+
try:
27+
import argcomplete
28+
except ImportError:
29+
argcomplete = None
2530
from guga import __version__
2631

2732

@@ -124,9 +129,41 @@ def run_command(cmd_args, port, silent, title):
124129
sys.exit(exit_code)
125130

126131

132+
# ── Configuration ─────────────────────────────────────────────────────────────
133+
134+
def load_config():
135+
"""Loads default values from ~/.config/guga/config"""
136+
config = configparser.ConfigParser()
137+
config_path = os.path.expanduser("~/.config/guga/config")
138+
139+
defaults = {
140+
"title": None,
141+
"port": 6769,
142+
"silent": False
143+
}
144+
145+
if os.path.exists(config_path):
146+
try:
147+
config.read(config_path)
148+
if "default" in config:
149+
section = config["default"]
150+
if "title" in section:
151+
defaults["title"] = section["title"]
152+
if "port" in section:
153+
defaults["port"] = int(section["port"])
154+
if "silent" in section:
155+
defaults["silent"] = section.getboolean("silent")
156+
except Exception:
157+
pass # Ignore invalid config files
158+
159+
return defaults
160+
161+
127162
# ── Entry point ───────────────────────────────────────────────────────────────
128163

129164
def parse_args():
165+
defaults = load_config()
166+
130167
parser = argparse.ArgumentParser(
131168
prog="guga",
132169
description="Send notifications to Android, or watch a command and notify on completion.",
@@ -236,22 +273,27 @@ def parse_args():
236273
parser.add_argument(
237274
"--server",
238275
type=int,
239-
default=6769,
276+
default=defaults["port"],
240277
metavar="PORT",
241-
help="GuGa server port (default: 6769).",
278+
help=f"GuGa server port (default: {defaults['port']}).",
242279
)
243280
parser.add_argument(
244281
"--silent",
245282
action="store_true",
283+
default=defaults["silent"],
246284
help="Suppress guga's own output.",
247285
)
248286
parser.add_argument(
249-
"--title",
250-
default=None,
287+
"-f", "--from", "--title",
288+
dest="title",
289+
default=defaults["title"],
251290
metavar="LABEL",
252291
help='Label shown in the notification, e.g. "GPU Server".',
253292
)
254293

294+
if argcomplete:
295+
argcomplete.autocomplete(parser)
296+
255297
return parser.parse_args()
256298

257299

server/pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "GuGa"
7-
version = "1.3.0"
7+
version = "1.4.0"
88
description = "Linux to Android notification bridge."
99
readme = "README.md"
1010
authors = [
@@ -19,7 +19,8 @@ dependencies = [
1919
"python-dotenv",
2020
"qrcode",
2121
"cryptography",
22-
"aiohttp"
22+
"aiohttp",
23+
"argcomplete"
2324
]
2425

2526
[project.scripts]

0 commit comments

Comments
 (0)