6

After upgraded to Ubuntu 19.10 I notice a stranger behaviour in code: if I double click a directory or a unit or right click a directory and try open the directory was open by code unless nemo or nautilus.

I install code by microsoft repo after add the repo to apt

I do not know if is a microsoft or gnome or ubuntu problem.

but this behaviour is not friendly.

4 Answers 4

9

I found a workaround to temporary solve the problem.

find
~/.local/share/applications/mimeapps.list
and be sure the inode/directory= was set to your file manager.

exemple:
inode/directory=nautilus-folder-handler.desktop;

same for file ~/.config/mimeapps.list

then find the code desktop file.
mine is in /usr/share/applications/code.desktop and change the row

MimeType=text/plain;inode/directory;
to
MimeType=text/plain;

then do $ sudo update-desktop-database

to me this work but if vscode is updated all reset to the initial behaviour.

The /usr/share/applications/code.desktop is revert to initial value.

So to make all more quickly I write a script:

 #!/bin/bash
 sudo sed -i "s/inode\/directory;//" /usr/share/applications/code.desktop
 sudo update-desktop-database

waiting for stable solution this may be acceptable

Update

I have put the script above in an after-upgrade-code.sh and change in this manner (I put it inside PATH env):

#!/bin/bash
UPDATED="$(tac /var/log/apt/history.log|sed '/End-Date/,$!d;/Start-Date/q'|tac|grep 'Upgrade.*code')"
if [[ ! -z $UPDATED ]]
then
  sudo sed -i "s/inode\/directory;//" /usr/share/applications/code.desktop
  sudo update-desktop-database
fi
exit 0

the I put it /etc/apt/apt.conf.d/100update:

Post-Invoke {"after-upgrade-code.sh";};

If last apt upgrade make change on code it will upgrade the code.desktop

Update

I have done some test and I not be sure if the postinvoke script work fine: the problem is that I not sure history.log was updated at Post-Invoke time, so the script can do noting if history is not updated.

This is version 2 and this will be trigger:

#!/bin/bash
CHECK="$(date '+%Y-%m-%d %H:%M')" 
CHECK="${CHECK:0:-1}.*upgrade code"
UPDATED=$(sudo grep "$CHECK" /var/log/dpkg.log)
#UPDATED="$(tac /var/log/apt/history.log|sed '/End-Date/,$!d;/Start-Date/q'|tac|grep 'Upgrade.*code')"
if [[ ! -z $UPDATED ]]
then
  sudo sed -i "s/inode\/directory;//" /usr/share/applications/code.desktop
  sudo update-desktop-database
    echo "after-update-code is been executed"
else
    echo "after-update-code is been not executed"
fi
exit 0

This: CHECK="$(date '+%Y-%m-%d %H:%M')" get the date time taking only minute.
This: ${CHECK:0:-1} cut minute unit and leave the ten so
the grep: grep "$CHECK" /var/log/dpkg.log
check if an 'Code' upgrade was done in less then ten minute and if verified try to update the code.desktop to avoid 'Code' will be use to open folder.

I have changed the hook trig:
sudo cat /etc/apt/apt.conf.d/100update
give:
DPkg::Post-Invoke {"/home/leonardo/sviluppo/script/after-upgrade-code.sh";};

Update

I have do a mistake writing the UPDATED wrong (UPTDATED), now is correct.

Uptate

Last version work: I have verified :-)

4
  • In my case (KDE Plasma + nautilus), just modifying /usr/share/applications/code.desktop (then update) did the trick.
    – Javier
    Feb 17, 2020 at 14:16
  • the script is to avoid to do it manually all the time :-) Feb 18, 2020 at 18:10
  • Indeed. I just wanted to point out that was enough. Actually I couldn't find mimeapps.list in /.local and there were no code.desktop in /usr mimeapps. That caused me half an hour of useless internet wandering.
    – Javier
    Feb 19, 2020 at 3:29
  • 2
    This behaviour by code is inacceptable. I don't want to open directories by default in vscode.
    – RichieHH
    Dec 28, 2020 at 14:42
4

Copy file:

cp /usr/share/applications/code.desktop ~/.local/share/applications/code.desktop

And edit ~/.local/share/applications/code.desktop:

MimeType=text/plain;inode/directory;application/x-code-workspace;

to

MimeType=text/plain;application/x-code-workspace;

2
  • This was enough for me too, a lot cleaner than the default answer
    – garzj
    Nov 25, 2022 at 8:30
  • Thank you, I spent just a half of a minute going through your solution and it works just nice, even though I'm not an ubuntu user - I'm a Manjaro Gnome user, so since it's the same Gnome - it works as it considered to do
    – Dominux
    Jan 22 at 8:20
2

In gnome, you can use this command for set natural folder browser as default:

xdg-mime default org.gnome.Nautilus.desktop inode/directory
0

Check also the mimetype inode/mount-point:

xdg-mime query default inode/mount-point

if it's empty the vscode could opens the mountpoint; set your filemanager to the default mimetype for mount point:

xdg-mime default org.kde.dolphin.desktop inode/mount-point

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .