コード例 #1
0
ファイル: ui.py プロジェクト: sit0/ranger
    def destroy(self):
        """Destroy all widgets and turn off curses"""
        if 'vcsthread' in self.__dict__:
            if not self.vcsthread.stop():
                self.fm.notify('Failed to stop `UI.vcsthread`', bad=True)
            del self.__dict__['vcsthread']
        DisplayableContainer.destroy(self)

        # Restore tmux setting `automatic-rename`
        if self.settings.update_tmux_title and 'TMUX' in os.environ:
            if self._tmux_automatic_rename:
                try:
                    check_output([
                        'tmux', 'set-window-option', 'automatic-rename',
                        self._tmux_automatic_rename
                    ])
                except CalledProcessError:
                    pass
            else:
                try:
                    check_output([
                        'tmux', 'set-window-option', '-u', 'automatic-rename'
                    ])
                except CalledProcessError:
                    pass

        self.suspend()
コード例 #2
0
ファイル: plugin_fasd_add.py プロジェクト: pengwyn/rcfiles
 def fasd_add():
     # fm.notify("In add ")
     for fobj in fm.thistab.get_selection():
         try:
             check_output(['fasd', '--add', fobj.path])
         except subprocess.CalledProcessError:
             pass
コード例 #3
0
    def execute(self):
        import subprocess
        import os.path

        try:
            dir_to_search = spawn.check_output(
                "git rev-parse --show-toplevel").strip()
        except CalledProcessError:
            dir_to_search = "."

        if self.quantifier:
            # match only directories
            command = f"fd {os.environ['FD_ARGS']} --type d . '{dir_to_search}' | fzf +m"
        else:
            # match files and directories
            command = f"fd {os.environ['FD_ARGS']} . '{dir_to_search}' | fzf +m"
        fzf = self.fm.execute_command(command,
                                      universal_newlines=True,
                                      stdout=subprocess.PIPE)
        stdout, stderr = fzf.communicate()
        if fzf.returncode == 0:
            fzf_file = os.path.abspath(stdout.rstrip('\n'))
            if os.path.isdir(fzf_file):
                self.fm.cd(fzf_file)
            else:
                self.fm.select_file(fzf_file)
コード例 #4
0
    def _run(
            self,
            args,
            path=None,  # pylint: disable=too-many-arguments
            catchout=True,
            retbytes=False,
            rstrip_newline=True):
        """Run a command"""
        if self.repotype == 'hg':
            # use "chg", a faster built-in client
            cmd = ['chg'] + args
        else:
            cmd = [self.repotype] + args
        if path is None:
            path = self.path

        try:
            if catchout:
                output = spawn.check_output(cmd, cwd=path, decode=not retbytes)
                if not retbytes and rstrip_newline and output.endswith('\n'):
                    return output[:-1]
                return output
            else:
                with open(os.devnull, mode='w') as fd_devnull:
                    subprocess.check_call(cmd,
                                          cwd=path,
                                          stdout=fd_devnull,
                                          stderr=fd_devnull)
                return None
        except (subprocess.CalledProcessError, OSError):
            raise VcsError('{0:s}: {1:s}'.format(str(cmd), path))
コード例 #5
0
ファイル: ui.py プロジェクト: yjqg6666/ranger
    def restore_multiplexer_name(self):
        if self._multiplexer_title:
            try:
                if _in_tmux():
                    if self._tmux_automatic_rename:
                        check_output(['tmux', 'set-window-option',
                                      'automatic-rename',
                                      self._tmux_automatic_rename])
                    else:
                        check_output(['tmux', 'set-window-option', '-u',
                                      'automatic-rename'])
            except CalledProcessError:
                self.fm.notify("Could not restore multiplexer window name!",
                               bad=True)

            sys.stdout.write("\033k{0}\033\\".format(self._multiplexer_title))
            sys.stdout.flush()
