Use sed to remove everything after and including the first dot:
:nnoremap yn :!sed "s/\..*//"<<<%c|xclip -selection clipboard %i<cr>
If your shell does not support herestrings (<<<
), use printf
(Why is printf better than echo?) to pipe into sed:
:nnoremap yn :!printf '%%s' %c|sed "s/\..*//"|xclip -selection clipboard %i<cr>
Vifm processes the macros before passing the
command to the shell. %c
becomes the file name (properly escaped);
%s
would also be substituted, thus %%s
is needed so that
printf gets a %s
. Likewise, <cr>
is the "Enter
equivalent" and is required, otherwise the command whole simply
pops up in the command-line.
This has been tested. Even the exquisitely named file
t*.a .<!e>&
passed the test, the clipboard gets t*
.
If you want to remove everything after and including the last
dot (not the first), use sed "s/\.[^.]*$//"
.
To display the copied string in the statusbar, repeat the command up to sed
and use the %S
macro.
:nnoremap yn :!printf '%%s' %c|sed "s/\..*//"|xclip -selection clipboard %i<cr>:!printf '%%s' %c|sed "s/\..*//;s/$/ is yanked to clipboard/" %S<cr>
basename
tool to remove them (or at least what looks like one). – ctrl-alt-delor Aug 06 '20 at 14:51<
and>
have special meaning in the shell. You will get some very unexpected behavior. – ctrl-alt-delor Aug 06 '20 at 14:52basename
man page: "Print NAME with any leading directory components removed. If specified, also remove a trailing SUFFIX." – ctrl-alt-delor Aug 06 '20 at 15:49basename "$(basename "$fileName" .sh)" .txt
— OK this dose not scale to any "extension". — usesed
. – ctrl-alt-delor Aug 06 '20 at 19:51