[~] Refactor
This commit is contained in:
parent
62b809bd3c
commit
58a1e5f1be
@ -2852,6 +2852,95 @@ def suspend_timer(argv):
|
||||
print("suspend computer at %s" % t1.isoformat())
|
||||
subprocess.check_call(["systemctl", "suspend"]);
|
||||
|
||||
def gnome_shortcuts(argv):
|
||||
parser = optparse.OptionParser()
|
||||
parser.add_option(
|
||||
'-a', '--add',
|
||||
action='store_true',
|
||||
default=None,
|
||||
)
|
||||
parser.add_option(
|
||||
'-l', '--list',
|
||||
action='store_true',
|
||||
default=None,
|
||||
)
|
||||
|
||||
options, args = parser.parse_args(argv)
|
||||
|
||||
def commands_ids() -> list[str]:
|
||||
t1 = json.loads(subprocess.check_output([
|
||||
'gsettings', 'get', 'org.gnome.settings-daemon.plugins.media-keys',
|
||||
'custom-keybindings',
|
||||
]).decode('utf-8').replace('\'', '"',))
|
||||
|
||||
return t1
|
||||
|
||||
def add_command(name, command, binding):
|
||||
command_id = len(commands_ids())
|
||||
|
||||
for cmd in [
|
||||
(
|
||||
'gsettings', 'set', 'org.gnome.settings-daemon.plugins.media-keys',
|
||||
'custom-keybindings', '[%s]' % ','.join([
|
||||
"'%s'" % \
|
||||
(
|
||||
'/org/gnome/settings-daemon/plugins/media-keys'
|
||||
'/custom-keybindings/custom%d/'
|
||||
) % o
|
||||
for o in range(command_id + 1)
|
||||
]),
|
||||
),
|
||||
(
|
||||
'gsettings', 'set',
|
||||
(
|
||||
'org.gnome.settings-daemon.plugins.media-keys.custom-keybinding'
|
||||
':/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom%d/'
|
||||
) % command_id,
|
||||
'name', name,
|
||||
),
|
||||
(
|
||||
'gsettings', 'set',
|
||||
(
|
||||
'org.gnome.settings-daemon.plugins.media-keys.custom-keybinding'
|
||||
':/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom%d/'
|
||||
) % command_id,
|
||||
'command', command,
|
||||
),
|
||||
(
|
||||
'gsettings', 'set',
|
||||
(
|
||||
'org.gnome.settings-daemon.plugins.media-keys.custom-keybinding'
|
||||
':/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom%d/'
|
||||
) % command_id,
|
||||
'binding', binding,
|
||||
),
|
||||
]:
|
||||
subprocess.check_call(cmd)
|
||||
|
||||
if options.list:
|
||||
t1 = commands_ids()
|
||||
|
||||
t2 = [
|
||||
{
|
||||
k : json.loads(subprocess.check_output([
|
||||
'gsettings', 'get',
|
||||
(
|
||||
'org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:%s'
|
||||
) % o,
|
||||
k,
|
||||
]).decode('utf-8').replace('\'', '"',))
|
||||
for k in ['name', 'binding', 'command']
|
||||
}
|
||||
for o in t1
|
||||
]
|
||||
|
||||
pprint.pprint(t2)
|
||||
elif options.add:
|
||||
add_command(*args)
|
||||
else:
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
def socat_ssh(argv):
|
||||
parser = optparse.OptionParser()
|
||||
parser.add_option(
|
||||
@ -3430,6 +3519,8 @@ def commands_cli():
|
||||
share_wifi(sys.argv[2:])
|
||||
elif sys.argv[1] == 'socat-ssh':
|
||||
socat_ssh(sys.argv[2:])
|
||||
elif sys.argv[1] == 'gnome-shortcuts':
|
||||
gnome_shortcuts(sys.argv[2:])
|
||||
elif sys.argv[1] == 'sway_sock':
|
||||
print(sway_sock())
|
||||
elif sys.argv[1] == 'suspend-timer':
|
||||
|
Loading…
Reference in New Issue
Block a user