Skip to content

Instantly share code, notes, and snippets.

@gocarlos
Forked from MatteoRagni/README.md
Created August 12, 2017 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gocarlos/18245fd5e418e64ac2951e6ed48e552b to your computer and use it in GitHub Desktop.
Save gocarlos/18245fd5e418e64ac2951e6ed48e552b to your computer and use it in GitHub Desktop.
Creates a context-menu in nautilus that allows to open a directory (or a list of selected directory) as project folder. Only for current user (no root required).

Atom context menu

Synopsis

This simple script creates a new element in context menu that opens current directory (background click) or a list of directory (selected elements) as project folder. It does not open single files (that should be done as MIME type, search on google!)

Installation

Prerequisites

Script requires python-nautilus to be installed:

Debian/Ubuntu

sudo apt install python-nautilus

Arch

sudo pacman -S python-nautilus

Extension directory

Current user must have an extension directory, that probably must be created manually:

mkdir -p ~/.local/share/nautilus-python/extensions
cd ~/.local/share/nautilus-python/extensions

I think that it can be installed globally in /usr/share/python-nautilus/extensions, but I never tested it.

Download script

Now that we are in the python-nautilus/extensions directory (either of the cirrent user or the global one), we can download the script:

wget "https://bit.ly/AtomContextMenu" -O atom-directory.py

It will work when we reload nautilus

killall nautilus

It should be available in Nautilus context on right-click.

import os
from gi.repository import Nautilus, GObject
class AtomOpenDirectory(GObject.GObject, Nautilus.MenuProvider):
def __init__(self):
pass
def menu_activate_cb(self, menu, file):
try:
path = file.get_location().get_path()
os.system("atom %s & pid=&!" % path)
except AttributeError: # it is a list of elements
dir_list = [f.get_location().get_path() for f in file if f.is_directory()]
os.system("atom %s & pid=&!" % ' '.join(dir_list))
def define_menu_helper(self, name, window, file):
item = Nautilus.MenuItem(name="AtomOpenDirectory::" + name,
label="Open directories in Atom",
tip='', icon='')
item.connect('activate', self.menu_activate_cb, file)
return item,
def get_background_items(self, window, file):
return self.define_menu_helper("Background", window, file)
def get_file_items(self, window, file):
return self.define_menu_helper("File", window, file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment