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:
~/.bashrc
alias cd='source ~/.cd_extend'
~/.cd_extend
#!/bin/bash
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.
~/.dotfiles/open_terminal.sh
#!/bin/bash
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.
echo $(pwd)
is just a complicated way of spellingpwd
. Another quick fix is that you should at least usecommand cd "$1"
instead ofcommand cd $1
in case the argument has spaces in it. – Celada Dec 01 '16 at 12:45