4

In Ubuntu, you can change the default size of the terminal using (edit>profile preferences) to change the size. How can you use the shortcut for bringing up terminal ctrl+alt+T to create two terminals of different sizes so that they are placed one above each other on the right hand side of the screen? So that one has a smaller height than the other but of equal width.

2
  • Um . . .might not be exactly what you wanna, but have you though about using byobu split vertically ? Let me know if you want this added to the answer section Feb 18, 2015 at 7:17
  • My solution in the answer below is now finally complete and tested. It provides both custom sized and placed terminal windows to be opened with the [Ctrl]+[Alt]+[T] shortcut. If you like my answer (I assume this), please accept it by clicking on the gray tick left to it. Thank you!
    – Byte Commander
    Feb 18, 2015 at 12:19

2 Answers 2

2

I will provide you a detailed and tested guide on how you can achieve your desired result.

First a short summary of the steps:

  • Write a short bash script that opens two terminal windows with specified sizes and positions.
  • Set the "executable"-flag of the script file
  • Test the script (to avoid typos and make sure everything works)
  • Disable/Change the old terminal shortcut to free the accelerator keys Ctrl+Alt+T
  • Set the new custom shortcut

Now follows the detailed guide:

As you can only launch a single command with a keyboard shortcut (as far as I know), we have to write a short bash script that opens the two windows. We can also hand a special parameter over to the gnome-terminal that sets the windows' size (in characters, not pixels) and position (in pixels on the screen). It should look like the following:

#!/bin/bash
# File: open-two-terminals.sh
# Purpose: launch two windows of gnome-terminal with different 
#          sizes (in characters) and positions (in pixels)

gnome-terminal --geometry=80x30+400+400 &
gnome-terminal --geometry=60x20+500+50 &

# geometry-syntax: --geometry=[width]x[height]+[x-position]+[y-position]

# Info: & continues with the next command right after the execution
#       of the command it is written after, instead of waiting until
#       the program finished and returns.

Note that you can/must experiment a bit with the geometry values to size and position the windows in exactly the way you want them. I only used example values.