コード例 #6
0
ファイル: linemode.py プロジェクト: ajtluser/ranger
 def infostring(self, fobj, metadata):
     if not fobj.is_directory:
         from subprocess import CalledProcessError
         try:
             fileinfo = spawn.check_output(["file", "-Lb", fobj.path]).strip()
         except CalledProcessError:
             return "unknown"
         return fileinfo
     else:
         raise NotImplementedError
コード例 #7
0
ファイル: linemode.py プロジェクト: joelostblom/ranger
 def infostring(self, fobj, metadata):
     if not fobj.is_directory:
         from subprocess import CalledProcessError
         try:
             fileinfo = spawn.check_output(["file", "-Lb",
                                            fobj.path]).strip()
         except CalledProcessError:
             return "unknown"
         return fileinfo
     else:
         raise NotImplementedError
コード例 #8
0
ファイル: linemode.py プロジェクト: dflupu/ranger
 def infostring(self, file, metadata):
     if not file.is_directory:
         from subprocess import Popen, PIPE, CalledProcessError
         try:
             fileinfo = spawn.check_output(["file", "-bL", file.path]).strip()
         except CalledProcessError:
             return "unknown"
         if sys.version_info[0] >= 3:
             fileinfo = fileinfo.decode("utf-8")
         return fileinfo
     else:
         raise NotImplementedError
コード例 #9
0
    def handle_multiplexer(self):
        if self.settings.update_tmux_title:
            if 'TMUX' in os.environ:
                # Stores the automatic-rename setting
                # prints out a warning if the allow-rename in tmux is not set
                tmux_allow_rename = check_output(
                    ['tmux', 'show-window-options', '-v',
                     'allow-rename']).strip()
                if tmux_allow_rename == 'off':
                    self.fm.notify('Warning: allow-rename not set in Tmux!',
                                   bad=True)
                elif self._tmux_title is None:
                    self._tmux_title = check_output(
                        ['tmux', 'display-message', '-p', '#W']).strip()
                else:
                    try:
                        self._tmux_automatic_rename = check_output(
                            ['tmux', 'show-window-options', '-v',
                             'automatic-rename']).strip()
                        if self._tmux_automatic_rename == 'on':
                            check_output(['tmux', 'set-window-option',
                                          'automatic-rename', 'off'])
                    except CalledProcessError:
                        pass
            elif 'screen' in os.environ['TERM'] and self._screen_title is None:
                # Stores the screen window name before renaming it
                # gives out a warning if $TERM is not "screen"
                try:
                    self._screen_title = check_output(
                        ['screen', '-Q', 'title']).strip()
                except CalledProcessError:
                    self._screen_title = None

            sys.stdout.write("\033kranger\033\\")
            sys.stdout.flush()
コード例 #10
0
ファイル: core.py プロジェクト: hankei6km/mirage_linemode
def spawn_xdg_user_dir(arg, default):
    ret = ''
    try:
        ret = spawn.check_output(['xdg-user-dir', arg]).strip()
    except AttributeError:
        try:
            ret = spawn.spawn(['xdg-user-dir', arg]).strip()
        except (OSError, CalledProcessError):
            ret = default
    except (OSError, CalledProcessError):
        ret = default
    ret = path.basename(ret)
    return ret
コード例 #11
0
 def infostring(self, file, metadata):
     if not file.is_directory:
         from subprocess import Popen, PIPE, CalledProcessError
         try:
             fileinfo = spawn.check_output(["file", "-bL",
                                            file.path]).strip()
         except CalledProcessError:
             return "unknown"
         if sys.version_info[0] >= 3:
             fileinfo = fileinfo.decode("utf-8")
         return fileinfo
     else:
         raise NotImplementedError
コード例 #12
0
ファイル: ui.py プロジェクト: sergeyguzhev/ranger
    def destroy(self):
        """Destroy all widgets and turn off curses"""
        if 'vcsthread' in self.__dict__:
            if not self.vcsthread.stop():
                self.fm.notify('Failed to stop `UI.vcsthread`', bad=True)
            del self.__dict__['vcsthread']
        DisplayableContainer.destroy(self)

        # Restore tmux setting `automatic-rename`
        if self.settings.update_tmux_title and 'TMUX' in os.environ:
            if self._tmux_automatic_rename:
                try:
                    check_output(['tmux', 'set-window-option',
                                  'automatic-rename', self._tmux_automatic_rename])
                except CalledProcessError:
                    pass
            else:
                try:
                    check_output(['tmux', 'set-window-option', '-u', 'automatic-rename'])
                except CalledProcessError:
                    pass

        self.suspend()
コード例 #13
0
 def restore_multiplexer_name(self):
     try:
         if 'TMUX' in os.environ:
             if self._tmux_automatic_rename:
                 check_output(['tmux', 'set-window-option',
                               'automatic-rename',
                               self._tmux_automatic_rename])
             else:
                 check_output(['tmux', 'set-window-option', '-u',
                               'automatic-rename'])
             if self._tmux_title:
                 check_output(['tmux', 'rename-window', self._tmux_title])
         elif 'screen' in os.environ['TERM'] and self._screen_title:
             check_output(['screen', '-X', 'title', self._screen_title])
     except CalledProcessError:
         self.fm.notify("Could not restore window-name!", bad=True)
コード例 #14
0
ファイル: ui.py プロジェクト: sit0/ranger
    def initialize(self):
        """initialize curses, then call setup (at the first time) and resize."""
        self.win.leaveok(0)
        self.win.keypad(1)
        self.load_mode = False

        curses.cbreak()
        curses.noecho()
        curses.halfdelay(20)
        try:
            curses.curs_set(int(bool(self.settings.show_cursor)))
        except curses.error:
            pass
        curses.start_color()
        try:
            curses.use_default_colors()
        except curses.error:
            pass

        self.settings.signal_bind('setopt.mouse_enabled', _setup_mouse)
        self.settings.signal_bind('setopt.freeze_files', self.redraw_statusbar)
        _setup_mouse(dict(value=self.settings.mouse_enabled))

        if not self.is_set_up:
            self.is_set_up = True
            self.setup()
            self.win.addstr("loading...")
            self.win.refresh()
            self._draw_title = curses.tigetflag('hs')  # has_status_line

            # Save tmux setting `automatic-rename`
            if self.settings.update_tmux_title and 'TMUX' in os.environ:
                try:
                    self._tmux_automatic_rename = check_output([
                        'tmux', 'show-window-options', '-v', 'automatic-rename'
                    ]).strip()
                except CalledProcessError:
                    self._tmux_automatic_rename = None

        self.update_size()
        self.is_on = True

        if self.settings.update_tmux_title and 'TMUX' in os.environ:
            sys.stdout.write("\033kranger\033\\")
            sys.stdout.flush()

        if 'vcsthread' in self.__dict__:
            self.vcsthread.unpause()
コード例 #15
0
ファイル: ui.py プロジェクト: sergeyguzhev/ranger
    def initialize(self):
        """initialize curses, then call setup (at the first time) and resize."""
        self.win.leaveok(0)
        self.win.keypad(1)
        self.load_mode = False

        curses.cbreak()
        curses.noecho()
        curses.halfdelay(20)
        try:
            curses.curs_set(int(bool(self.settings.show_cursor)))
        except curses.error:
            pass
        curses.start_color()
        try:
            curses.use_default_colors()
        except curses.error:
            pass

        self.settings.signal_bind('setopt.mouse_enabled', _setup_mouse)
        self.settings.signal_bind('setopt.freeze_files', self.redraw_statusbar)
        _setup_mouse(dict(value=self.settings.mouse_enabled))

        if not self.is_set_up:
            self.is_set_up = True
            self.setup()
            self.win.addstr("loading...")
            self.win.refresh()
            self._draw_title = curses.tigetflag('hs')  # has_status_line

            # Save tmux setting `automatic-rename`
            if self.settings.update_tmux_title and 'TMUX' in os.environ:
                try:
                    self._tmux_automatic_rename = check_output(
                        ['tmux', 'show-window-options', '-v', 'automatic-rename']).strip()
                except CalledProcessError:
                    self._tmux_automatic_rename = None

        self.update_size()
        self.is_on = True

        if self.settings.update_tmux_title and 'TMUX' in os.environ:
            sys.stdout.write("\033kranger\033\\")
            sys.stdout.flush()

        if 'vcsthread' in self.__dict__:
            self.vcsthread.unpause()
コード例 #16
0
ファイル: vcs.py プロジェクト: dflupu/ranger
    def _run(self, args, path=None,  # pylint: disable=too-many-arguments
             catchout=True, retbytes=False, rstrip_newline=True):
        """Run a command"""
        cmd = [self.repotype] + args
        if path is None:
            path = self.path

        try:
            if catchout:
                output = spawn.check_output(cmd, cwd=path, decode=not retbytes)
                if not retbytes and rstrip_newline and output.endswith('\n'):
                    return output[:-1]
                return output
            else:
                with open(os.devnull, mode='w') as fd_devnull:
                    subprocess.check_call(cmd, cwd=path, stdout=fd_devnull, stderr=fd_devnull)
        except (subprocess.CalledProcessError, FileNotFoundError):
            raise VcsError('{0:s}: {1:s}'.format(str(cmd), path))
コード例 #17
0
ファイル: ui.py プロジェクト: zyklotomic/ranger
    def handle_multiplexer(self):
        if (self.settings.update_tmux_title and not self._multiplexer_title):
            try:
                if _in_tmux():
                    # Stores the automatic-rename setting
                    # prints out a warning if allow-rename isn't set in tmux
                    try:
                        tmux_allow_rename = check_output([
                            'tmux', 'show-window-options', '-v', 'allow-rename'
                        ]).strip()
                    except CalledProcessError:
                        tmux_allow_rename = 'off'
                    if tmux_allow_rename == 'off':
                        self.fm.notify(
                            'Warning: allow-rename not set in Tmux!', bad=True)
                    else:
                        self._multiplexer_title = check_output(
                            ['tmux', 'display-message', '-p', '#W']).strip()
                        self._tmux_automatic_rename = check_output([
                            'tmux', 'show-window-options', '-v',
                            'automatic-rename'
                        ]).strip()
                        if self._tmux_automatic_rename == 'on':
                            check_output([
                                'tmux', 'set-window-option',
                                'automatic-rename', 'off'
                            ])
                elif _in_screen():
                    # Stores the screen window name before renaming it
                    # gives out a warning if $TERM is not "screen"
                    self._multiplexer_title = check_output(
                        ['screen', '-Q', 'title']).strip()
            except CalledProcessError:
                self.fm.notify(
                    "Couldn't access previous multiplexer window"
                    " name, won't be able to restore.",
                    bad=False)
            if not self._multiplexer_title:
                self._multiplexer_title = os.path.basename(
                    os.environ.get("SHELL", "shell"))

            sys.stdout.write("\033kranger\033\\")
            sys.stdout.flush()
コード例 #18
0
ファイル: fsobject.py プロジェクト: tkunic/ranger
 def filetype(self):
     try:
         return spawn.check_output(
             ["file", '-Lb', '--mime-type', self.path])
     except OSError:
         return ""
コード例 #19
0
ファイル: fasd_add.py プロジェクト: jameswritescode/dotfiles
 def fasd_add():
     for fobj in fm.thistab.get_selection():
         try:
             check_output(['fasd', '--add', fobj.path])
         except subprocess.CalledProcessError:
             pass
コード例 #20
0
ファイル: fsobject.py プロジェクト: phantasea/ranger
 def filetype(self):
     try:
         return spawn.check_output(["file", '-Lb', '--mime-type', self.path])
     except OSError:
         return ""