Ejemplo n.º 1
0
    def get_tag_name_from_tags(
            self,
            tags,
            options: List[str] = [],
            preview: str = "",
            multi: str = "--no-multi") -> Union[str, List[str]]:
        format_columns = FormatColumns()

        # prepend 'tag' to each line
        tags = self._prefix_lines_with(tags, 'tag').splitlines()
        tags.reverse()
        tags = '\n'.join(tags)

        if not tags:
            raise NoTagsException

        lines = self._fzf.run(format_columns.set_colors({
            0: Fore.BLUE
        }).format(tags),
                              preview=preview,
                              multi=multi)

        if lines:
            if multi == '--multi':
                return list(
                    map(lambda line: line.split('\t')[1].strip(),
                        lines.splitlines()))
            else:
                return lines.split('\t')[1].strip()
Ejemplo n.º 2
0
 def get_semantic_part(self, preview: str = None) -> str:
     options = "Part|Patch\nPart|Minor\nPart|Major"
     format_columns = FormatColumns()
     selection = self._fzf.run(format_columns.set_colors({
         0: Fore.BLUE
     }).format(options),
                               preview=preview)
     if selection:
         return selection.split('\t')[1].strip()
Ejemplo n.º 3
0
    def run(self):
        options = self._options.get()

        format_columns = FormatColumns()
        result = self._fzf.run(
            format_columns.set_colors({
                0: Fore.BLUE,
                1: Fore.YELLOW
            }).format(options))

        command = self._get_column(result, 0)
        process = run(command.split())
Ejemplo n.º 4
0
    def run(self):
        history_path = path.expanduser("~") + "/.config/git-gopher/history"

        if not path.exists(history_path):
            return "No git-gopher history found"

        history = Path(history_path).read_text().splitlines()
        history.reverse()
        history = '\n'.join(history)
        format_columns = FormatColumns()
        return pager(
            format_columns.set_colors({
                0: Fore.BLUE,
                1: Fore.YELLOW
            }).format(history))
Ejemplo n.º 5
0
 def get_branch_names_remote(self,
                             remote: str,
                             preview: str = "") -> List[str]:
     format_columns = FormatColumns()
     branches = self._command_runner.check_output(
         ['git', 'ls-remote', '--heads', remote])
     branches = list(
         map(
             lambda line: 'branch|' + line.split()[1].strip().replace(
                 'refs/heads/', ''), branches.splitlines()))
     lines = self._fzf.run(format_columns.set_colors({
         0: Fore.BLUE
     }).format('\n'.join(branches)),
                           multi='--multi')
     return list(
         map(lambda line: line.split('\t')[1].strip(), lines.splitlines()))
Ejemplo n.º 6
0
    def get_stash_ref(self, preview: str = "") -> str:
        format_columns = FormatColumns()
        DIR = path.dirname(path.realpath(__file__))
        preview = "echo {1} | xargs git stash show -p | cat <(echo -n \"" + preview + "\n\nALT+J: Down | ALT+K: Up\n----------------------------\n\n\") - | ggo-colorize"
        stashes = '\n'.join(
            list(
                map(
                    lambda line: sub(':', ' |', line),
                    self._command_runner.check_output(['git', 'stash',
                                                       'list']).splitlines())))
        stash = self._fzf.run(format_columns.set_colors({
            0: Fore.BLUE
        }).format(stashes),
                              preview=preview,
                              preview_window="--preview-window=right")

        if stash:
            return stash.split('\t')[0].strip()
Ejemplo n.º 7
0
    def get_local_tag_name(self,
                           remote,
                           options: List[str] = [],
                           preview: str = "") -> str:
        format_columns = FormatColumns()
        local_tags = list(
            map(
                lambda line: line.split()[1].strip(),
                self._command_runner.check_output(
                    ['git', 'show-ref', '--tags']).splitlines()))
        remote_tags = self.get_remote_tags(remote)
        unpushed_tags = set(local_tags) - set(remote_tags)
        unpushed_tags = '\n'.join(
            list(map(lambda tag: tag.split('/')[2], unpushed_tags)))
        line = self._fzf.run(format_columns.set_colors({
            0: Fore.BLUE
        }).format(self._prefix_lines_with(unpushed_tags, 'tag')),
                             preview=preview)

        if line:
            return line.split('\t')[1].strip()
Ejemplo n.º 8
0
    def _get_branches(self, options: str, preview: str,
                      multi: str) -> Union[str, List[str]]:
        format_columns = FormatColumns()
        branches = self._command_runner.check_output([
            'git', '--no-pager', 'branch', *options,
            '--format=%(if)%(HEAD)%(then)%(else)%(if:equals=HEAD)%(refname:strip=3)%(then)%(else)branch | %(refname:short)%(end)%(end)'
        ])
        branches = self._command_runner.check_output(
            ['sed', '/^$/d'],
            input=str.encode(
                format_columns.set_colors({
                    0: Fore.BLUE
                }).format(branches)))
        lines = self._fzf.run(branches, preview=preview, multi=multi)

        if lines:
            if multi == '--multi':
                return list(
                    map(lambda line: line.split('\t')[1].strip(),
                        lines.splitlines()))
            else:
                return lines.split('\t')[1].strip()
Ejemplo n.º 9
0
    def get_remote_name(self, preview: str = "") -> str:
        format_columns = FormatColumns()
        remotes_list = list(
            set(
                self._command_runner.check_output(['git', 'remote',
                                                   '-v']).splitlines()))
        remotes = ""

        for line in remotes_list:
            if "push" in line:
                line = sub(r'\s+\(push\)', '', line)
                line = self._replace_tab_with_pipe(line)
                line = "remote | " + line
                remotes += line + "\n"

        line = self._fzf.run(format_columns.set_colors({
            0: Fore.BLUE
        }).format(remotes),
                             preview=preview)

        if line:
            return line.split('\t')[1].strip()