Save these lines (you only need the 1st and those without #, as the others are only comments) into a file like open-two-terminals.sh in whatever location you want. I would suggest your home bin directory /home/MYUSERNAME/bin (create this directory if it does not exist), but you can change this to what you want (as long as it's somewhere in the PATH) as well as the file name, it should only end with .sh.
So I now assume you have a script file /home/MYUSERNAME/bin/open-two-terminals.sh.

The next step is to make the script executable, as by now it is nothing more than a plain text file nice to look at. To do this, run the following command in a terminal: chmod +x /home/MYUSERNAME/bin/open-two-terminals.sh

Now after the executable flag is set, you can do a first test whether you did everything right until now. Run the script by entering open-two-terminals.sh in a terminal window or into the Alt+F2-HUD. It should open two new terminal windows with the different profiles and sizes.

If this works (else you made a mistake and should double-check and try all steps again), you can set the keyboard shortcut.
Go to your System settings panel and click on Keyboard. Change to the Shortcuts tab and select Launchers in the list on the left. You see the shortcut for Launch terminal in the list on the right.

First you have to either disable this shortcut (enter Backspace as new shortcut) or assign (a) different key(s) than Ctrl+Alt+T, as you want to use them later for your custom shortcut.

After that, select Custom shortcuts in the list on the left. Add a new shortcut by clicking on the + symbol below the right list. A window will pop up and request a name for the shortcut (anything you want, e.g. Open Two Terminals) and the command to run (enter the script file created before, e.g. open-two-terminals.sh). Confirm with a click on OK.
Now the last thing we still have to do is to assign the old terminal keys Ctrl+Alt+T to this new shortcut. Therefore click on the right column containing the accelerator keys (default value is Disabled - important, because a click on the left column containing the title opens the popup window) and then press/hold the keys you want to assign to the shortcut. You should see them written on the left of the shortcut's title now.

Close the control panel and enjoy your new double-terminal shortcut! :-D

Hope this detailed guide did help you and solve your question. If this is the case, please accept the answer with a quick click on the gray tick at the left side of it, to show your appreciation. Should you or anyone else reading this have a problem, need further clarification or find an error, please leave me a comment!

7
  • Thank you @Fabby for adding the paragraph on how to place the windows at a constant location. I will try whether it works later. But isn't there a terminal command? It would be easier to just include a line like xmovewindow terminalBig 60 22 (no working code! just example!) after each terminal got launched in the script. I will also research on that and would prefer this solution...
    – Byte Commander
    Feb 18, 2015 at 10:42
  • I gave you a solution: If you don't like it, roll back the edit! ;-) :P (My solution works for terminal and non-terminal windows under Ubuntu, but not on Xubuntu, Lubuntu, Kubuntu, ...)
    – Fabby
    Feb 18, 2015 at 10:47
  • 1
    @Fabby I deleted your paragraph because as we both tested it together, it does not work (window roles seem to be assigned dynamically and therefore change between two executions). However, I finally found a working solution with the --geometry parameter. It also makes the use of different profiles obsolete.
    – Byte Commander
    Feb 18, 2015 at 12:13
  • I'm working on a solution , too, here. Idea for the script is same but for positioning the window , I've different solution. How do you wanna do this - separate answers or should we collab ? Feb 18, 2015 at 13:22
  • How about I'll just post mine first , and then we can decide whether to merge the answers or not ? Feb 18, 2015 at 13:24
0

Basic procedure:

  1. sudo apt-get install wmctrl
  2. touch bin/twoterm.sh && sudo chmod +x bin/twoterm.sh
  3. Copy the script bellow and save it into bin/twoterm.sh file
  4. Create custom shortcut Ctrl+Alt+R , which will call command `gnome-terminal -e /home/yourusername/bin/twoterm.sh

The Script

#!/bin/bash
# Author: Serg Kolo
# Date: 2/18/2015
# Description: A simple script to create two windows on right side
# of the screen with specific size. 

sleep 1

gnome-terminal -t WINDOW-ONE 
gnome-terminal -t WINDOW-TWO

if [  $? == 0  ]

    then
        wmctrl -r WINDOW-ONE -e 0,1300,300,250,250
        sleep 0.5
        wmctrl -r WINDOW-TWO -e 0,1300,0,250,250
fi

Explanation:

  • wmctrl is a program that helps interacting with window managers and open windows. more info in man wmctrl, this and this askubuntu posts
  • gnome-terminal -t WINDOM-TITLE calls for a gnome-terminal window with specific title. No need for creating different profiles, although you may if you decide so. Refer to ByteCommander's answer for that
  • wmctrl -r WINDOW-NAME -e g,x,y,w,h, tells a window with specific title WINDOW-NAME to have exact parameters gravity,x-position on screen, y-position on screen, window width, window height.

Bugs/quirks:

  • Apparently hud executes everything one by one , but gnome-terminal can execute parts of the script much faster, which is why in the short cut i call for gnome-terminal -e '/home/username/bin/twoterm.sh' ; This way there is one gnome-terminal window created for split second which allows two execute the script properly.

  • The reason for if statement is that the script for some reason fails to execute sequentially

  • The reason for sleep statement is to allow the second window catch up with the first one. Apparently the script cannot call two instances of wmctrl at the same time
  • The shortcut+script can be executed only once. If you call the script more than once, you will end up with multiple windows, but the wmctrl command will organize only the original two windows that you called first time

Screenshots:

enter image description here

Alternative script:

Per ByteCommander's suggestion, I've edited the script to be executed purely by the /bin/sh and removed if statement.

#!/bin/bash
# Author: Serg Kolo
# Date: 2/18/2015
# Description: A simple script to create two windows on right side
# of the screen with specific size. 

gnome-terminal -t WINDOW-ONE &
gnome-terminal -t WINDOW-TWO &

sleep 1 
wmctrl -r WINDOW-ONE -e 0,1300,300,250,250 &
wmctrl -r WINDOW-TWO -e 0,1300,0,250,250 &
8
  • I think the idea is ok, but I prefer my own solution without additional software. And the windows in my solution will always get their positions, not depending on which instance it is. You also can not keep the original terminal window title like in my own answer. So I would think we leave both answers how they are and people decide what they like better.
    – Byte Commander
    Feb 18, 2015 at 16:25
  • Fair enough. I'm still gonna touch up a little on the script, see if I can tweak it, but yeah, I guess we can leave it at that Feb 18, 2015 at 16:30
  • @ByteCommander I've ran into a currious bug here. The shortcut doesn't work if there's no other terminal windows open. It brings up one window, but then hangs around until it's closed, brings up second one. So in other words, hud seems to be executing script piece by piece. Is hud supposed to execute just one thing at a time ? Feb 18, 2015 at 16:57
  • @ByteCommander Fixed that already Feb 18, 2015 at 17:34
  • You write an & at the end of all lines that should not block and wait until the command has finished but continue right away.
    – Byte Commander
    Feb 18, 2015 at 18:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .