Skip to content

Latest commit

 

History

History

copy-filename

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

copy-filename.lua

Copy current file's name or path to clipboard.

Video tutorial:

Video tutorial

Support me on Ko-fi

Dependencies and running this script on different OSes

Video commentary

This script needs to run an external command in order to copy text to the clipboard.

That command is set with the clipboard_command option, which has the default value of 'xclip -rmlastnl -selection clipboard'. See the Options section for more information.

On Linux, if you don't already have xclip installed, you can install it with your distribution's package manager (e.g. on Debian, run sudo apt install xclip).

On macOS, set the clipboard_command option to pbcopy.

On Windows, a modification to the script is required. An imperfect example can be found in a previous commit, here. Since I don't run Windows, I won't be able to provide much support regarding this issue, but if someone knows a robust solution to this, I would be glad to hear from you. Take a look at this Issues thread for more information.

Options

Video tutorial

Options can be set either on the command line, or in a config file.

In both cases, this script's identifier – copy_subtitle – will be needed.

Use --script-opts=<identifier>-<option>=<value>,... to set options on the command line.

To set options in a config file, create the following file: ~/.config/mpv/script-opts/<identifier>.conf. Set options in the file, one per line, in the following fashion: <option>=<value>.

More information on mpv's script-opts command line and config file syntax can be found here (based on the example of the built-in osc.lua script).

NOTE: The table below shows values as they appear in the script's source code written in Lua. When passing script options on the command line, or setting them in a config file, in mpv you use the words yes and no instead of Lua's true and false, respectively.

The following options are available for this script:

Option Default value
console_message true
console_message_print_copied true
osd_message true
osd_message_print_copied true
clipboard_command 'xclip -rmlastnl -selection clipboard'

Keybindings

Video tutorial

Keybindings can be remapped in ~/.config/mpv/input.conf. Add a line in the following format to remap a keybinding: <key> script-binding <name>.

If you remap a keybinding, you will likely want to disable the default keybinding by adding <default key> ignore to ~/.config/mpv/input.conf. See the video tutorial linked to above for a demonstration and for information on how to see what a given key is currently mapped to in mpv.

The following keybindings are available for this script:

Key Name
Ctrl+z copy-filename-basename
Ctrl+Alt+z copy-filename-relative-path
Ctrl+Z copy-filename-absolute-path

License

GNU General Public License v3.0