Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3f4dc26

Browse files
Added multi-select support to add and delete (#105)
1 parent 7be77f0 commit 3f4dc26

File tree

9 files changed

+37
-21
lines changed

9 files changed

+37
-21
lines changed

‎README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ Commands will list out the available branches or tags in `fzf` as a fuzzy search
7575

7676
Run any command or alias by passing it to the `ggo` command
7777

78+
For commands that support multiple selections, use `SHIFT+TAB` to mark each option.
79+
7880
```
7981
ggo [command|alias]
8082
```

‎git_gopher/Add.py‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ def __init__(self, command_runner, git_data_getter, fzf):
1111

1212
def run(self):
1313
unstaged_files = self._get_unstaged_files()
14-
filepath = self._get_user_selection(unstaged_files)
14+
filepaths = self._get_user_selections(unstaged_files)
1515

16-
if filepath:
17-
self._command_runner.run(['git', 'add', filepath])
16+
if filepaths:
17+
for filepath in filepaths:
18+
self._command_runner.run(['git', 'add', filepath])
1819

1920
def _get_unstaged_files(self):
2021
unstaged_files = self._git_data_getter.get_unstaged_files().splitlines()
@@ -55,10 +56,10 @@ def _colorize_unstaged_files(self, unstaged_files):
5556

5657
return unstaged_files
5758

58-
def _get_user_selection(self, unstaged_files):
59+
def _get_user_selections(self, unstaged_files):
5960
format_columns = FormatColumns()
6061
preview = "ggo-add-preview {2}"
61-
filepath = self._fzf.run(format_columns.set_colors({0: Fore.BLUE}).format('\n'.join(unstaged_files)), preview=preview, preview_window="--preview-window=right")
62+
filepaths = self._fzf.run(format_columns.set_colors({0: Fore.BLUE}).format('\n'.join(unstaged_files)), preview=preview, preview_window="--preview-window=right", multi="--multi")
6263

63-
if (filepath):
64-
return filepath.split('\t')[1].strip()
64+
if (filepaths):
65+
return list(map(lambdaline: line.split('\t')[1].strip(), filepaths.splitlines()))

‎git_gopher/DeleteBranch.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ def __init__(self, command_runner, git_data_getter):
66
self._git_data_getter = git_data_getter
77

88
def run(self):
9-
branch = self._git_data_getter.get_branch_name(preview='echo "git branch -d {2}"')
9+
branches = self._git_data_getter.get_branch_names(preview='echo "git branch -d {2}"')
1010

11-
if branch:
12-
self._command_runner.run(['git', 'branch', '-d', branch])
11+
if branches:
12+
for branch in branches:
13+
self._command_runner.run(['git', 'branch', '-d', branch])

‎git_gopher/DeleteBranchForce.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ def __init__(self, command_runner, git_data_getter):
66
self._git_data_getter = git_data_getter
77

88
def run(self):
9-
branch = self._git_data_getter.get_branch_name(preview='echo "git branch -D {2}"')
9+
branches = self._git_data_getter.get_branch_names(preview='echo "git branch -D {2}"')
1010

11-
if branch:
12-
self._command_runner.run(['git', 'branch', '-D', branch])
11+
if branches:
12+
for branch in branches:
13+
self._command_runner.run(['git', 'branch', '-D', branch])

‎git_gopher/Fzf.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from subprocess import check_output, CalledProcessError
22

33
class Fzf:
4-
def run(self, options: str, preview: str="", preview_window: str="--preview-window=down:5"):
5-
cmd: list = ['fzf', '--no-sort', '--no-hscroll', '--ansi', '--no-multi', '--preview='+preview, preview_window]
4+
def run(self, options: str, preview: str="", preview_window: str="--preview-window=down:5", multi: str="--no-multi"):
5+
cmd: list = ['fzf', '--no-sort', '--no-hscroll', '--ansi', multi, '--preview='+preview, preview_window]
66
try:
77
return check_output(cmd, input=str.encode(options)).decode()
88
except CalledProcessError as e:

‎git_gopher/GitDataGetter.py‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,22 @@ def get_current_branch_name(self):
1313
return check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']).decode().strip().strip("'")
1414

1515
def get_branch_name(self, options=[], preview="git config branch.{2}.description"):
16+
return self._get_branches(options, preview, '--no-multi')
17+
18+
def get_branch_names(self, options=[], preview="git config branch.{2}.description"):
19+
return self._get_branches(options, preview, '--multi')
20+
21+
def _get_branches(self, options, preview, multi):
1622
format_columns = FormatColumns()
1723
branches = 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)']).decode()
1824
branches = check_output(['sed', '/^$/d'], input=str.encode(format_columns.set_colors({0: Fore.BLUE}).format(branches)))
19-
line = self._fzf.run(branches.decode(), preview=preview)
25+
lines = self._fzf.run(branches.decode(), preview=preview, multi=multi)
2026

21-
if line:
22-
return line.split('\t')[1].strip()
27+
if lines:
28+
if multi == '--multi':
29+
return list(map(lambda line: line.split('\t')[1].strip(), lines.splitlines()))
30+
else:
31+
return lines.split('\t')[1].strip()
2332

2433
def get_tag_name_from_tags(self, tags, options=[], preview=""):
2534
format_columns = FormatColumns()

‎setup.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
# For a discussion on single-sourcing the version across setup.py and the
3131
# project code, see
3232
# https://packaging.python.org/en/latest/single_source_version.html
33-
version='0.4.5', # Required
33+
version='0.4.6', # Required
3434

3535
# This is a one-line description or tagline of what your project does. This
3636
# corresponds to the "Summary" metadata field:

‎test/test_DeleteBranch.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ class TestDeleteBranch(unittest.TestCase):
99

1010
def test_run(self):
1111
branch = 'foo'
12+
branches = [branch]
1213
git_data_getter = GitDataGetter(Fzf())
13-
git_data_getter.get_branch_name = MagicMock(return_value=branch)
14+
git_data_getter.get_branch_names = MagicMock(return_value=branches)
1415
command_runner = CommandRunner(git_data_getter)
1516
command_runner.run = MagicMock()
1617
delete_branch = DeleteBranch(command_runner, git_data_getter)

‎test/test_DeleteBranchForce.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ class TestDeleteBranchForce(unittest.TestCase):
99

1010
def test_run(self):
1111
branch = 'foo'
12+
branches = [branch]
1213
git_data_getter = GitDataGetter(Fzf())
13-
git_data_getter.get_branch_name = MagicMock(return_value=branch)
14+
git_data_getter.get_branch_names = MagicMock(return_value=branches)
1415
command_runner = CommandRunner(git_data_getter)
1516
command_runner.run = MagicMock()
1617
delete_branch_force = DeleteBranchForce(command_runner, git_data_getter)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /