Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ Changed:
* Support for PyQt5 < 5.15 was dropped.
* The option to read binary images from stdin using ``vimiv -``. Thanks `@mozirilla213`_
for the idea and initial implementation!
* Command ``:copy-name`` takes the paths to copy as an argument. This allows to copy
e.g. all marked images, using ``:copy-name %m``. Keybinding for this new functionality
have been added.

Fixed:
^^^^^^
Expand Down
16 changes: 11 additions & 5 deletions tests/end2end/features/misc/clipboard.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,37 @@ Feature: Interaction with the system clipboard.

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

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

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

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

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

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

Scenario: Copy image to clipboard.
Given I open any image
When I run copy-image
Expand Down
30 changes: 19 additions & 11 deletions vimiv/api/_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""

import os
from typing import List
from typing import List, Iterable

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


@api.keybindings.register("yA", "copy-name --abspath --primary")
@api.keybindings.register("yY", "copy-name --primary")
@api.keybindings.register("ya", "copy-name --abspath")
@api.keybindings.register("yy", "copy-name")
@api.keybindings.register("yA", "copy-name % --abspath --primary")
@api.keybindings.register("yY", "copy-name % --primary")
@api.keybindings.register("ya", "copy-name % --abspath")
@api.keybindings.register("yy", "copy-name %")
@api.keybindings.register("ymA", "copy-name %m --abspath --primary")
@api.keybindings.register("ymY", "copy-name %m --primary")
@api.keybindings.register("yma", "copy-name %m --abspath")
@api.keybindings.register("ymy", "copy-name %m")
@api.commands.register()
def copy_name(abspath: bool = False, primary: bool = False) -> None:
"""Copy name of current path to system clipboard.
def copy_name(
paths: Iterable[str], abspath: bool = False, primary: bool = False
) -> None:
"""Copy file name or full path of provided paths(s) to system clipboard.

**syntax:** ``:copy-name path [path ...] [--abspath] [--primary]``

**syntax:** ``:copy-name [--abspath] [--primary]``
positional arguments:
* ``paths``: The path(s) to copy.

optional arguments:
* ``--abspath``: Copy absolute path instead of basename.
* ``--primary``: Copy to primary selection.
"""
clipboard = QGuiApplication.clipboard()
mode = QClipboard.Mode.Selection if primary else QClipboard.Mode.Clipboard
path = api.current_path()
name = path if abspath else os.path.basename(path)
clipboard.setText(name, mode=mode)
text = " ".join(path if abspath else os.path.basename(path) for path in paths)
clipboard.setText(text, mode=mode)


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