var Gio = imports.gi.Gio; var GLib = imports.gi.GLib; let extensionPath = GLib.getenv("HOME") + "/.local/share/gnome-shell/extensions/paperwm@hedning:matrix.org"; let schemaSource = Gio.SettingsSchemaSource.new_from_directory( GLib.build_filenamev([extensionPath, "schemas"]), Gio.SettingsSchemaSource.get_default(), false ); let schemaObj = schemaSource.lookup("org.gnome.Shell.Extensions.PaperWM.Keybindings", true); let settings = new Gio.Settings({settings_schema: schemaObj}) let keysymToChar = { comma: ',', period: '.', } let renderAll = ARGV[0] == "--all" function arrayEqual(a, b) { if (a.length != b.length) return false; for (let i = 0; i < a.length; i++) { if (a[i] !== b[i]) return false; } return true; } let lines = [] lines.push("| Keybindings | Description |"); lines.push("| ----------- | ----------- |"); for (let name of settings.list_keys()) { let schemaKey = settings.settings_schema.get_key(name); let bindingStrs = settings.get_strv(name); let defaultValue = schemaKey.get_default_value().get_strv() if (!renderAll && arrayEqual(defaultValue, bindingStrs)) continue let line = "| "; // let binding = settings.get_strv("move-left")[0]; function renderBinding(binding) { let modifiers = []; let i = 0; while (true) { let match = binding.slice(i).match(/<([^>]*)>/); if (match === null) break; i += match[0].length; modifiers.push(match[1]); } let key = binding.slice(i); key = keysymToChar[key] || key; return [...modifiers, key].map(m => `${m}`).join(""); } line += bindingStrs.map(b => renderBinding(b)).join(" or "); line += " | "; line += schemaKey.get_summary(); line += " |"; lines.push(line); } print(lines.join("\n"))