73 lines
2.4 KiB
Lua
Executable File
73 lines
2.4 KiB
Lua
Executable File
#!/usr/bin/env lua
|
|
-- This is where you add the bindings. Entries contain three strings: 1 - name, 2 - shell command, and 3 - keybinding.
|
|
local entries = {
|
|
{
|
|
"Toggle terminal transparency",
|
|
"${HOME}/scripts/toggle-term-transparency.sh",
|
|
"<Primary>dead_acute",
|
|
},
|
|
{
|
|
"Toggle bg",
|
|
"${HOME}/scripts/switch-bg.sh t",
|
|
"<Primary>ccedilla",
|
|
},
|
|
}
|
|
---add " marks to either end of a string
|
|
---@param str string
|
|
---@return string
|
|
local addDoubleQuotes = function(str)
|
|
return '"' .. str .. '"'
|
|
end
|
|
---add ' marks to either end of a string
|
|
---@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
|
|
-- create and set custom_list. Gsettings needs this in order to create bindings before they can be modified.
|
|
local custom_list = '"['
|
|
for i, _ in pairs(entries) do
|
|
custom_list = custom_list .. "'custom" .. (i - 1) .. "',"
|
|
end
|
|
-- remove last comma, close bracket etc
|
|
custom_list = custom_list:sub(1, custom_list:len() - 1) .. ']"'
|
|
os.execute("gsettings set org.cinnamon.desktop.keybindings custom-list " .. custom_list)
|
|
-- 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 cmd = "gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/cinnamon/desktop/keybindings/custom-keybindings/custom"
|
|
.. index
|
|
.. "/ name "
|
|
.. addDoubleQuotes(name)
|
|
os.execute(cmd)
|
|
cmd = "gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/cinnamon/desktop/keybindings/custom-keybindings/custom"
|
|
.. index
|
|
.. "/ command "
|
|
.. addDoubleQuotes(command)
|
|
os.execute(cmd)
|
|
cmd = "gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/cinnamon/desktop/keybindings/custom-keybindings/custom"
|
|
.. index
|
|
.. "/ binding "
|
|
.. makeBindings(binding)
|
|
os.execute(cmd)
|
|
end
|
|
for i, entry in pairs(entries) do
|
|
gset(i - 1, entry[1], entry[2], entry[3])
|
|
end
|
|
print("REMEMBER: Cinnamon has to be restarted (ctrl+alt+esc) before these changes will take effect!")
|