-
Notifications
You must be signed in to change notification settings - Fork 26
A contributed configuration
Avindra Goolcharan edited this page Jan 11, 2021
·
4 revisions
Thanks to Evgeny for an excellent terminal!
It took me a while to settle on this profile which I think is close to what has become a 'standard' (if there is such a thing) in the terminal world. Posting here in the hope that it is useful to others.
- Ctrl-plus/minus/0 etc for dynamic font size adjustment
- Shift-insert to insert PRIMARY selection (ie whatever you just selected with the mouse) Requires xvkdb or xdotool
- Ctrl-Shift-c/v for copy/paste CLIPBOARD selection
- Clicking on a URL can either just copy the URL to the CLIPBOARD, open it in your browser or popup a menu to select
- Ctrl-f1 etc to select the nth tab
- Ctrl-tab to select the next tab; CtrlShift-tab for the previous
- Ctrl-g / f to toggle on/off the tab bar and the menu bar
Put this in $HOME/.config/termit/rc.lua
:
function notify (url, msg)
os.execute("notify-send '"..url.."' "..msg)
end
function handle_url_simple_copy (url)
-- simply copies the url
-- requires package xclip
local url = string.gsub(url,"\n.+$", "")
os.execute ("echo -n '"..url.."' | xclip -i -selection clipboard")
notify (url, "copied")
end
function handle_url_simple_open (url)
-- simply opens the url
-- requires package xdg-utils
local url = string.gsub(url,"\n.+$", "")
os.execute ("xdg-open '"..url.."'")
notify (url, "opened")
end
function handle_url_zenity (url)
-- pops up a dialog to allow choice of copying or opening the url
-- requires package zenity and the termit-zenity-dialog script
local url = string.gsub(url,"\n.+$", "")
os.execute("termit-zenity-dialog '"..url.."' &") -- make it async otherwise this termit waits
end
function handle_url_lgi (url)
-- pops up a dialog to allow choice of copying or opening the url
-- also allows editing of the url before copying/opening
-- requires package lua-lgi and the termit-lgi-dialog script
local url = string.gsub(url,"\n.+$", "")
os.execute("termit-lgi-dialog '"..url.."' &") -- make it async otherwise this termit waits
end
defaults = {}
defaults.windowTitle = 'Termit'
defaults.tabName = 'Terminal'
defaults.encoding = 'UTF-8'
defaults.wordChars = '+-AA-Za-z0-9,./?%&#:_~'
defaults.scrollbackLines = 4096
defaults.font = 'Monospace 8'
defaults.geometry = '80x24'
defaults.hideSingleTab = false
defaults.showScrollbar = true
defaults.fillTabbar = false
defaults.hideMenubar = false
defaults.allowChangingTitle = true
defaults.visibleBell = false
defaults.audibleBell = false
defaults.urgencyOnBell = false
defaults.matches = {['http[^ \'\"]+'] = handle_url_lgi } -- choose one of the above
setOptions(defaults)
function get_primary()
os.execute ("type xvkbd && xvkbd -text '\\m2' || xdotool click 2")
end
function changeTabFontSize(delta)
tab = tabs[currentTabIndex()]
setTabFont(string.sub(tab.font, 1, string.find(tab.font, '[0-9.]+$') - 1)..(tab.fontSize + delta))
end
bindKey('Ctrl-t', nil) -- needed for bash
bindKey('CtrlShift-t', openTab)
bindKey('CtrlShift-Tab', prevTab)
bindKey('Ctrl-Tab', nextTab)
bindKey('CtrlShift-f', toggleMenubar)
bindKey('CtrlShift-g', toggleTabbar)
bindKey('CtrlShift-v', paste)
bindKey('CtrlShift-c', copy)
bindKey('Shift-Delete', copy)
bindKey('Ctrl-Insert', copy)
bindKey('Shift-Insert', function() get_primary() end)
bindKey('Ctrl-F1', function () activateTab(1) end)
bindKey('Ctrl-F2', function () activateTab(2) end)
bindKey('Ctrl-F3', function () activateTab(3) end)
bindKey('Ctrl-F4', function () activateTab(4) end)
bindKey('Ctrl-F5', function () activateTab(5) end)
bindKey('Ctrl-F6', function () activateTab(6) end)
bindKey('Ctrl-F7', function () activateTab(7) end)
bindKey('Ctrl-F8', function () activateTab(8) end)
bindKey('Ctrl-F9', function () activateTab(9) end)
bindKey('CtrlShift-equal', function () changeTabFontSize(1) end)
bindKey('Ctrl-equal', function () changeTabFontSize(1) end)
bindKey('Ctrl-minus', function () changeTabFontSize(-1) end)
bindKey('Ctrl-0', function () setTabFont(defaults.font) end)
setKbPolicy('keycode')
Put this in termit-zenity-dialog
on your $PATH and make it executable with chmod +x termit-zenity-dialog
#!/usr/bin/env lua
function notify (url, msg)
os.execute("notify-send '"..url.."' "..msg)
end
url = arg[1]
print ("handle_url_zenity("..url..")")
local handle = io.popen ('echo -e "copy url\nopen url" | zenity --list --title "URL" --text "URL: '..url..'" --column "Choice"')
local result = handle:read("*a")
handle:close()
print ("result = "..result)
if result == "copy url\n" then
os.execute ("echo -n '"..url.."' | xclip -i -selection clipboard")
notify (url, "copied")
elseif result == "open url\n" then
os.execute ("xdg-open '"..url.."'")
notify (url, "opened")
end
Put this in termit-lgi-dialog
on your $PATH and make it executable with chmod +x termit-lgi-dialog
:
#!/usr/bin/env lua
function handle_url_lgi (url)
-- requires package lua-lgi
local lgi = require 'lgi'
local Gtk = lgi.require('Gtk', '3.0')
local assert = lgi.assert
local buffer
function button_press(dialog, response)
print ("response = "..tostring(response))
url = buffer.get_text(buffer)
print ("url = '"..url.."'")
local s = ""
local msg = ""
if response == 1.0 then
s = "echo -n '"..url.."' | xclip -i -selection clipboard"
msg = "copied"
elseif response == 2.0 then
s = "xdg-open '"..url.."'"
msg = "opened"
end
if s ~= "" then
print ("executing '"..s.."'")
os.execute (s)
os.execute("notify-send '"..url.."' "..msg)
end
Gtk.Widget.destroy(dialog)
end
local window = Gtk.Dialog {
title = "URL",
resizable = false,
on_response = button_press,
buttons = {
{ "Copy URL", 1 },
{ "Open URL", 2 },
{ "Cancel", 0 },
},
}
buffer = Gtk.EntryBuffer()
local content = Gtk.Box {
orientation = 'VERTICAL',
spacing = 5,
border_width = 5,
Gtk.Label {
label = "URL",
use_markup = true,
},
Gtk.Entry {
buffer = buffer,
text = url,
},
}
window:get_content_area():add(content)
window:show_all()
local app = Gtk.Application { application_id = 'foobar.com' }
function app:on_activate()
-- Assign the window as the application one and display it.
window.application = self
window:show_all()
end
-- Run it
app:run { arg[0] }
end
handle_url_lgi(arg[1])