I'm not looking for a keyboard shortcut, rather I want a commands for:
- New window
- New Tab
- Close Current tab or window
- Maximise Shell Window
- Minimise Shell Window
- Move Shell to a different work-space
- Switch Tab
And basically anything like this. Remember; I do not want shortcuts, but rather actual commands. The reason for this is so I can utilize alias functionality.
You cannot do this by default in Gnome-Terminal, at least with raw commands.
However, you can write scripts that call keyboard shortcuts that can do this. Note that you need
xdotool
for this:sudo apt install xdotool
New Window: Launch a new terminal window with
nw
We can do this with just
gnome-terminal
.Add to
.bashrc
:New Tab: Launch a new tab with
nt
We can do this with
xdotool getactivewindow $(xdotool key ctrl+shift+t)
Add to
.bashrc
:Close Tab: Close the current tab or window with
ct
xdotool
strikes again:xdotool getactivewindow $(xdotool key ctrl+shift+w)
Add to
.bashrc
:Maximize Window: Maximize the entire window with
maw
We can use
wmctrl
here:wmctrl -r :ACTIVE: -b toggle,maximized_vert,maximized_horz
Add to
.bashrc
:Minimize Window: Minimize the entire window with
miw
We can use
xdotool
again:xdotool windowminimize $(xdotool getactivewindow)
Add to
.bashrc
:Move to Workspace: Move a window to another workspace with
mtw <id>
This would be just barely possible in shell scripting, and is way beyond my personal experience. I would recommend using Serg's script for this purpose, because it actually works as of now. Ah, the benefits of Compiz.
Introduction
The script presented in this answer allows user to control their terminal window via one single command and list of options. It is simple to use and compatible with any terminal emulator that has keybindings similar to
gnome-terminal
. Moving options can be used with other terminals as well, but tab opening is not guaranteed for those terminals.The script covers tab opening, window opening, moving to workspace down, workspace right, specific workspace refereed to by integer number, minimizing, maximizing, and unmaximizing a window. The only thing the script does not cover is closing tab/window simply because each shell/terminal emulator already has a command for it -
exit
or alternatively via CtrlD shortcut.!!! NOTE : you will need
xdotool
for workspace switching and tab opening. Install it viasudo apt-get install xdotool
. If you prefer to not install extra packages, keep in mind that workspace and tab switching won't work, but other options will.Usage:
All of the arguments to
windowctrl.py
are optional, so they can be used separately, or potentially together. As shown by-h
option.Script Source code:
The script source code is available on GitHub as well as here. Latest changes are likely to go into the GitHub rather than here, so I strongly suggest checking for latest version there. It is also suggested to post bug reports there as well.
Side notes
You asked "Is there a command in Gnome-Terminal, or any tabbable shell to open a new tab?" Gnome Terminal manual doesn't list such option. The shells are command-line utilities. Tabs are feature of GUI applications. There are terminal multiplexers like
screen
ortmux
which can have "tabs" or split windows , which sort of comes close to "tabbable shell" but this is not the same type of behavior you ask. Basically, answer to your question is "No". There are always alternatives, and my answer provides one of them. It treats terminal window according to its nature - X11 GUI window.How does this answer relate to aliases ? Well, first of all aliases can be a bit messy, especially when it comes to quoting and parsing multiple outputs from multiple commands. This script gives you one , centralized command, with flags/switches to do a discrete task upon a window. It also makes aliases simpler. You could do
alias nw='windowctrl.py --window'
. Much shorter, much neater.