-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathpypr.py
113 lines (102 loc) · 4.47 KB
/
pypr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
"""Fake pypr CLI to generate auto-completion scripts."""
import argparse
import os
import pathlib
import shtab
TOML_FILE = {
"bash": "_shtab_greeter_compgen_TOMLFiles",
"zsh": "_files -g '(*.toml|*.TOML)'",
"tcsh": "f:*.toml",
}
PREAMBLE = {
"bash": """
# $1=COMP_WORDS[1]
_shtab_greeter_compgen_TOMLFiles() {
compgen -d -- $1 # recurse into subdirs
compgen -f -X '!*?.toml' -- $1
compgen -f -X '!*?.TOML' -- $1
}
""",
"zsh": "",
"tcsh": "",
}
def get_parser():
"""Parses the command line arguments."""
parser = argparse.ArgumentParser(prog="pypr", description="Pyprland CLI", add_help=False, allow_abbrev=False)
parser.add_argument(
"--debug",
help="Enable debug mode and log to a file",
metavar="filename",
).complete = shtab.FILE
parser.add_argument(
"--config",
help="Use a different configuration file",
metavar="filename",
type=pathlib.Path,
).complete = TOML_FILE
shtab.add_argument_to(parser, preamble=PREAMBLE)
# Base commands
subparsers = parser.add_subparsers(dest="command")
subparsers.add_parser("dumpjson", help="Dump the current state in JSON format")
subparsers.add_parser("edit", help="Edit the configuration file")
subparsers.add_parser("exit", help="Exit the currently running daemon")
subparsers.add_parser("help", help="Prints this help message")
subparsers.add_parser("version", help="Prints the current version")
subparsers.add_parser("reload", help="Reload the configuration file")
# Scratchpads
subparsers.add_parser("attach", help="Attach the focused window to the last focused scratchpad")
show = subparsers.add_parser("show", help="Show the given scratchpad")
show.add_argument("Scratchpad", help="scratchpad name")
hide = subparsers.add_parser("hide", help="Hide the given scratchpad")
hide.add_argument("Scratchpad", help="scratchpad name")
toggle = subparsers.add_parser("toggle", help="Toggle the given scratchpad")
toggle.add_argument("Scratchpad", help="scratchpad name")
# gbar
gbar = subparsers.add_parser("gbar", help="Starts gBar on the first available monitor")
gbar.add_argument(
"command",
help="Starts gBar on the first available monitor",
nargs="?",
choices=["restart"],
)
# shortcuts_menu
menu = subparsers.add_parser("menu", help="Shows the menu")
menu.add_argument("name", help="submenu to show", nargs="?")
# toggle_special
toggle_special = subparsers.add_parser(
"toggle_special",
help="Toggle switching the focused window to the special workspace",
)
toggle_special.add_argument("name", help="special workspace name")
# layout_center
layout_center = subparsers.add_parser("layout_center", help="Change the active window")
layout_center.add_argument("command", help="Change the active window", choices=["toggle", "next", "prev"])
# lost_windows
subparsers.add_parser("attract_lost", help="Brings lost floating windows to the current workspace")
# shift_monitors
shift_monitors = subparsers.add_parser("shift_monitors", help="Swaps monitors' workspaces in the given direction")
shift_monitors.add_argument("direction", help="Swaps monitors' workspaces in the given direction")
# toggle_dpms
subparsers.add_parser("toggle_dpms", help="Toggles dpms on/off for every monitor")
# magnify
zoom = subparsers.add_parser("zoom", help="Zoom to the given factor")
zoom.add_argument("factor", help="Zoom to the given factor", nargs="?")
# Expose
subparsers.add_parser("expose", help="Expose every client on the active workspace")
# workspaces_follow_focus
change_workspace = subparsers.add_parser("change_workspace", help="Switch workspaces of current monitor")
change_workspace.add_argument("direction", help="direction to switch workspaces", choices=["-1", "+1"])
# wallpapers
wall = subparsers.add_parser("wall", help="Skip the current background image")
wall.add_argument("action", help="Skip the current background image", choices=["next", "clear"])
# fetch_client_menu
subparsers.add_parser(
"fetch_client_menu",
help="Select a client window and move it to the active workspace",
)
subparsers.add_parser("unfetch_client", help="Returns a window back to its origin")
# monitors
subparsers.add_parser("relayout", help="Recompute & apply every monitors's layout")
return parser
if "RUN" in os.environ:
get_parser().parse_args()