示例#1
0
文件: fm.py 项目: anekos/ranger
        def sxiv_workaround_hook(command):
            import re
            from ranger.ext.shell_escape import shell_quote

            if self.settings.open_all_images and \
                    len(self.thisdir.marked_items) == 0 and \
                    re.match(r'^(feh|sxiv) ', command):

                images = [f.basename for f in self.thisdir.files if f.image]
                escaped_filenames = " ".join(shell_quote(f) \
                        for f in images if "\x00" not in f)

                if images and self.thisfile.basename in images and \
                        "$@" in command:
                    new_command = None

                    if command[0:5] == 'sxiv ':
                        number = images.index(self.thisfile.basename) + 1
                        new_command = command.replace("sxiv ",
                                "sxiv -n %d " % number, 1)

                    if command[0:4] == 'feh ':
                        new_command = command.replace("feh ",
                            "feh --start-at %s " % \
                            shell_quote(self.thisfile.basename), 1)

                    if new_command:
                        command = "set -- %s; %s" % (escaped_filenames,
                                new_command)
            return old_preprocessing_hook(command)
示例#2
0
文件: fm.py 项目: yusiwen/ranger
        def sxiv_workaround_hook(command):
            import re
            from ranger.ext.shell_escape import shell_quote

            if self.settings.open_all_images and \
                    len(self.thisdir.marked_items) == 0 and \
                    re.match(r'^(feh|sxiv|imv) ', command):

                images = [f.relative_path for f in self.thisdir.files if f.image]
                escaped_filenames = " ".join(shell_quote(f) \
                        for f in images if "\x00" not in f)

                if images and self.thisfile.relative_path in images and \
                        "$@" in command:
                    new_command = None

                    if command[0:5] == 'sxiv ':
                        number = images.index(self.thisfile.relative_path) + 1
                        new_command = command.replace("sxiv ",
                                "sxiv -n %d " % number, 1)

                    if command[0:4] == 'feh ':
                        new_command = command.replace("feh ",
                            "feh --start-at %s " % \
                            shell_quote(self.thisfile.relative_path), 1)

                    if command[0:4] == 'imv ':
                        number = images.index(self.thisfile.relative_path) + 1
                        new_command = command.replace("imv ",
                                "imv -n %d " % number, 1)

                    if new_command:
                        command = "set -- %s; %s" % (escaped_filenames,
                                new_command)
            return old_preprocessing_hook(command)
    def sxiv_workaround_hook_modified(command):
        import re
        from ranger.ext.shell_escape import shell_quote

        if self.settings.open_all_images and \
                len(self.thisdir.marked_items) == 0 and \
                re.match(r'^.*sxiv ', command):

            images = [f.basename for f in self.thisdir.files if f.image]
            escaped_filenames = " ".join(shell_quote(f) \
                    for f in images if "\x00" not in f)

            if images and self.thisfile.basename in images and \
                    "$@" in command:
                new_command = None

                if 'sxiv ' in command:
                    number = images.index(self.thisfile.basename) + 1
                    new_command = command.replace("sxiv ",
                                                  "sxiv -n %d " % number, 1)

                if new_command:
                    command = "set -- %s; %s" % (escaped_filenames,
                                                 new_command)
        return old_preprocessing_hook(command)
示例#4
0
    def execute(self):
        import subprocess
        from ranger.core.loader import safeDecode
        import sys
        import os.path

        if self.rest(1):
            command = 'find . -iname ' + shell_quote('*' + self.rest(1) + '*') + \
                    '| slmenu -t -i -l $(($(tput lines)-1)) -p locate '
            self.fm.ui.suspend()
            try:
                p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
                filename = p.communicate()[0]
            finally:
                self.fm.ui.initialize()
            if p.poll() == 0: # no error returned
                if sys.version >= '3':
                    filename = safeDecode(filename)
                # remove the newline
                filename = filename.rstrip('\n')
                # make the path absolute
                filename = os.path.join(self.fm.thisdir.path, filename.lstrip('./'))
                # select the file
                self.fm.select_file(filename)
        else:
            self.fm.notify('usage: locate <name_part>', bad=True)
示例#5
0
 def substitute_macros(self, string, additional=dict(), escape=False):
     macros = self._get_macros()
     macros.update(additional)
     if escape:
         for key, value in macros.items():
             if isinstance(value, list):
                 macros[key] = " ".join(shell_quote(s) for s in value)
             elif value != MACRO_FAIL:
                 macros[key] = shell_quote(value)
     else:
         for key, value in macros.items():
             if isinstance(value, list):
                 macros[key] = " ".join(value)
     result = _MacroTemplate(string).safe_substitute(macros)
     if MACRO_FAIL in result:
         raise ValueError("Could not apply macros to `%s'" % string)
     return result
