7

I have been trying to set gnome-terminal --geometry x y's position permanently. I know I would need to find a file that has settings for the terminal but I don't know its location. Basically, what I want is to be in control of where the terminal`s window is positioned when launched.

kos
  • 35,535
  • 13
  • 101
  • 151
Alex Bogdanov
  • 75
  • 1
  • 5
  • Several of the more xwindows parameters to gnome-terminal have been removed recently, including title. I presume this was preparation for the change to mir which has been on the cards for a while but not made it in to the last two releases – Amias May 17 '16 at 08:39
  • [This](https://askubuntu.com/questions/500571/how-to-move-resize-xfce4-terminal-using-the-command-line/790089#790089) works for xterm. Not sure if it is applicable for other terminals. YMMV. – Kevin Bowen Aug 27 '16 at 07:22
  • You could put `alias gnome-terminal="gnome-terminal --geometry x y"` in your startup file (e.g. `~/.bashrc`) – ajwood May 17 '17 at 19:32
  • The suggestion to use an alias doesn't work: The command-line arg "--geometry=WIDTHxHEIGHT+X+Y" only seems to work on WIDTH and HEIGHT (in characters). Different integer values for X and Y seem to have no effect. Am I using this arg wrong? This is how it is documented in --help and manpage. – Jonathan Hartley Feb 15 '22 at 17:01

2 Answers2

5

I don't think there's such a file: such a setting doesn't show up at all, neither in gnome-terminal's preferences nor in gnome-terminal's profile preferences.

However, even though you can't directly set how gnome-terminal starts, you can always set how your system invokes gnome-terminal:

cp /usr/share/applications/gnome-terminal.desktop ~/.local/share/applications
sed -i 's/^Exec=gnome-terminal$/& --geometry=80x24+100+100/' ~/.local/share/applications/gnome-terminal.desktop
gsettings set org.gnome.desktop.default-applications.terminal exec 'gnome-terminal --geometry=80x24+100+100'
  • cp /usr/share/applications/gnome-terminal.desktop ~/.local/share/applications: copies /usr/share/applications/gnome-terminal.desktop in ~/.local/share/applications, i.e. it creates a user-specific version of the system-wide gnome-terminal's desktop file;
  • sed -i 's/^Exec=gnome-terminal$/& --geometry=80x24+100+100/' ~/.local/share/applications/gnome-terminal.desktop: changes the line Exec=gnome-terminal in the user-specific version of the system-wide gnome-terminal's desktop file to Exec=gnome-terminal --geometry=80x24+100+100;
  • gsettings set org.gnome.desktop.default-applications.terminal exec 'gnome-terminal --geometry=80x24+100+100': changes dconf's settings so to tell the desktop environment to run gnome-terminal --geometry=80x24+100+100 instead of gnome-terminal when hitting CTRL+ALT+T.

To revert:

rm ~/.local/share/applications/gnome-terminal.desktop
gsettings set org.gnome.desktop.default-applications.terminal exec 'gnome-terminal'
kos
  • 35,535
  • 13
  • 101
  • 151
  • Hi kos, just curious, what happened to you and your participation on AU? Appreciated your presence here. – Jacob Vlijm Aug 05 '16 at 14:12
  • Works for Ubuntu 20.04! – Edwarric Aug 28 '20 at 09:05
  • In 21,10, for me, the command-line arg `--geometry=WIDTHxHEIGHT+X+Y` only seems to work on WIDTH and HEIGHT (in characters). Different integer values for X and Y seem to have no effect. Am I using this arg wrong? This is how it is documented in --help and manpage. – Jonathan Hartley Feb 15 '22 at 17:03
4

I have also been annoyed by the terminal window popping up in random locations, and it was compounded by the fact that I have multiple monitors flipped vertically and each time the bash terminal would appear at the very top of my screen causing me to have to drag it down to the bottom of the screen, so finally I had to do something about it to fix this issue.

Also, using the solution provided above(making a custom gnome-terminal.desktop file) does not fix the issue in nearly all the cases, like when you right-click on the desktop to launch the Terminal using the "Open Terminal" menu (which I do quite frequently), or if you do "Terminal->New Terminal" from the Terminal's menu, or if you use the hotkey from within the terminal to launch a new window. It does work if you only launch a terminal by clicking the desktop button but for me that was insufficient. So I came up with a solution that would fix this issue and dynamically place the Terminal window at your current pointer position.

I wrote a little bash script that you can put at the very end of your ~/.bashrc and it positions any Terminal window you open at the $X and $Y position of your current mouse pointer position. The script should work right out of the box if you're using the Unity display manager (should just work with other DMs but you might have to tweak the script) and running Ubuntu 16.x (tested on on 16.04).

You'll first need to make sure you install wmctrl and xdotool in a shell type:

sudo apt-get install wmctrl xdotool

Here is the script, copy/paste it using a text editor into the end of your .bashrc file in your home directory:

# This opens new terminal windows at the specified window size
# positioned at your current mouse position on screen 
# On 16.04 Terminals were defaulting to the TOP OF THE SCREEN and 
# since I have vertical 4k monitors this was driving me crazy. 
# This is a good little hack to fix all instances of gnome-terminal
# some which are baked into a core .so like the desktop "Open Terminal" 
# menu for example.  This is fun and should work in all cases :)
#
if [ -n "$XDG_CURRENT_DESKTOP" ] && [ -z ${GIO_LAUNCHED_DESKTOP_FILE+x} ]; 
then
    ###
    # change these to whatever resolution you want
    # the shell width and height to be in pixels:
    xWinWidth=1000
    yWinHeight=750

    xScreenRes=$(xdpyinfo  | grep dimensions | uniq | awk '{print $2}' | cut -d 'x' -f1)
    yScreenRes=$(xdpyinfo  | grep dimensions | uniq | awk '{print $2}' | cut -d 'x' -f2)

    #cool cmd to get mouse postion, returns result into $X and $Y:  
    eval $(xdotool getmouselocation --shell)

    # make sure window's x width stays on screen:
    if(( $(expr $xWinWidth + $X) > xScreenRes ));
    then
        X=$(expr $xScreenRes - $xWinWidth + 30)
    fi

    # make sure the window height stays on screen:
    if(( $(expr $yWinHeight + $Y) > yScreenRes ));
    then
        Y=$(expr $yScreenRes - $yWinHeight + 60)
    fi

    # set the current active window positon which, since this
    # is being run from .bashrc is always the terminal window!
    wmctrl -r :ACTIVE: -e 0,"$X","$Y","$xWinWidth","$yWinHeight"
                         #0,left, top,width,height  
fi
etron
  • 331
  • 2
  • 6
  • @ebron , I've tested your script, and works ok, except by a little detail: I've noticed that the top of the terminal starts at the place where the pointer is when one *selects* the option "Open Terminal". In other words, when I locate the pointer in some point (x,y) and then right click there, the options "New Folder", "New Document", etc. appear, and by the time I arrive to the option "Open in Terminal", it's two low with respect to the initial point (x,y). May you fix this? – Diego Nov 06 '16 at 20:41
  • (+1) Can confirm that it works as advertised on Ubuntu 16.04. This is a great solution as one can play around with the default size too. It first opens a window at Ubuntu's default position (just as before), then shifts the terminal to the mouse's position - so don't be surprised with the small _glitch-like_ movement of terminal. I saved the script into a file called `~/.open-terminal-at-point` and then added a line to my bash file which sources/runs this solution, i.e. add `source .open-terminal-at-point` to the bottom of `~/.bashrc`, just preventing the bash file from becoming cluttered. – n1k31t4 Apr 08 '17 at 09:38