After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 706927 - terminal-nautilus doesn't set the correct directory for custom commands
terminal-nautilus doesn't set the correct directory for custom commands
Status: RESOLVED FIXED
Product: gnome-terminal
Classification: Core
Component: general
3.9.x
Other Linux
: Normal normal
: ---
Assigned To: GNOME Terminal Maintainers
GNOME Terminal Maintainers
: 739225 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2013-08-27 20:35 UTC by Sebastian Keller
Modified: 2019-09-30 20:05 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
app: Keep track of available shells according to /etc/shells (4.27 KB, patch)
2015-02-02 18:54 UTC, Sebastian Keller
none Details | Review
screen: Don't ignore the cwd if the custom command is a shell (1.79 KB, patch)
2015-02-02 18:54 UTC, Sebastian Keller
none Details | Review

Description Sebastian Keller 2013-08-27 20:35:07 UTC
In your default terminal profile set "/bin/bash" as custom command and then start nautilus go to some folder and use terminal-nautilus to open a terminal in that folder. Bash will be running in the home directory rather than that folder.
Comment 1 Christian Persch 2013-09-14 12:04:44 UTC
Not reproducible here...
Comment 2 Sebastian Keller 2013-09-14 15:55:55 UTC
This is on fedora 20:
gnome-terminal-3.9.90-1.fc20.x86_64
vte3-0.34.7-2.fc20.x86_64
nautilus-3.9.91-1.fc20.x86_64
bash-4.2.45-4.fc20.x86_64

----------------------------------------

$ dconf dump /org/gnome/terminal/
[legacy]
new-terminal-mode='tab'
schema-version=uint32 3

[legacy/profiles:]
list=['32b1c728-8bac-4875-8f89-fd7b79bb884e']
default='32b1c728-8bac-4875-8f89-fd7b79bb884e'

[legacy/profiles:/:32b1c728-8bac-4875-8f89-fd7b79bb884e]
foreground-color='rgb(243,243,243)'
visible-name='bash'
login-shell=false
palette=['rgb(0,0,0)', 'rgb(213,1,1)', 'rgb(78,154,6)', 'rgb(196,160,0)', 'rgb(61,116,186)', 'rgb(117,80,123)', 'rgb(6,152,154)', 'rgb(211,215,207)', 'rgb(85,87,83)', 'rgb(239,41,41)', 'rgb(138,226,52)', 'rgb(252,233,79)', 'rgb(114,159,207)', 'rgb(173,127,168)', 'rgb(52,226,226)', 'rgb(238,238,236)']
custom-command='bash'
default-size-columns=140
default-size-rows=34
cursor-shape='ibeam'
use-custom-command=true
use-custom-default-size=true
use-system-font=false
use-theme-colors=false
font='Inconsolata Bold 9'
allow-bold=true
background-color='rgb(46,52,54)'

----------------------------------------

$ cat ~/.bash_profile 
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
	. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH

----------------------------------------

$ cat cat ~/.bashrc 
# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
	. /etc/bashrc
fi

# User specific aliases and functions

export PROMPT_DIRTRIM="2"
export PS1="\u@\h \[\e[0;92m\]\w\[\e[0m\]> "

----------------------------------------

