Skip to content

Commit 2c4bcf0

Browse files
committed
Add flag --mark to :copy-name to copy marked images
The flag `--mark` makes the command act on all marked images instead of the currently selected path. All other flags of `:copy-name` can be combined with this one.
1 parent 6759320 commit 2c4bcf0

File tree

3 files changed

+33
-16
lines changed

3 files changed

+33
-16
lines changed

docs/changelog.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ Changed:
2626
* Support for PyQt5 < 5.15 was dropped.
2727
* The option to read binary images from stdin using ``vimiv -``. Thanks `@mozirilla213`_
2828
for the idea and initial implementation!
29+
* Command ``:copy-name`` takes the paths to copy as an argument. This allows to copy
30+
e.g. all marked images, using ``:copy-name %m``. Keybinding for this new functionality
31+
have been added.
2932

3033
Fixed:
3134
^^^^^^

tests/end2end/features/misc/clipboard.feature

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,37 @@ Feature: Interaction with the system clipboard.
22

33
Scenario: Copy basename from library path to clipboard.
44
Given I open a directory with 1 paths
5-
When I run copy-name
5+
When I run copy-name %
66
Then the clipboard should contain 'child_01'
77

88
Scenario: Copy basename from library path to primary.
99
Given I open a directory with 1 paths
10-
When I run copy-name --primary
10+
When I run copy-name % --primary
1111
Then the primary selection should contain 'child_01'
1212

1313
Scenario: Copy abspath from library path to clipboard.
1414
Given I open a directory with 1 paths
15-
When I run copy-name --abspath
15+
When I run copy-name % --abspath
1616
# /tmp from the directory in which tests are run
1717
Then the absolute path of child_01 should be saved in the clipboard
1818

1919
Scenario: Copy basename from image path to clipboard.
2020
Given I open any image
21-
When I run copy-name
21+
When I run copy-name %
2222
Then the clipboard should contain 'image.jpg'
2323

2424
Scenario: Copy and paste basename from library
2525
Given I open a directory with 1 paths
26-
When I run copy-name
26+
When I run copy-name %
2727
And I run paste-name
2828
Then the working directory should be child_01
2929

30+
Scenario: Copy basename from marked images to clipboard.
31+
Given I open 5 images
32+
When I run mark image_01.jpg image_02.jpg
33+
And I run copy-name %m
34+
Then the clipboard should contain 'image_01.jpg image_02.jpg'
35+
3036
Scenario: Copy image to clipboard.
3137
Given I open any image
3238
When I run copy-image

vimiv/api/_modules.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"""
88

99
import os
10-
from typing import List
10+
from typing import List, Iterable
1111

1212
from vimiv.qt.core import QDateTime
1313
from vimiv.qt.gui import QGuiApplication, QClipboard
@@ -64,25 +64,33 @@ def toggle(mode: str) -> None:
6464
api.modes.get_by_name(mode).toggle()
6565

6666

67-
@api.keybindings.register("yA", "copy-name --abspath --primary")
68-
@api.keybindings.register("yY", "copy-name --primary")
69-
@api.keybindings.register("ya", "copy-name --abspath")
70-
@api.keybindings.register("yy", "copy-name")
67+
@api.keybindings.register("yA", "copy-name % --abspath --primary")
68+
@api.keybindings.register("yY", "copy-name % --primary")
69+
@api.keybindings.register("ya", "copy-name % --abspath")
70+
@api.keybindings.register("yy", "copy-name %")
71+
@api.keybindings.register("ymA", "copy-name %m --abspath --primary")
72+
@api.keybindings.register("ymY", "copy-name %m --primary")
73+
@api.keybindings.register("yma", "copy-name %m --abspath")
74+
@api.keybindings.register("ymy", "copy-name %m")
7175
@api.commands.register()
72-
def copy_name(abspath: bool = False, primary: bool = False) -> None:
73-
"""Copy name of current path to system clipboard.
76+
def copy_name(
77+
paths: Iterable[str], abspath: bool = False, primary: bool = False
78+
) -> None:
79+
"""Copy file name or full path of provided paths(s) to system clipboard.
80+
81+
**syntax:** ``:copy-name path [path ...] [--abspath] [--primary]``
7482
75-
**syntax:** ``:copy-name [--abspath] [--primary]``
83+
positional arguments:
84+
* ``paths``: The path(s) to copy.
7685
7786
optional arguments:
7887
* ``--abspath``: Copy absolute path instead of basename.
7988
* ``--primary``: Copy to primary selection.
8089
"""
8190
clipboard = QGuiApplication.clipboard()
8291
mode = QClipboard.Mode.Selection if primary else QClipboard.Mode.Clipboard
83-
path = api.current_path()
84-
name = path if abspath else os.path.basename(path)
85-
clipboard.setText(name, mode=mode)
92+
text = " ".join(path if abspath else os.path.basename(path) for path in paths)
93+
clipboard.setText(text, mode=mode)
8694

8795

8896
@api.keybindings.register("yi", "copy-image")

0 commit comments

Comments
 (0)