I'm trying to write a command in vifm (on linux) that copies the content of an image to the clipboard, using copyq.
This is what I got so far:
I use the command xdg-mime query filetype myfile.jpg
to get the mimetype.
I use qcopy
to write the content of the file to the clipboard like this:
qcopy write $MIMETYPE - < myfile.jpg
The following command works fine in the shell and the content of the file gets copied to the clipboard:
qcopy write $(xdg-mime query filetype myfile.jpg) - < myfile.jpg
Now how can I rewrite this command as a vifm command in my vifmrc
file?
I tried this but it doesn't work:
command! copyf
\| let $MIMETYPE = system(expand('xdg-mime query filetype %c'))
\| execute expand("copyq write $MIMETYPE - < %c && copyq select 0")
I just get an "Invalid command name" error.
CodePudding user response:
There are multiple issues here:
- By default command's body is executed by the shell, if you start it with a colon, it will be processed as an internal one. See help.
- You need to have a space between command name and its body and writing
copyf\n<spaces>\|
results in first argument of:command
beingcopyf|
, henceIncorrect command name
error. Help. qcopy
was spelled ascopyq
in one place.:execute
runs an internal command, internal command called!
runs a shell command, so!
needs to be used on the last line.%
in a body of a command is expanded automatically, need to double it to escape so that it's expanded later. Last line is expanded also byexpand()
, so double escaping of%
there.
Fixed version that should work:
command! copyf
\ : let $MIMETYPE = system(expand('xdg-mime query filetype %%c'))
\ | execute expand('!qcopy write $MIMETYPE - < %%%%c && copyq select 0')