17

In windows, we have an option: adding "open with code" action to context menu, this allows us to open any file or folder with vscode, is there any way to add this feature in Ubuntu?

1

6 Answers 6

32
wget -qO- https://raw.githubusercontent.com/cra0zy/code-nautilus/master/install.sh | bash

Just run this in your terminal and it will add open with VSCode in context menu for Ubuntu 18.04 LTS. Source: Crazy0's GitHub Repository
Edit 1: Works for Ubuntu 20.04 LTS as well.
Edit 2: Works for Ubuntu 20.10 LTS as well.

8
  • 4
    Works on Ubuntu 20.04 as well May 24, 2020 at 7:53
  • 1
    Working on Ubuntu 20.10 too
    – Dijkie85
    Oct 24, 2020 at 16:36
  • 1
    On my distro (Pop!_OS 20.10) I had to install the python3-nautilus package in order to get it to work. You can do that with sudo apt install python3-nautilus. May 2, 2021 at 23:41
  • 1
    Make sure to close all open windows first. Works great! Aug 17, 2021 at 17:56
  • 1
    Pop!_OS now also seems to add python3-nautilus so the manual step is no longer required
    – Imre_G
    Sep 13, 2021 at 8:10
7

What you need to do is install Nautilus Actions

sudo apt install nautilus-actions

and add new action :

Path: code Parameters: %B

command

in menu

NOTE ❗ ❗ Modern version of Nautilus Actions (nautilus-actions package in trusty (14.04 LTS), xenial (16.04 LTS), artful (17.10)) are named as FileManager Actions (filemanager-actions package, it is not yet packaged in Debian and Ubuntu - see at repology.org).

sudo add-apt-repository ppa:daniel-marynicz/filemanager-actions

sudo apt-get install filemanager-actions-nautilus-extension 

NOTE 2 As of Ubuntu 19.04, the package is filemanager-actions.

sudo apt-get install filemanager-actions

orginal post askubuntu.com/a/1031746/843203

4
  • "Package nautilus-actions is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source" Jun 27, 2018 at 17:23
  • 1
    @MichaelCole Sorry ! Modern version of Nautilus Actions (nautilus-actions package in trusty (14.04 LTS), xenial (16.04 LTS), artful (17.10)) are named as FileManager Actions (filemanager-actions package, it is not yet packaged in Debian and Ubuntu - see at repology.org). ** sudo add-apt-repository ppa:daniel-marynicz/filemanager-actions ** sudo apt-get install filemanager-actions-nautilus-extension orginal post askubuntu.com/a/1031746/843203
    – Leone
    Jun 27, 2018 at 17:36
  • where can I find the vscode icon to set it to this context-menu? Jul 17, 2020 at 15:24
  • This might be a long shot but... when opening vscode with right click actions from filemanager action, it does not import all of the bashrc $PATH. For example, if I right click for 'Open with Code' and try to debug a javacript file, vscode will say it can not find Node.js. However, when I open vscode normally, full $PATH is exported and can then debug javascript normally. Any idea why the right click aciton is missing $PATH export?
    – moredrowsy
    Jul 9, 2021 at 23:31
3

I was able to find this vscode extension for nautilus written by Crazy0 that lets you do this.

The steps can be found in that github gist, which are:

  1. Go to the gist.
  2. And do the following (also found in the head section of that gist):

    • Place me in ~/.local/share/nautilus-python/extensions/, restrart Nautilus, and enjoy :)
    • mkdir -p ~/.local/share/nautilus-python/extensions && cp -f VSCodeExtension.py ~/.local/share/nautilus-python/extensions/VSCodeExtension.py && nautilus -q

Just tested on Ubuntu Bionic and it works great.

3

If you're on 20.10 and you're running this script:

wget -qO- https://raw.githubusercontent.com/cra0zy/code-nautilus/master/install.sh | bash`

You'll need to install python3-nautilus because python-nautilus isn't in non-LTS versions of Ubuntu.

Simply install the python3 version of python-nautilus

sudo apt install python3-nautilus

Then restart nautilus (this will close all nautilus folders)

nautilus -q && nautilus &

And it should work should work.

1
  • The last command did it for me. Also, python3-nautilus wasn't found, so I installed python-nautilus instead. Apr 11 at 13:07
1

1.Create a file ~/.local/share/nautilus/scripts/open-in-code.sh with this content:

#!/bin/bash
if [ -n "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" ]; then
    set $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
    if [ $# -eq 1 ]; then
        destination="$1"
    else
        zenity --error --title="Error - Open in Visual Studio Code" \
        --text="You can only select one file/directory."
        exit 1
    fi
else
    destination="`echo "$NAUTILUS_SCRIPT_CURRENT_URI" | sed 's/^file:\/\///'`"
fi

# It's only possible to go to local directories
if [ -n "`echo "$destination" | grep '^[a-zA-Z0-9]\+:'`" ]; then
    zenity --error --title="Error - Open in Visual Studio Code" \
    --text="Only local directories can be used."
    exit 1
fi

exec code "$destination"

2.Add execution permission to the file:

 $ chmod +x ~/.local/share/nautilus/scripts/open-in-code.sh

3.Restart Nautilius.

4.Right-click on a file or directory, you will see this:

open in nautilus

Source: https://help.ubuntu.com/community/NautilusScriptsHowto

0

Just Run this command on your terminal:

wget -qO- https://raw.githubusercontent.com/cra0zy/code-nautilus/master/install.sh | bash

Source: itectec.com

2
  • 3
    I would not suggest that anyone pipe a script from the internet directly into your shell. It's dangerous.
    – Nmath
    Nov 8, 2020 at 20:11
  • The same answer does exist
    – Sahin
    Oct 31, 2021 at 18:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.