(gnome-terminal opened from nautilus in ~/devel)
$ env
LC_PAPER=de_DE.utf8
XDG_VTNR=1
XDG_SESSION_ID=2
HOSTNAME=t400
LC_MONETARY=de_DE.utf8
GPG_AGENT_INFO=/run/user/1000/keyring-qRiZJb/gpg:0:1
VTE_VERSION=3407
TERM=xterm-256color
SHELL=/bin/bash
XDG_MENU_PREFIX=gnome-
HISTSIZE=1000
GJS_DEBUG_OUTPUT=stderr
WINDOWID=29369118
LC_NUMERIC=de_DE.utf8
GNOME_KEYRING_CONTROL=/run/user/1000/keyring-qRiZJb
GJS_DEBUG_TOPICS=JS ERROR;JS LOG
PROMPT_DIRTRIM=2
QT_GRAPHICSSYSTEM_CHECKED=1
USER=sebastian
LS_COLORS=rs=0:di=38;5;27:ln=38;5;51:mh=44;38;5;15:pi=40;38;5;11:so=38;5;13:do=38;5;5:bd=48;5;232;38;5;11:cd=48;5;232;38;5;3:or=48;5;232;38;5;9:mi=05;48;5;232;38;5;15:su=48;5;196;38;5;15:sg=48;5;11;38;5;16:ca=48;5;196;38;5;226:tw=48;5;10;38;5;16:ow=48;5;10;38;5;21:st=48;5;21;38;5;15:ex=38;5;34:*.tar=38;5;9:*.tgz=38;5;9:*.arc=38;5;9:*.arj=38;5;9:*.taz=38;5;9:*.lha=38;5;9:*.lzh=38;5;9:*.lzma=38;5;9:*.tlz=38;5;9:*.txz=38;5;9:*.tzo=38;5;9:*.t7z=38;5;9:*.zip=38;5;9:*.z=38;5;9:*.Z=38;5;9:*.dz=38;5;9:*.gz=38;5;9:*.lrz=38;5;9:*.lz=38;5;9:*.lzo=38;5;9:*.xz=38;5;9:*.bz2=38;5;9:*.bz=38;5;9:*.tbz=38;5;9:*.tbz2=38;5;9:*.tz=38;5;9:*.deb=38;5;9:*.rpm=38;5;9:*.jar=38;5;9:*.war=38;5;9:*.ear=38;5;9:*.sar=38;5;9:*.rar=38;5;9:*.alz=38;5;9:*.ace=38;5;9:*.zoo=38;5;9:*.cpio=38;5;9:*.7z=38;5;9:*.rz=38;5;9:*.cab=38;5;9:*.jpg=38;5;13:*.jpeg=38;5;13:*.gif=38;5;13:*.bmp=38;5;13:*.pbm=38;5;13:*.pgm=38;5;13:*.ppm=38;5;13:*.tga=38;5;13:*.xbm=38;5;13:*.xpm=38;5;13:*.tif=38;5;13:*.tiff=38;5;13:*.png=38;5;13:*.svg=38;5;13:*.svgz=38;5;13:*.mng=38;5;13:*.pcx=38;5;13:*.mov=38;5;13:*.mpg=38;5;13:*.mpeg=38;5;13:*.m2v=38;5;13:*.mkv=38;5;13:*.ogm=38;5;13:*.mp4=38;5;13:*.m4v=38;5;13:*.mp4v=38;5;13:*.vob=38;5;13:*.qt=38;5;13:*.nuv=38;5;13:*.wmv=38;5;13:*.asf=38;5;13:*.rm=38;5;13:*.rmvb=38;5;13:*.flc=38;5;13:*.avi=38;5;13:*.fli=38;5;13:*.flv=38;5;13:*.gl=38;5;13:*.dl=38;5;13:*.xcf=38;5;13:*.xwd=38;5;13:*.yuv=38;5;13:*.cgm=38;5;13:*.emf=38;5;13:*.axv=38;5;13:*.anx=38;5;13:*.ogv=38;5;13:*.ogx=38;5;13:*.aac=38;5;45:*.au=38;5;45:*.flac=38;5;45:*.mid=38;5;45:*.midi=38;5;45:*.mka=38;5;45:*.mp3=38;5;45:*.mpc=38;5;45:*.ogg=38;5;45:*.ra=38;5;45:*.wav=38;5;45:*.axa=38;5;45:*.oga=38;5;45:*.spx=38;5;45:*.xspf=38;5;45:
SSH_AUTH_SOCK=/run/user/1000/keyring-qRiZJb/ssh
SESSION_MANAGER=local/unix:@/tmp/.ICE-unix/1398,unix/unix:/tmp/.ICE-unix/1398
USERNAME=sebastian
PATH=/usr/lib64/ccache:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/home/sebastian/.local/bin:/home/sebastian/bin
MAIL=/var/spool/mail/sebastian
DESKTOP_SESSION=gnome
QT_IM_MODULE=ibus
PWD=/home/sebastian
XMODIFIERS=@im=ibus
GNOME_KEYRING_PID=1365
LANG=de_DE.utf8
GDM_LANG=de_DE.utf8
LC_MEASUREMENT=de_DE.utf8
PS1=\u@\h \[\e[0;92m\]\w\[\e[0m\]> 
GDMSESSION=gnome
HISTCONTROL=ignoredups
XDG_SEAT=seat0
HOME=/home/sebastian
SHLVL=2
GNOME_DESKTOP_SESSION_ID=this-is-deprecated
LOGNAME=sebastian
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-EQqLPlTsKr,guid=f329d7588e67a58e2b1689e252347d2f
LESSOPEN=||/usr/bin/lesspipe.sh %s
WINDOWPATH=1
XDG_RUNTIME_DIR=/run/user/1000
DISPLAY=:0
LC_TIME=de_DE.utf8
CCACHE_HASHDIR=
COLORTERM=gnome-terminal
XAUTHORITY=/run/gdm/auth-for-sebastian-nckHfk/database
_=/usr/bin/env
Comment 3 Christian Persch 2013-09-14 16:54:35 UTC
Looking at the code, the change from bug 692148 may be causing this. Now how to fix this without regressing that bug...
Comment 4 Sebastian Keller 2014-08-07 05:05:16 UTC
I've looked into this and found the cause of this behavior:

https://git.gnome.org/browse/gnome-terminal/commit/?id=fc68d2735f8804d3c5d0d40635a27989727c3f9b


Reverting this commit gives the behavior I was expecting, the terminal now has the right PWD when opened from terminal-nautilus.

Since this commit obviously was an intentional change, are there any specific problems this was helping with? Because it currently is breaking the use case of having multiple profiles with different shells specified as custom commands.

If reverting this change is not an option, another solution could be to check if the custom command is not listed in /etc/shells and only then ignore the working directory.
Comment 5 David Adam 2014-11-20 04:36:42 UTC
FWIW, we've had a few users run into this as they use the "custom command" option to set a new shell.

https://github.com/fish-shell/fish-shell/issues/1814
https://github.com/fish-shell/fish-shell/issues/1816
Comment 6 Sebastian Keller 2015-02-02 18:54:49 UTC
Created attachment 295969 [details] [review]
app: Keep track of available shells according to /etc/shells

This will be useful to determine whether a custom command is a shell or
not.
Comment 7 Sebastian Keller 2015-02-02 18:54:57 UTC
Created attachment 295970 [details] [review]
screen: Don't ignore the cwd if the custom command is a shell
Comment 8 Debarshi Ray 2015-08-04 07:31:26 UTC
*** Bug 748293 has been marked as a duplicate of this bug. ***
Comment 9 Christian Persch 2016-02-21 14:20:10 UTC
*** Bug 739225 has been marked as a duplicate of this bug. ***
Comment 10 MOZGIII 2016-05-09 14:36:31 UTC
It is still an issue on Ubuntu 15.10 and Ubuntu 16.04. I've looked at the code a bit and it seemed to me the bug was not on in terminal-nautilus.c, but rather somewhere else, and it source of it is inability for a gnome-terminal to set a working dir properly with a custom shell command.
I've tested it with a fresh Ubuntu 16.04 installation:

mozgiii@mozgiii-pc:~/naulog2$ gnome-terminal --working-directory=/
mozgiii@mozgiii-pc:~/naulog2$ gnome-terminal --working-directory=/home

Both open terminal in my $HOME dir instead of the ones requested.

By the way, there is no need to determine if a custom command is a shell or not: there is a checkbox for that. Furthermore, I somethimes want to run a custom command like `bash -l -c 'exec zsh'` to load up bash's configs into zsh, and that would not be in /etc/shells list. So I don't see that approach working for me (at least).
Comment 11 Sebastian Keller 2016-05-09 16:46:48 UTC
The code determining whether to set the working directory is in terminal_screen_do_exec of terminal-screen.c. However the component where the bug becomes visible is terminal-nautilus.

And the checkbox is about the command being a *login* shell. It can still be a shell without it being a login shell. Shells started in GUI terminals usually are non-login shells by default. It probably still could be used as an indicator that the command definitely is a shell and should set the working directory. The case for non-login shells would still need to be covered though.

A solution as suggested in Bug 748293 seems like it would cover this problem as well. I'll try to write a patch that implements it in a way that preserves the current behavior in the default case, since [1] indicates it is intentional behavior.

[1] https://git.gnome.org/browse/gnome-terminal/commit/?id=fc68d2735f8804d3c5d0d40635a27989727c3f9b
Comment 12 MOZGIII 2016-05-09 17:04:12 UTC
Yes, you are right about the checkbox.
Maybe there should be another checkbox there then? Just to determine whether to set working directory or not.

By the way, what is the purpose of login/non-login shell checkbox if custom command is used? It seems like the only possible thing there would be some kind of internal magic that is not documented anywhere, or it would just do nothing.
Comment 13 Sebastian Keller 2016-05-09 17:33:22 UTC
It launches the command with a "-" prefixed to argv[0]. What the launched program does with this depends on the program. For shells it causes them to run as login shells and source your profile files.
Comment 14 Sebastian Keller 2016-05-09 20:39:56 UTC
I've attached the patches to Bug 748293.
Comment 15 MOZGIII 2016-05-09 21:25:52 UTC
Very nice! All right, what to do next to get this change in my OS? :)
Comment 16 Christian Persch 2019-09-30 20:05:38 UTC
This should now work on master.