VS Code open directory instead of system file manager in Ubuntu 19.10
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.
Solution 1:
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;
toMimeType=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 :-)