tilda terminal emulator

Miscellaneous tools
Post Reply
Message
Author
User avatar
rufwoof
Posts: 3690
Joined: Mon 24 Feb 2014, 17:47

tilda terminal emulator

#1 Post by rufwoof »

tilda terminal emulator is similar to lxterminal, but is activated via a hotkey. Supports multiple tabs, cut/paste via a menu and you can set it to follow url links (ctrl-click a link and it opens your browser to that link assuming you've defined your browser in the tilda configuration (right click, preferences menu option)).

I had been using tmux, but have switched over to tilda primarily for the better (IMO) cut/paste and link following functions.

But tilda is lacking compared to tmux is some (many) respects. Setting tab titles for instance, and having it start with multiple tabs activated.

Initially I started running tilda with a command to ssh to my ssh server

tilda -c "ssh user@sshserver.org"

however tilda stores that as its initial command ... so add another tab/window and it runs that command again by default. The workaround I used was to create a file in /tmp first and then run tilda in the background set to that command, and then change the /tmp file content. Something like

echo "#!/bin/sh" >/tmp/TILDA
echo "TERM=screen ssh user@sshserver.org" >>/tmp/TILDA
chmod 700 /tmp/TILDA
tilda -c /tmp/TILDA &
sleep 3
echo "#!/bin/sh" >/tmp/TILDA
echo "TERM=linux /bin/sh" >>/tmp/TILDA
chmod 700 /tmp/TILDA

... and that works fine. First time its run it opens tilda and a ssh connection (I set the TERM for that to screen as I run screen in that ssh session), and if another tilda tab/window is opened then it runs /bin/sh in that window.

The next desire was to have multiple tilda tabs open at startup. For that I opted to use xdotool. Ctrl-T (ctrl-shift-t) in tilda adds a new tab, so
xdotool key ctrl+T
... and then to set the tabs title I use the escape code
newTitle=$1
echo -e "\x1B]2;${newTitle}\x07 tab --> [${newTitle}]"
... and of course whatever command/program I want to have running in that tap.

So I've swapped out using tmux for using tilda combined with screen. tilda is set to toggle show/hide on pressing F1, and I've set the window size to be full screen, less the height of the tray. That way I can flip between terminal and gui quick/easily.

Typically I'm running ssh to my ssh server in one tilda tab, where that's running screen within which I run irc, mutt (mail); And in other tilda tabs I have mc (file manager/text editor), bmon (network traffic monitoring), htop (system utilisation) and a simple press of F1 flips to that view, F1 again to switch back to gui (typically browser with its multiple tabs on one desktop, music player on another desktop).

I've taken that a further yet, and have my .ssh folder in a encrypted folder, and decrypt that in Startup and run tilda ... which connects to my ssh server as above, and also opens a sshfs connection so the ssh servers folder is presented as a local folder in rox. I also setup a socks proxy connection so all my browser traffic routes via a ssh tunnel. Once that's all setup the script closes the decrypted folder, so its encrypted again as the ssh keys are done with once the ssh connections have all been made, which hides my .ssh folder (private keys). So if my system is cracked, the cracker wont see the .ssh keys. Or if my laptop is stolen they can't connect to the ssh server.

I'm using a free hashbang.sh account for my ssh server. For socks proxy, email and irc predominately. screen/tilda for irc is nice as you can just detach (ctrl-a d) and later return (screen -r) having left irc running and provided you've set tilda's buffer to a reasonable size (I have mine set to 1000 lines) then you can scroll back (page-up/down) through the days/historic irc postings.
[size=75]( ͡° ͜ʖ ͡°) :wq[/size]
[url=http://murga-linux.com/puppy/viewtopic.php?p=1028256#1028256][size=75]Fatdog multi-session usb[/url][/size]
[size=75][url=https://hashbang.sh]echo url|sed -e 's/^/(c/' -e 's/$/ hashbang.sh)/'|sh[/url][/size]

User avatar
rufwoof
Posts: 3690
Joined: Mon 24 Feb 2014, 17:47

tilda terminal emulator open with multiple tabs

#2 Post by rufwoof »

I call a script very similar to this (except with my actual hashbang userid rather than xxxxx) from within ~/Startup. My ssh .ssh folder is a sym link to a encrypted folder that I open (so requires a password be entered), and then make all of the ssh connections, before closing that folder again, which keeps the ssh keys more secure (i.e. once ssh connections have all be established the keys are no longer required to be visible). Which means I only have to enter the password once, at startup. Without that password, if the laptop is stolen, the thief cannot access my .ssh folder (ssh keys). I store my calendar (calcurse) file on the ssh server in encrypted form, so that is secure and set up a sshfs so that is locally available after the sshfs connection has been established. Minimising the number of times you enter a password in X is good practice and in this case I just enter it once, as part of startup.

The script loads up tilda with a range of windows (tabs). The first tab is a ssh tunnel to hashbang where that runs "screen" (terminal multiplexor) on hashbang (the free ssh server I use) and that has screen windows for irssi and mutt.

The script provides a feel for how you might adapt the code to start tilda with your own set of tabs already pre-loaded and ready to use

Code: Select all

#!/bin/bash

_tab () {
		# escape code to change a tilda terminals tab label
		# and run a command in the tab
		#
		# $1 label to set tab title to
		# $2 command to run on tab

		newtitle=$1
		command=$2
		esc="\"\\x1B]2;${newtitle}\\x07\""
		xdotool key ctrl+T				# add a new tilda tab
		xdotool type 'echo -e ' $esc
		xdotool key KP_Enter
		xdotool type "$command"
		xdotool key KP_Enter
}

_hashbang_sshfs_and_socks () {
	
	# I've substituted xxxxx here for my actual hashbang userid
	
		# set up sshfs mounted to local /hb folder
		[ ! -d /hb ] && mkdir /hb
		chmod go-wrx /hb
		sshfs xxxxx@ny1.hashbang.sh:/home/xxxxx /hb &

		# and start the socks proxy
		ssh -D 9999 -q -C -N xxxxx@ny1.hashbang.sh &
		PIDSSH=$!
		echo $PIDSSH >/tmp/PIDSSH	# record that its running
}

_wait_for_network () {
	
	cnt=0
	while :; do  # validate network available (try each second for 20 seconds max)
		ping -q -w 1 -c 1 `ip r | grep default | cut -d ' ' -f 3` && break || sleep 1
		cnt=`expr $cnt + 1`
		if [ $cnt -gt 20 ]; then
			xmessage "No network connection detected - aborting ssh socks proxy setup"
			exit
		fi
	done
}

_wait_for_network

# Set up socks proxy, sshfs, tilda tabs ..etc
if [ ! -f /tmp/PIDSSH ]; then
	# if not already available open up encrypted folder that contains our .ssh folder
	[ ! -d /mnt/sda3/PRIVATE/.ssh ] && xterm -e /mnt/sda1/private-open

	if [ -d /mnt/sda3/PRIVATE/.ssh ]; then
	
		# activate tilda ssh'd to hashbang
		# i.e. we run tilda using "tilda /tmp/TILDA"
		echo "#!/bin/sh" >/tmp/TILDA
		echo "TERM=screen ssh hashbang" >>/tmp/TILDA
		chmod 700 /tmp/TILDA
		tilda -c "/tmp/TILDA" &
		sleep 2 # time for tilda in background to work
		# so that opening another tilda tab doesn't reinvoke ssh ...
		echo "#!/bin/sh" >/tmp/TILDA
		# set TERM to screen for line drawing purposes 
		echo "TERM=linux /bin/sh" >>/tmp/TILDA 
		chmod 700 /tmp/TILDA
		
		# set up sshfs to hashbang and socks proxying
		_hashbang_sshfs_and_socks
		
		# return to tilda and activate additional tabs/windows		
		xdotool key F1		# F1 is assumed to be the tilda window toggle key
		
		# prepare for xdotool'ing
		winid=`xdotool search --all --pid $pid | head -1`
		# first visible window owned by pid
		xdotool windowactivate $winid
		sleep 2

		# add additional tilda tabs
		_tab "calcurse" "TERM=linux calcurse"
		_tab "sw19" "TERM=linux curl wttr.in/sw19?2n"
		_tab "mc" "TERM=screen mc /mnt/sda1"
		_tab "bmon" "TERM=linux bmon"
		_tab "htop" "TERM=linux htop"
		_tab "alsa" "TERM=linux alsamixer"
		
		# we cant set the tab name for the first tab until other tabs
		# already exist, so we return to tab 1 now to rename it
		xdotool key alt+1	# alt and a tab number to change tabs in tilda
		xdotool type 'echo -e  "\x1B]2;hashbang\x07"'
		xdotool key KP_Enter
		# and reconnect to screen
		xdotool type "screen -r"
		xdotool key KP_Enter		
		
		xdotool key F1    # hide tilda again
	else
		xmessage "Invalid password"
		exit
	fi
else
	xmessage "/tmp/PIDSSH exists - already running ??"
fi
sleep 4
/mnt/sda1/private-close
umount /mnt/sda3
Attachments
xscreenshot-20190505T192421.png
(62.22 KiB) Downloaded 358 times
[size=75]( ͡° ͜ʖ ͡°) :wq[/size]
[url=http://murga-linux.com/puppy/viewtopic.php?p=1028256#1028256][size=75]Fatdog multi-session usb[/url][/size]
[size=75][url=https://hashbang.sh]echo url|sed -e 's/^/(c/' -e 's/$/ hashbang.sh)/'|sh[/url][/size]

User avatar
rufwoof
Posts: 3690
Joined: Mon 24 Feb 2014, 17:47

bmon adjusting graph height

#3 Post by rufwoof »

After adjusting the tilda default height (in right click - Properties), so that tilda fits the entire width (100%) and revising the height so that the default desktop drive icons are still visible when tilda is open, bmon for my resolution and choice of default font size no longer displayed the net activity graph. To 'fix' (resolve) that I adjusted the bmon graph height from the default 6 value to 5. So now to show my wlan0 default interface (wireless) the command is ...

Code: Select all

bmon -o curses:gheight=5 -p wlan0
Image

My current code (script in /root/Startup) now looks like ...

Code: Select all

#!/bin/bash 

# Requires xdotool (install via your PPM)

_tab () { 
      # escape code to change a tilda terminals tab label 
      # and run a command in the tab 
      # 
      # $1 label to set tab title to 
      # $2 command to run on tab 

      newtitle=$1 
      command=$2 
      esc="\"\\x1B]2;${newtitle}\\x07\"" 
      xdotool key ctrl+T            # add a new tilda tab 
      xdotool type 'echo -e ' $esc 
      xdotool key KP_Enter 
      xdotool type "$command" 
      xdotool key KP_Enter 
} 

echo "#!/bin/sh" >/tmp/TILDA 
echo "TERM=screen /bin/sh" >>/tmp/TILDA 
chmod 700 /tmp/TILDA 
tilda -c "/tmp/TILDA" & 
sleep 2 # time for tilda in background to work 
echo "#!/bin/sh" >/tmp/TILDA 
# set TERM to screen for line drawing purposes 
echo "TERM=linux /bin/sh" >>/tmp/TILDA 
chmod 700 /tmp/TILDA 
       
# prepare for xdotool'ing 
winid=`xdotool search --all --pid $pid | head -1` 
# first visible window owned by pid 
xdotool windowactivate $winid 
sleep 2 

# add additional tilda tabs 
_tab "calcurse" "TERM=linux calcurse" 
_tab "sw19" "TERM=linux clear;curl wttr.in/sw19?1n" 
_tab "mc" "TERM=screen mc /mnt/sdb1" 
# have to restrict the bmon graph height otherwise doesn't show on 
# my setup (my choice of terminal font size). Default is 6 
_tab "bmon" "TERM=linux bmon -o curses:gheight=5 -p wlan0" 
_tab "htop" "TERM=linux htop" 
_tab "ncdu" "TERM=linux ncdu" 
_tab "alsa" "TERM=linux alsamixer" 

# we can't set the tab name for the first tab until other tabs 
# already exist, so we return to tab 1 now to rename it 
xdotool key alt+1   # alt and a tab number to change tabs in tilda 
xdotool type 'echo -e  "\x1B]2;hashbang\x07"' 
xdotool key KP_Enter  
xdotool type "ssh hashbang"
xdotool key KP_Enter 
[size=75]( ͡° ͜ʖ ͡°) :wq[/size]
[url=http://murga-linux.com/puppy/viewtopic.php?p=1028256#1028256][size=75]Fatdog multi-session usb[/url][/size]
[size=75][url=https://hashbang.sh]echo url|sed -e 's/^/(c/' -e 's/$/ hashbang.sh)/'|sh[/url][/size]

User avatar
rufwoof
Posts: 3690
Joined: Mon 24 Feb 2014, 17:47

#4 Post by rufwoof »

Some more screenshots of my tui (text user interface) tilda tabs are shown here ...
http://murga-linux.com/puppy/viewtopic. ... 23#1029923
[size=75]( ͡° ͜ʖ ͡°) :wq[/size]
[url=http://murga-linux.com/puppy/viewtopic.php?p=1028256#1028256][size=75]Fatdog multi-session usb[/url][/size]
[size=75][url=https://hashbang.sh]echo url|sed -e 's/^/(c/' -e 's/$/ hashbang.sh)/'|sh[/url][/size]

User avatar
rufwoof
Posts: 3690
Joined: Mon 24 Feb 2014, 17:47

mc user menus

#5 Post by rufwoof »

tilda as a Quake (game) like drop down (F1 toggle) terminal along with midnight commander for file manager and text editing is a great combination.

We can however improve upon that relatively easily - that adds menu/program launch type functionality on top of that. mc includes a F2 'user menu' option that few seem to use, so I'll add a little insight into how that can be setup/used.

Simply create a .mc.menu file in a folder, where that .mc.menu file contains ...

Code: Select all

H     Run htop
        htop

s      Run a shell
        /bin/sh

g      Run Geany
         geany
Once saved, then in mc pressing F2 whilst viewing that folder content will launch that folders .mc.menu. Note that you can have different .mc.menu files in different folders.

In the above code, the first character such as H is the key that will launch that command (ie shift-h (capital H)) when the menu is visible, alternatively use the up and down arrows to navigate to the desired menu option and press ENTER. The text following that launch keycode/character is the text that is shown for that menu option. The line(s) after that are the command(s) that will be run when that menu option is selected.

There's a wealth of additional possibilities and a good starting point reference is this http://linuxcommand.org/lc3_adv_mc.php - specifically the User Menu section that starts at around three-quarters of the way down that web page.

Note also that mc reads the .mc.menu dynamically, so it could be updated and the next time F2 is pressed that updated menu is shown.

Also note that if .mc.menu doesn't exist in the current folder that mc is displaying then it looks for ~/.config/mc/menu and if that doesn't exist then it falls back to using the system wide menu /usr/share/mc/mc.menu

So now you know how to not only just use mc as a file manager and text editor (mc -e), but also how to set up mc so it can act as a user defined program launcher/menu system :)

A great thing about mc is that once you're familiar with its key bindings, such as F4 to edit, F5 to copy ... and now the F2 user menu choice, then not only can you use that on your local system, but also any other remote server that you might log into that has mc installed - and being textual (tui/ncurses) it tends to run remote versions just as quick as local versions.

Combined with tilda's Quake like drop down hide/show terminal toggle action, you can toggle between gui an tui in a flash, and under some usage navigating and launching programs/actions via tui can be quicker than using gui.
Attachments
s.png
(97.81 KiB) Downloaded 223 times
[size=75]( ͡° ͜ʖ ͡°) :wq[/size]
[url=http://murga-linux.com/puppy/viewtopic.php?p=1028256#1028256][size=75]Fatdog multi-session usb[/url][/size]
[size=75][url=https://hashbang.sh]echo url|sed -e 's/^/(c/' -e 's/$/ hashbang.sh)/'|sh[/url][/size]

Post Reply