Is there a way in Ubuntu 18.04.3 LTS that once a tab of "Terminal" window is detached from that window, to re-attach that tab to the another already opened Terminal window (with other tabs) again?
I just upgraded to Ubuntu 20.04 and I am unable to toggle between the tabs in the terminal with the mouse wheel, which was fine in 18.04. I can't find where this feature is enabled. Is it possible that this feature has been removed?
What I'm trying to do:
- Write a script to open 3 tabs.
cd
into a different folder in each tab (ie: run a unique command).- get each tab to have a unique title by modifying its local
PS1
variable - Ensure each tab stays open after the script is run
I want this scripted so I can click the script on my Desktop and have it open up terminals as I'd like for my daily development environment.
Description:
I have this script to try and open 3 terminal tabs with unique commands to be run in the tabs:
open_tabs.sh
#!/bin/bash
gnome-terminal --tab -- bash -ic "set-title title 1; exec bash"
gnome-terminal --tab -- bash -ic "cd ~; set-title title 2; exec bash"
gnome-terminal --tab
When I run it with ./open_tabs.sh
, it opens up 3 new tabs, but unfortunately set-title
doesn't work to set the tab title! It appears the PS1
variable isn't staying set with my set-title
call. The exec bash
is there to keep the tab open, per this answer and comments underneath it.
I have set-title
defined as a function in ~/.bashrc
like this. Its purpose is to set the title string at the top of any terminal window. It works perfectly when I use it manually. Ex: set-title hey how are you?
will put "hey how are you?" at the top of my terminal window.
# From: https://unix.stackexchange.com/questions/177572/how-to-rename-terminal-tab-title-in-gnome-terminal/566383#566383
set-title() {
# If the length of string stored in variable `PS1_BAK` is zero...
# - See `man test` to know that `-z` means "the length of STRING is zero"
if [[ -z "$PS1_BAK" ]]; then
# Back up your current Bash Prompt String 1 (`PS1`) into a global backup variable `PS1_BAK`
PS1_BAK=$PS1
fi
# Set the title escape sequence string with this format: `\[\e]2;new title\a\]`
# - See: https://wiki.archlinux.org/index.php/Bash/Prompt_customization#Customizing_the_terminal_window_title
TITLE="\[\e]2;$@\a\]"
# Now append the escaped title string to the end of your original `PS1` string (`PS1_BAK`), and set your
# new `PS1` string to this new value
PS1=${PS1_BAK}${TITLE}
}
How do I fix this so that each tab runs a command, sets its title by modifying its PS1
variable, and stays open?
Note that gnome-terminal
has deprecated its --title
and --command
options, hence these work-arounds.
Related:
- bash: "command not found" when calling function defined in ~/.bashrc file in `bash -c` command while opening gnome-terminal tab
- https://unix.stackexchange.com/questions/177572/how-to-rename-terminal-tab-title-in-gnome-terminal/566383#566383
Open Terminal with multiple tabs and execute application <== this is what I'm really trying to solve, but
gnome-terminal
's--command
(-e
) option is now deprecated!# Option “--command” is deprecated and might be removed in a later version of gnome-terminal. # Use “-- ” to terminate the options and put the command line to execute after it.
I have created a keyboard shortcut that initiates an SSH session to my server which works as expected and there is no issue with that.
However, to enable faster access to multiple log files I have resorted to opening multiple terminals with the same command, this means several terminals each with its own ssh session.
What would like to happen is to have just one terminal/ssh session and open each log file under a separate tab.
How would you approach this?
The current keyboard shortcut I use is: (previously -x updated --):
gnome-terminal -- ssh server1r
Note: server1r is a just a predefined ssh configuration in ~/.ssh/config
Previously: running this in the terminal creates a new tab showing the error log:
gnome-terminal --tab-with-profile=basic -- ssh server1r "tail /var/log/apache2/error.log -f"
Previously: This is where I am at now using information gleaned from various sources including man gnome-terminal, :
gnome-terminal --tab-with-profile=basic -- ssh server1r "tail ~/logs/error.log -f -n500" && gnome-terminal --tab-with-profile=basic -- ssh server1r "tail ~/logs/access.log -f -n500"
The above code runs perfectly from the terminal, creating two new tabs with the log entries shown. However, putting the command into the keyboard shortcuts doesn't work as expected. only the first log is opened and no tabs are created.
Keyboard shortcut entered exactly as above in: settings > devices > keyboard > custom shortcuts
Final Update: I have created a bash script using last code block as a temporary workaround giving me a terminal for each log. From this point I will check in periodically so see if anybody answers with a better solution, but at least for now I can open all of the required logs from one keyboard shortcut.
Edit : other answer talked about change the title of the terminal, not a tab, but effectively they answer to my question too. Everything is great.
I'm a newbie and I wonder how give a specific name to a terminal tab instance ?
Here an instance of my question :
Currently I have just few knowledge in Ubuntu system. Thanks