This forum has been archived. All content is frozen. Please use KDE Discuss instead.

how to copy filename without file://?

Tags: None
(comma "," separated)
User avatar
toad
Global Moderator
Posts
1258
Karma
7
OS
Ah, I forgot about F4! Very good solution and I think that is the closest you get to what you want - regardless of which file manager you look at.


Debian testing
Flitcraft
Registered Member
Posts
4
Karma
0
RazrFalcon wrote:I use F4 to show terminal in Dolphin, and then start ls, to show file paths.



You can simply drag and drop the file to the konsole window to copy the full path.
User avatar
sparhawk
Registered Member
Posts
433
Karma
0
OS
I know that this is an old thread, but I still think it's the best place to comment.

Flitcraft wrote:You can simply drag and drop the file to the konsole window to copy the full path.


I use terminator instead of konsole/yakuake (because of this bug). Dragging and dropping into terminator doesn't work. Not only does it keep the "file://" prefix, but all spaces are translated into the url code %20.

As stated previous in this thread, I find that the klipper actions also modify the spaces to %20, which seems like a bug. Also, I find using klipper actions inconvenient, since (as above in the thread) I get an annoying popup every single time I copy something now.

Instead, I've created a custom code to modify the contents of the clipboard. The code reads the clipboard, strips the file://, then puts this back into the clipboard.
Code: Select all
xclip -o -selection clipboard | sed 's/^file:\/\///' | xclip -selection clipboard


I then assigned this to a shortcut key in System Settings > Shortcuts and Gestures > Custom Shortcuts, assigning it to (e.g.) alt+ctrl+v. Now I've just got to remember to use this everytime before I paste into the terminal!

I thought it might have been nice to rebind ctrl+v to do the sed and then paste all in one go, but I don't think that is possible. I could use xvkbd to type out the clipboard, but then I think it'd fail if I try and copy-paste images, etc.

===EDIT===

I've decided that since I'm only ever going to run this command on clipboards copied from Dolphin anyway, I might as well automatically paste it. I've also wrapped ' around the path too, since I always forget to do that.
Code: Select all
xclip -o -selection clipboard | sed -r "s/^file:\/\/(.*)/'\1'/" | xvkbd -xsendevent -file - 2>/dev/null


However, I'm actually using this code, which also replaces the clipboard at the same time, since I can think of no useful reason why we should have the "file://" prefix in the first place.
Code: Select all
bash -c 'xclip -o -selection clipboard | sed -r "s/^file:\/\/(.*)/'"'"'\1'"'"'/" | tee >( xvkbd -xsendevent -file - 2>/dev/null ) | xclip -selection clipboard'
User avatar
sparhawk
Registered Member
Posts
433
Karma
0
OS
I've since found xvkbd in my code above to be quite slow when "pasting" into the terminal. Hence, I'm now using the following code, which simulates a Ctrl+v instead. This will fail in programs such as default Konsole, where paste is not bound to Ctrl+v, but it's almost instantaneous for other programs (or you could change \Cv to \CV for the default Konsole Ctrl+Shift+V).

Code: Select all
bash -c 'xclip -o -selection clipboard | sed -r "s/^file:\/\/(.*)/'"'"'\1'"'"'/" | xclip -selection clipboard; xvkbd -xsendevent -text "\Cv" 2>/dev/null'
noric
Registered Member
Posts
42
Karma
0
OS


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], rockscient, Yahoo [Bot]