Skip to content

Instantly share code, notes, and snippets.

@gwash
Created January 26, 2012 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gwash/1685143 to your computer and use it in GitHub Desktop.
Save gwash/1685143 to your computer and use it in GitHub Desktop.
relinker command for ranger
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