add documentation

This commit is contained in:
andrzej 2024-05-15 22:03:55 +02:00
parent 100df16d38
commit 81aab0fee6
1 changed files with 34 additions and 8 deletions

View File

@ -1,18 +1,39 @@
#!/usr/bin/env lua #!/usr/bin/env lua
-- Entries contain three strings: 1 - name, 2 - shell command, and 3 - keybinding. -- This is where you add the bindings. Entries contain three strings: 1 - name, 2 - shell command, and 3 - keybinding.
local entries = { local entries = {
{ {
"Toggle terminal transparency", "Toggle terminal transparency",
"${HOME}/scripts/toggle-term-transparency.sh", "${HOME}/scripts/toggle-term-transparency.sh",
"<Primary>dead_acute", "<Primary>dead_acute",
}, },
{ "Toggle bg", "${HOME}/scripts/switch-bg.sh t", "<Primary>ccedilla" }, {
"Toggle bg",
"${HOME}/scripts/switch-bg.sh t",
"<Primary>ccedilla",
},
} }
local addQuotes = function(str) ---add " marks to either end of a string
---@param str string
---@return string
local addDoubleQuotes = function(str)
return '"' .. str .. '"' return '"' .. str .. '"'
end end
local makeBinding = function(str) ---add ' marks to either end of a string
return "\"['" .. str .. "']\"" ---@param str string
local addSingleQuotes = function(str)
return "'" .. str .. "'"
end
---add square brackets to either end of a string
---@param str string
local addSquareBrackets = function(str)
return "[" .. str .. "]"
end
---add [ ]s and 's for bindings array
---@param str string
---@return string
local makeBindings = function(str)
return addDoubleQuotes(addSquareBrackets(addSingleQuotes(str)))
-- return "\"['" .. str .. "']\""
end end
-- create and set custom_list. Gsettings needs this in order to create bindings before they can be modified. -- create and set custom_list. Gsettings needs this in order to create bindings before they can be modified.
local custom_list = '"[' local custom_list = '"['
@ -23,21 +44,26 @@ end
custom_list = custom_list:sub(1, custom_list:len() - 1) .. ']"' custom_list = custom_list:sub(1, custom_list:len() - 1) .. ']"'
os.execute("gsettings set org.cinnamon.desktop.keybindings custom-list " .. custom_list) os.execute("gsettings set org.cinnamon.desktop.keybindings custom-list " .. custom_list)
-- set bindings -- set bindings
---set bindings via gsettings
---@param index integer
---@param name string
---@param command string
---@param binding string
local gset = function(index, name, command, binding) local gset = function(index, name, command, binding)
local cmd = "gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/cinnamon/desktop/keybindings/custom-keybindings/custom" local cmd = "gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/cinnamon/desktop/keybindings/custom-keybindings/custom"
.. index .. index
.. "/ name " .. "/ name "
.. addQuotes(name) .. addDoubleQuotes(name)
os.execute(cmd) os.execute(cmd)
cmd = "gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/cinnamon/desktop/keybindings/custom-keybindings/custom" cmd = "gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/cinnamon/desktop/keybindings/custom-keybindings/custom"
.. index .. index
.. "/ command " .. "/ command "
.. addQuotes(command) .. addDoubleQuotes(command)
os.execute(cmd) os.execute(cmd)
cmd = "gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/cinnamon/desktop/keybindings/custom-keybindings/custom" cmd = "gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/cinnamon/desktop/keybindings/custom-keybindings/custom"
.. index .. index
.. "/ binding " .. "/ binding "
.. makeBinding(binding) .. makeBindings(binding)
os.execute(cmd) os.execute(cmd)
end end
for i, entry in pairs(entries) do for i, entry in pairs(entries) do