Created
January 26, 2012 21:14
-
-
Save gwash/1685143 to your computer and use it in GitHub Desktop.
relinker command for ranger
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
class relink(Command): | |
""" | |
:relink <newpath> | |
Changes the linked path of the currently highlighted symlink to <newpath> | |
""" | |
def execute(self): | |
from ranger.fsobject import File | |
new_path = self.rest(1) | |
cf = self.fm.env.cf | |
if not new_path: | |
return self.fm.notify('Syntax: relink <newpath>', bad=True) | |
if not cf.is_link: | |
return self.fm.notify('%s is not a symlink!' % cf.basename, bad=True) | |
if new_path == os.readlink(cf.path): | |
return | |
try: | |
os.remove(cf.path) | |
os.symlink(new_path, cf.path) | |
except OSError as err: | |
self.fm.notify(err) | |
self.fm.reset() | |
self.fm.env.cwd.pointed_obj = cf | |
self.fm.env.cf = cf | |
def tab(self): | |
if not self.rest(1): | |
return self.line+os.readlink(self.fm.env.cf.path) | |
else: | |
return self._tab_directory_content() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment