I'm running Awesome WM on the latest Arch Linux with Gnome Terminal and the default bash. I've managed to get this working, but I wonder if any form of improvement is possible with this implementation. The question does NOT relate to opening new tabs, only to spawning new terminal windows with Awesome WM.

I have rewritten the "cd" command to save the current working directory in the ".cd_extend" file:


alias cd='source ~/.cd_extend'



command cd $1
echo $(pwd) > ~/.terminal_directory

When I spawn a new terminal, the ".terminal_directory" is read and appended as an argument to gnome terminal's "--working-directory" flag.



DIR=$(cat ~/.terminal_directory)
gnome-terminal --working-directory=$DIR

awesomewm rc.lua

terminal   = "~/.dotfiles/open_terminal.sh"
awful.key({ modkey, }, "Return", function () awful.util.spawn(terminal) end)

I wonder if I have missed any internal bash functionality which could have simplified this and if there is room for improvement.

  • Note: echo $(pwd) is just a complicated way of spelling pwd. Another quick fix is that you should at least use command cd "$1" instead of command cd $1 in case the argument has spaces in it. – Celada Dec 1 '16 at 12:45
  • I thought that outputting to a file was only possible with echo. Thanks for the tips. – user1213904 Dec 1 '16 at 12:57
  • 1
    Possible duplicate of gnome-terminal: keep track of directory in new tab – Ashok Apr 23 at 11:19
  • @Ashok The question that you're referring to has nothing to do with spawning new terminal windows in Awesome WM. The question is related to gnome-terminal tabs. I have edited the question to make it a bit more clear. – user1213904 Apr 23 at 13:28

In the menu of Gnome-terminal, use:

File --> Open Terminal 

That will open a new window using the pwd as the directory.

Also, you may set the open tabs:

Edit --> Preferences --> General --> Open new terminals in: --> select tab.

So new terminals will open in the same window with the same pwd.
You will still be able to open new windows if needed:

Alt-F2 --> gnome-terminal

  • Thanks for the answer, however this breaks the flow with awesome, because awesome should be spawning the terminals, otherwise I'm required to bind my keys for a new terminal through gnome-terminal, which is not desired. Also using Alt-F2 is a bit hard as i'm missing the Fn buttons. – user1213904 Dec 2 '16 at 12:38
  • 1
    This option seems to be missing in gnome-terminal 3.22 :/ – hugomg Apr 13 '17 at 4:55
  • On the Gnome-terminal 3.22.2 I have it is still valid, shrug :/. – sorontar Apr 14 '17 at 0:02

After a few days of testing and asking around, this seems to be the easiest implementation. It could be done with a global state which Awesome WM reads, however to keep predictability and ease of implementation I'm keeping this.


alias cd='source ~/.cd_extend'


command cd "$1"
pwd > ~/.terminal_directory

Afterwards I can open the terminal, which reads from the .terminal_directory file and opens a new gnome shell with the given working directory.



DIR=$(cat ~/.terminal_directory)
gnome-terminal --working-directory="$DIR"

awesomewm rc.lua

terminal   = "~/.dotfiles/open_terminal.sh
awful.key({ modkey, }, "Return", function () awful.util.spawn(terminal) end)
  • (1) Since you’re running the ~/.cd_extend file with the source command, you don’t need a “shebang” (#!/bin/bash) in it. (It is harmless; it will be ignored.)  (2) The gnome-terminal command should say --working-directory="$DIR" (with quotes). – G-Man Apr 8 at 18:12
  • thanks @G-Man, I have updated my answer accordingly. – user1213904 Apr 23 at 13:43

On Arch Linux + GNOME (at least), you can add the following line into ~/.bashrc to have new Terminal windows opened in the current directory:

source /etc/profile.d/vte.sh

There is already a related question about new tabs. It turns out that the answer is the same for new windows.

  • 1
    It’s not clear how this answers the question.  What does this do?  Please do not respond in comments; edit your answer to make it clearer and more complete (i.e., to explain how this answers the question). – G-Man Apr 8 at 18:02
  • It precisely answers the asked question. I have nothing to add, except that I just thank you for your downvote. – Thomas Hugel Apr 9 at 6:11
  • It does not answer the question as it is related to tabs, and not new windows spawned by Awesome WM as noted in my question. Therefore you're answer should elaborate more as to why sourcing vte.sh solves retaining directory state between Awesome WM spawns. – user1213904 Apr 23 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.