示例#6
0
    def execute(self):
        from ranger.ext.shell_escape import shell_quote

        command = 'wget --content-disposition --trust-server-names "`xsel -o`"'
        if self.rest(1):
            command += ' -O ' + shell_quote(self.rest(1))
        action = ['zsh', '-c', command]
        self.fm.execute_command(action)
示例#7
0
文件: actions.py 项目: 9M2PJU/ranger
 def substitute_macros(self, string, additional=dict(), escape=False):
     macros = self._get_macros()
     macros.update(additional)
     if escape:
         for key, value in macros.items():
             if isinstance(value, list):
                 macros[key] = " ".join(shell_quote(s) for s in value)
             elif value != MACRO_FAIL:
                 macros[key] = shell_quote(value)
     else:
         for key, value in macros.items():
             if isinstance(value, list):
                 macros[key] = " ".join(value)
     result = _MacroTemplate(string).safe_substitute(macros)
     if MACRO_FAIL in result:
         raise ValueError("Could not apply macros to `%s'" % string)
     return result
示例#8
0
    def sxiv_workaround_hook_modified(command):
        import re
        from ranger.ext.shell_escape import shell_quote

        if self.settings.open_all_images and \
                len(self.thisdir.marked_items) == 0 and \
                re.match(r'^(.*sxiv|feh|imv|.*pqiv) ', command):

            images = [f.relative_path for f in self.thisdir.files if f.image]
            media = [f.relative_path for f in self.thisdir.files if f.image
                     or f.video]
            escaped_filenames = " ".join(shell_quote(f) \
                    for f in images if "\x00" not in f)

            if (images and self.thisfile.relative_path in images) or \
                    (media and self.this)and \
                    "$@" in command:
                new_command = None

                if 'sxiv ' in command:
                    number = images.index(self.thisfile.relative_path) + 1
                    new_command = command.replace("sxiv ",
                            "sxiv -n %d " % number, 1)

                if command[0:4] == 'feh ':
                    new_command = command.replace("feh ",
                        "feh --start-at %s " % \
                        shell_quote(self.thisfile.relative_path), 1)

                if command[0:4] == 'imv ':
                    number = images.index(self.thisfile.relative_path) + 1
                    new_command = command.replace("imv ",
                            "imv -n %d " % number, 1)

                if 'pqiv ' in command:
                    number = images.index(self.thisfile.relative_path)
                    new_command = command.replace("pqiv ",
                            "pqiv --action \"goto_file_byindex(%d)\" " % \
                            number, 1)

                if new_command:
                    command = "set -- %s; %s" % (escaped_filenames,
                            new_command)
        return old_preprocessing_hook(command)
示例#9
0
文件: actions.py 项目: tonttu/ranger
	def _get_macros(self):
		macros = {}

		if self.fm.env.cf:
			macros['f'] = shell_quote(self.fm.env.cf.basename)
		else:
			macros['f'] = ''

		macros['s'] = ' '.join(shell_quote(fl.basename) \
				for fl in self.fm.env.get_selection())

		macros['c'] = ' '.join(shell_quote(fl.path)
				for fl in self.fm.env.copy)

		macros['t'] = ' '.join(shell_quote(fl.basename)
				for fl in self.fm.env.cwd.files
				if fl.realpath in self.fm.tags)

		if self.fm.env.cwd:
			macros['d'] = shell_quote(self.fm.env.cwd.path)
		else:
			macros['d'] = '.'

		# define d/f/s macros for each tab
		for i in range(1,10):
			try:
				tab_dir_path = self.fm.tabs[i]
			except:
				continue
			tab_dir = self.fm.env.get_directory(tab_dir_path)
			i = str(i)
			macros[i + 'd'] = shell_quote(tab_dir_path)
			macros[i + 'f'] = shell_quote(tab_dir.pointed_obj.path)
			macros[i + 's'] = ' '.join(shell_quote(fl.path)
				for fl in tab_dir.get_selection())

		# define D/F/S for the next tab
		found_current_tab = False
		next_tab_path = None
		first_tab = None
		for tab in self.fm.tabs:
			if not first_tab:
				first_tab = tab
			if found_current_tab:
				next_tab_path = self.fm.tabs[tab]
				break
			if self.fm.current_tab == tab:
				found_current_tab = True
		if found_current_tab and not next_tab_path:
			next_tab_path = self.fm.tabs[first_tab]
		next_tab = self.fm.env.get_directory(next_tab_path)

		macros['D'] = shell_quote(next_tab)
		macros['F'] = shell_quote(next_tab.pointed_obj.path)
		macros['S'] = ' '.join(shell_quote(fl.path)
			for fl in next_tab.get_selection())

		return macros
