Scripting GNOME Terminal Tabs in Debian
I know folks that have so many Chrome tabs open that they live in fear of their computer turning off because they have no idea how they will get back to work. I suffer from the same problem, but with with terminal tabs.
I run a few services on a server that I connect to remotely over ssh. This includes mutt for email, and weechat for hanging out on irc. I also ssh into my server whenever I want to schedule a new post for social media via the POSSE dagger module that I am working on.
The main reason I do this over SSH is because I work from a few different computers, and a few different operating systems. It feels really nice to always be able to get back to my workspace without having to configure anything anywhere else.
Throughout the day I’ll pop open a GNOME terminal window and ssh into my server, open up mutt, and getting to work. This works really well, except sometimes I’ll be in the middle of writing an email when my connection dies for some reason and my in-progress message is lost forever.
This is where tmux comes to the rescue. tmux allows you create a resilient terminal session that can withstand network issues, create split panes in the same window, move long running tasks to the background, and overall makes doing important work on a server a lot less error prone. When I was at Linode, someone taught me that “if it’s worth doing, it’s worth doing in tmux”. I think about that often, especially when I am doing things that I should be doing in tmux outside of tmux and live to regret it.
The only downside is that this increases the complexity of the command.
Now instead of ssh myserver && mutt
I have to ssh myserver && tmux attach -t mutt
where mutt
in the second example is a named tmux session that
I created with tmux new -s mutt
.
It’s not so bad, but I also want to open up a separate tab and run a similar command to connect to my irc window that is running weechat. I also want to have a blank prompt directly on the server in case I ever want to do something else.
After about 100 manual invocations, yesterday I finally decided that there has to be a better way. I am running the built in GNOME terminal in Debian right now, so I decided to RTFM to see if there is anything I could find. The good news is that GNOME terminal does have some built-in scripting capabilities.
This allows me to write a script like this which opens up three named tabs with an ssh session that connects to my tmux session and puts my gnome-terminal in the exact state that I want it to be in.
#!/bin/bash
gnome-terminal \
--tab -t irc -e 'ssh -t myserver.com "tmux attach -t irc"'\
--tab -t mutt -e 'ssh -t myserver.com "tmux attach -t mutt"'\
--tab -t myserver -e 'ssh -t myserver.com'
I saved this script as /usr/local/bin/work
so now I can call it from
any other terminal and it will do the right thing. Better yet, I can
open up the “Run a Command” dialog in GNOME using Alt + F2, type in
work
and get right to work.
Thanks to gnome-terminal, ssh, tmux, and a sprinkle of bash, the next time I accidentally close a gnome-terminal window with a bunch of open tabs I’m a command away from getting right back to where I was.
Thank you for reading! Share your thoughts with me on mastodon or via email.
Check out some more stuff to read down below.
Most popular posts this month
- Dagger Feels Like Magic
- Setting up ANTLR4 on Windows
- SQLite DB Migrations with PRAGMA user_version
- 20 Years of Ubuntu
- видно по глазам - you can see it in the eyes
Recent Favorite Blog Posts
This is a collection of the last 8 posts that I bookmarked.
- Serendipity from Armin Ronacher's Thoughts and Writings
- Andrea Veri: GNOME Infrastructure migration to AWS from Planet GNOME
- A Whale of a Time from https://popagandhi.com/
- Pluralistic: You should be using an RSS reader (16 Oct 2024) from Pluralistic: Daily links from Cory Doctorow
- Sahil Dhiman: 25, A Quarter of a Century Later from Planet Debian
- Reflections on Palantir from Nabeel S. Qureshi
- Reading Old Posts from Kev Quirk
- Capture less than you create from David Heinemeier Hansson
Articles from blogs I follow around the net
Script Doctoring
I’ve been having a number of communications problems in my interactions with my doctors at Kaiser lately, and it’s becoming one of those things where the burden and onus entirely is placed upon me to sort out, and that’s exhausting for the actually autist…
via Bix Dot Blog October 22, 2024Blockchain company Forte acquires games studios, demands secrecy, shuts them down
Sometime in 2023, blockchain firm Forte acquired game studios Phoenix Labs and Rumble Games. However, it would be a year before this came to light, because according to a report from Game Developer, Forte demanded secrecy from employ…
via Web3 is Going Just Great October 22, 2024Initial explorations of Anthropic's new Computer Use capability
Two big announcements from Anthropic today: a new Claude 3.5 Sonnet model and a new API mode that they are calling computer use. (They also pre-announced Haiku 3.5, but that's not available yet so I'm ignoring it until I can try it out myself.) Comp…
via Simon Willison's Weblog: Entries October 22, 2024Generated by openring