Created
March 14, 2011 05:07
-
-
Save seungwon0/868807 to your computer and use it in GitHub Desktop.
Nautilus Extension for Symbolic Link
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# symlink.py - Nautilus Extension for Symbolic Link | |
# | |
# It adds 'Follow symbolic link' and 'Read symbolic link' menu in | |
# Nautilus. | |
# | |
# In Ubuntu, you can install this program using the following commands: | |
# % sudo apt-get install python-nautilus zenity | |
# % mkdir -p ~/.nautilus/python-extensions | |
# % cp symlink.py ~/.nautilus/python-extensions | |
# % nautilus -q | |
# | |
# Seungwon Jeong <[email protected]> | |
# | |
# Copyright (C) 2011 by Seungwon Jeong | |
import nautilus | |
import os | |
import urllib | |
class Symlink(nautilus.MenuProvider): | |
def __init__(self): | |
pass | |
def _uri_to_path(self, uri): | |
return urllib.unquote(uri[7:]) # Strip leading file:// | |
def follow_symlink(self, menu, files): | |
path = self._uri_to_path(files[0].get_uri()) | |
dirname = os.path.dirname(os.path.realpath(path)) | |
os.system('gnome-open ' + dirname) | |
def read_symlink(self, menu, files): | |
path = self._uri_to_path(files[0].get_uri()) | |
realpath = os.path.realpath(path) | |
os.system("zenity --info --title='%s' --text='%s' &" % (path, realpath)) | |
def get_file_items(self, window, files): | |
if len(files) != 1: | |
return | |
path = self._uri_to_path(files[0].get_uri()) | |
if not os.path.islink(path): | |
return; | |
item_follow = nautilus.MenuItem('Symlink::Follow', | |
'Follow symbolic link', | |
'Follow symbolic link') | |
item_follow.connect('activate', self.follow_symlink, files) | |
item_read = nautilus.MenuItem('Symlink::Read', | |
'Read symbolic link', | |
'Read symbolic link') | |
item_read.connect('activate', self.read_symlink, files) | |
return [item_follow, item_read] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For the record, if someone is searching for something like this for current caja versions. I wrote one see here: https://github.com/Nudin/caja-extensions