示例#10
0
文件: clipboard.py 项目: amerlyq/airy
def hook_init(fm):
    old_hook_init(fm)
    fm.get_clipboard = lambda r='b': _xsel('-o' + r)
    fm.get_clipboard_q = lambda r='b': shell_quote(_xsel('-o' + r))

    fm.set_clipboard = lambda t, r='b': _xsel('-i' + r, input=t)
示例#11
0
 def execute(self):
     command = 'wget --content-disposition --trust-server-names "`xsel -o`"'
     if self.rest(1):
         command += ' -O ' + shell_quote(self.rest(1))
     action = ['zsh', '-c', command]
     self.fm.execute_command(action)
示例#12
0
 def execute(self):
     if self.rest(1):
         command = 'find . -iname ' + shell_quote('*' + self.rest(1) + '*') + '| grep -i --color=always ' + shell_quote(self.rest(1))
         action = ['zsh', '-c', command]
         self.fm.execute_command(action, flags='p')
示例#13
0
文件: tc_ext.py 项目: Dieterbe/ranger
	def test_shell_escape(self):
		from ranger.ext.shell_escape import shell_escape, shell_quote
		self.assertEqual(r"'luigi'\''s pizza'", shell_quote("luigi's pizza"))
		self.assertEqual(r"luigi\'s\ pizza", shell_escape("luigi's pizza"))
		self.assertEqual(r"\$lol/foo\\xyz\|\>\<\]\[",
				shell_escape(r"$lol/foo\xyz|><]["))
示例#14
0
 def execute(self):
     if self.rest(1):
         self.command += ' -o ' + shell_quote(self.rest(1))
     action = ['/bin/sh', '-c', self.command]
     self.fm.execute_command(action)
示例#15
0
文件: commands.py 项目: amerlyq/airy
 def _quot(self, patt):
     return patt if ag.qarg.match(patt) else shell_quote(patt)
示例#16
0
    def _get_macros(self):
        macros = {}

        if self.fm.env.cf:
            macros['f'] = shell_quote(self.fm.env.cf.basename)
        else:
            macros['f'] = ''

        macros['s'] = ' '.join(shell_quote(fl.basename) \
          for fl in self.fm.env.get_selection())

        macros['c'] = ' '.join(shell_quote(fl.path) for fl in self.fm.env.copy)

        macros['t'] = ' '.join(
            shell_quote(fl.basename) for fl in self.fm.env.cwd.files
            if fl.realpath in self.fm.tags)

        if self.fm.env.cwd:
            macros['d'] = shell_quote(self.fm.env.cwd.path)
        else:
            macros['d'] = '.'

        # define d/f/s macros for each tab
        for i in range(1, 10):
            try:
                tab_dir_path = self.fm.tabs[i]
            except:
                continue
            tab_dir = self.fm.env.get_directory(tab_dir_path)
            i = str(i)
            macros[i + 'd'] = shell_quote(tab_dir_path)
            macros[i + 'f'] = shell_quote(tab_dir.pointed_obj.path)
            macros[i + 's'] = ' '.join(
                shell_quote(fl.path) for fl in tab_dir.get_selection())

        # define D/F/S for the next tab
        found_current_tab = False
        next_tab_path = None
        first_tab = None
        for tab in self.fm.tabs:
            if not first_tab:
                first_tab = tab
            if found_current_tab:
                next_tab_path = self.fm.tabs[tab]
                break
            if self.fm.current_tab == tab:
                found_current_tab = True
        if found_current_tab and not next_tab_path:
            next_tab_path = self.fm.tabs[first_tab]
        next_tab = self.fm.env.get_directory(next_tab_path)

        macros['D'] = shell_quote(next_tab)
        macros['F'] = shell_quote(next_tab.pointed_obj.path)
        macros['S'] = ' '.join(
            shell_quote(fl.path) for fl in next_tab.get_selection())

        return macros
示例#17
0
 def test_shell_escape(self):
     from ranger.ext.shell_escape import shell_escape, shell_quote
     self.assertEqual(r"'luigi'\''s pizza'", shell_quote("luigi's pizza"))
     self.assertEqual(r"luigi\'s\ pizza", shell_escape("luigi's pizza"))
     self.assertEqual(r"\$lol/foo\\xyz\|\>\<\]\[",
                      shell_escape(r"$lol/foo\xyz|><]["))