Sunday, May 5, 2024
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 22278  / 1 Year ago, thu, december 15, 2022, 12:32:51

I'm trying to open up a few terminal tabs in gnome-terminal, and so far I've managed to do something, but I'm stuck now.



So, I have the following requirement:




  • Open tabs titled "X" and "Y"

  • Execute some commands

  • Keep the tabs open and ready for further use; keep the title.



So far, I managed to meet some of the requirements, but not all of them:



gnome-terminal --tab -t "X" -e "bash" --tab -t "Y" -e "top"


This opens two tabs:




  1. "X" (and then changes the title to the default title)

  2. "Y", but the tab closes as soon as I quit top.



Is there a way to open up a tab, launch bash, but not change the title? I've tried Google, but gave up.



EDIT: It doesn't has to be a command.


More From » gnome-terminal

 Answers
1

As you can see in other answers, the title of the tab is changed by the shell every time it outputs a prompt. And after executing top your tab exits because the command you told it to run finishes...



I'll do the following:



Step 1: call the terminal with shells, adding environment variables like that:



gnome-terminal --tab -t X -e "env MYTAB=X bash" --tab -t Y -e "env MYTAB=Y bash" 


Step 2: add at the end of your .bashrc the following code:



#if MYTAB is not set, return
[ -z "$MYTAB" ] && return
# reset the cursor and title
PS1='${debian_chroot:+($debian_chroot)}u@h:w$ '
PS1="[e]0;$MYTAB wa]$PS1" #title: $MYTAB and current dir
# execute the commands for every tab
case "$MYTAB" in
X)
echo this is X
;;

Y)
echo this is Y
top
;;
esac


...which I think is easy to understand and you can modify with the command/tweaks you need. Tested and works ok; after you exit top from the tab you'll still have the prompt and the tab for you to peruse.



Screenshot (after pressing "q" in top):



screenshot


[#26089] Friday, December 16, 2022, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
atchcommo

Total Points: 114
Total Questions: 130
Total Answers: 101

Location: Cook Islands
Member since Sat, Oct 16, 2021
3 Years ago
;