Skip to content

Commit c87d256

Browse files
committed
Change argument of copy_name to be the paths itself
This way we can remove the --mark flag again. This however, breaks backward compatibility.
1 parent 3c26695 commit c87d256

File tree

3 files changed

+28
-24
lines changed

3 files changed

+28
-24
lines changed

docs/changelog.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@ Added:
1717
* ``6`` or ``PyQt6``: Use PyQt6.
1818
* ``PySide6``: Use PySide6 (Qt for Python). This is highly experimental and should be
1919
used with care.
20-
* The ``--mark`` flag to ``:copy-name`` command. It allows for copying the names of all
21-
marked images instead of the currently selected one.
2220

2321
Changed:
2422
^^^^^^^^
2523

2624
* The JPEG image header check was simplified to have a false negative rate of 0, while
2725
maintaining a decently low false positive rate.
2826
* Support for PyQt5 < 5.15 was dropped.
27+
* Command ``:copy-name`` takes the paths to copy as an argument. This allows to copy
28+
e.g. all marked images, using ``:copy-name %m``. Keybinding for this new functionality
29+
have been added.
2930

3031
Fixed:
3132
^^^^^^

tests/end2end/features/misc/clipboard.feature

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,35 @@ 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

3030
Scenario: Copy basename from marked images to clipboard.
3131
Given I open 5 images
3232
When I run mark image_01.jpg image_02.jpg
33-
And I run copy-name --mark
33+
And I run copy-name %m
3434
Then the clipboard should contain 'image_01.jpg image_02.jpg'
3535

3636
Scenario: Copy image to clipboard.

vimiv/api/_modules.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"""
1212

1313
import os
14-
from typing import List
14+
from typing import List, Iterable
1515

1616
from vimiv.qt.core import QDateTime
1717
from vimiv.qt.gui import QGuiApplication, QClipboard
@@ -68,30 +68,33 @@ def toggle(mode: str) -> None:
6868
api.modes.get_by_name(mode).toggle()
6969

7070

71-
@api.keybindings.register("yA", "copy-name --abspath --primary")
72-
@api.keybindings.register("yY", "copy-name --primary")
73-
@api.keybindings.register("ya", "copy-name --abspath")
74-
@api.keybindings.register("yy", "copy-name")
75-
@api.keybindings.register("ymA", "copy-name --abspath --primary --mark")
76-
@api.keybindings.register("ymY", "copy-name --primary --mark")
77-
@api.keybindings.register("yma", "copy-name --abspath --mark")
78-
@api.keybindings.register("ymy", "copy-name --mark")
71+
@api.keybindings.register("yA", "copy-name % --abspath --primary")
72+
@api.keybindings.register("yY", "copy-name % --primary")
73+
@api.keybindings.register("ya", "copy-name % --abspath")
74+
@api.keybindings.register("yy", "copy-name %")
75+
@api.keybindings.register("ymA", "copy-name %m --abspath --primary")
76+
@api.keybindings.register("ymY", "copy-name %m --primary")
77+
@api.keybindings.register("yma", "copy-name %m --abspath")
78+
@api.keybindings.register("ymy", "copy-name %m")
7979
@api.commands.register()
80-
def copy_name(abspath: bool = False, primary: bool = False, mark: bool = False) -> None:
81-
"""Copy name of current path or of marked images to system clipboard.
80+
def copy_name(
81+
paths: Iterable[str], abspath: bool = False, primary: bool = False
82+
) -> None:
83+
"""Copy file name or full path of provided paths(s) to system clipboard.
84+
85+
**syntax:** ``:copy-name path [path ...] [--abspath] [--primary]``
8286
83-
**syntax:** ``:copy-name [--abspath] [--primary] [--mark]``
87+
positional arguments:
88+
* ``paths``: The path(s) to copy.
8489
8590
optional arguments:
8691
* ``--abspath``: Copy absolute path instead of basename.
8792
* ``--primary``: Copy to primary selection.
88-
* ``--mark``: Copy all marked images instead of current path.
8993
"""
9094
clipboard = QGuiApplication.clipboard()
9195
mode = QClipboard.Mode.Selection if primary else QClipboard.Mode.Clipboard
92-
paths = api.mark.paths if mark else [api.current_path()]
93-
names = [path if abspath else os.path.basename(path) for path in paths]
94-
clipboard.setText(" ".join(names), mode=mode)
96+
text = " ".join(path if abspath else os.path.basename(path) for path in paths)
97+
clipboard.setText(text, mode=mode)
9598

9699

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

0 commit comments

Comments
 (0)