I know that you can usually use chdir in your screenrc file to change directory before running a screen command. However, this doesn't work for me if I have defshell -bash
set. Here's a sample file that doesn't work:
defshell -bash
defscrollback 100000
hardstatus on
hardstatus alwayslastline
hardstatus string "%w%=%m/%d %c"
chdir /Users/myuser/work
screen -t "work"
$ screen -c testrc
$ pwd
/Users/myuser
Commenting out the first line does the trick, but I'd like to run bash shells in my screens. This is on OSX if that's relevant. My screen command is not aliased.
The problem is that your defshell
specifies a login shell, which makes it go to the home directory. According to screen
's manual
shell command
Set the command to be used to create a new shell. This overrides the value of the environment variable $SHELL. This is useful if you'd like to run a tty-enhancer which is expecting to execute the program specified in $SHELL. If the command begins with a '-' character, the shell will be started as a login-shell.
If you change that to
defshell bash
it should not do that.