LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Why does Kate replace spaces in filename with "%20", thus preventing opening it? (https://www.linuxquestions.org/questions/linux-general-1/why-does-kate-replace-spaces-in-filename-with-20-thus-preventing-opening-it-4175631209/)

winger9 06-04-2018 04:15 PM

Why does Kate replace spaces in filename with "%20", thus preventing opening it?
 
I'm using the the Kate editor ver 16.04.2 on live knoppix 7.7.1 on a usb stick.

When I double-click on a normal text file in pcmanfm, Kate opens but it
replaces the spaces in the filename with "%20", and a message says "New", which
I presume means "new file". The contents of the file I double-clicked on do not
appear in Kate, but the text window is empty.

Say the true filename is "my notes", then Kate changes it to "my%20notes".

If I open Kate separately, then opening the file in the following ways DOES
work:
a) Using File/Open from Kate's menu, and selecting the file from there.
b) Clicking and dragging the file from pcmanfm across to the Kate window.

My humble question:
Why does the double-click opening method replace spaces with "%20", and how do
I fix it?

On my main Debian system on the hard drive, Kate (ver 3.8.4) opens a
double-clicked file fine.

teckk 06-04-2018 04:57 PM

Quote:

Why does the double-click opening method replace spaces with "%20", and how do I fix it?
You should not have files names with spaces in them. Change my file to my_file or something with allowed characters. If your file name has spaces in it then you'll have to quote the name. Or better yet, don't put spaces in file names.

If you try
Code:

ls my notes
You'll get an error
Code:

ls "my notes"
Will work.

jbuckley2004 06-05-2018 12:19 AM

I'm not sure teckk is exactly right. %20 is the hexadecimal equivalent to the space character. Spaces in file names have been "ok" to use in both linux and windows (and I think in whatever version of the OS Apple's been using) for quite some time. There are some rules, though.

If your using a terminal emulator (I use KDE, and Konsole alot) it will take spaces for the names of files, but you either have to enclose the entire file name in quotes or you have to use the \ character to make it suppress the special meaning of the next character (the space, in this case, which usually means "here is the next part of the command on this line") and take it as a plain character. So the command to list my file.txt should be typed as
Code:

#ls my\ file.txt
No quotes needed, but it often becomes hard to read.

But here's something I discovered about kate. I often create playlists for my mp3 player using VLC. The standard play list has two lines for every file, the first being a comment, the second being the file name. When I use kate to open the file created by VLC, the file name line always uses %20 for spaces, but the comment line does not. That one reads as you'd expect, with the space character.

I usually do a edit -> replace all in kate to change the %20s to the space character.

If I recall correctly, kwrite does not do this. So yes, I agree that it's some setting or other in kate that I do not understand either.

hydrurga 06-05-2018 12:24 AM

Just a note that the OP, presumably, has also set up a question on the issue on Stack Exchange:

https://unix.stackexchange.com/quest...ing-opening-it

DavidMcCann 06-05-2018 11:23 AM

Quote:

Originally Posted by jbuckley2004 (Post 5863778)
Spaces in file names have been "ok" to use in both linux … for quite some time. If your using a terminal emulator … you either have to enclose the entire file name in quotes or you have to use the \ character to make it suppress the special meaning of the next character

Spaces will work in GUI programs and you can force them to work in the command line. But they are not actually acceptable in Unix file names (which, of course, includes internet addresses) and may cause havoc with scripts or other programs that have not been designed to cope with them. It's far better to stick to the rules for file names:
1. start with a letter or number
2. only use letters, numbers, under-scores, hyphens, or dots

hydrurga 06-05-2018 11:27 AM

Quote:

Originally Posted by DavidMcCann (Post 5863978)
Spaces will work in GUI programs and you can force them to work in the command line. But they are not actually acceptable in Unix file names (which, of course, includes internet addresses) and may cause havoc with scripts or other programs that have not been designed to cope with them. It's far better to stick to the rules for file names:
1. start with a letter or number
2. only use letters, numbers, under-scores, hyphens, or dots

It may be recommended that you don't use them, but spaces *are* allowed in *nix filenames.

https://unix.stackexchange.com/quest...-in-a-filename

winger9 06-05-2018 02:55 PM

Thanks for your kind responses.

Could I humbly point out that it's not the use of spaces in filenames that is
the problem.


As I mentioned at the end of my original thread, I have NO PROBLEM
double-clicking a filename in pcmanfm* file manager on my main Debian system on
the hard drive. Kate happily opens the file, and spaces aren't replaced with
%20. (*I think it's an older version than pcmanfm on the live knoppix 7.7.1 on
usb stick.)

It's when I double-click a file in pcmanfm (ver 1.2.4) ON THE STICK when spaces
are replaced by %20 in Kate.

I did the following tests (SOLELY on the stick):

1) Using pcmanfm:

a) (This is the SAME scenario I've already described in my original thread.)

Kate was already the default application that's launched when a text file is
double-clicked. I double-clicked the file "my notes" in pcmanfm, but Kate
opened a NEW file called "my%20notes", with nothing in it.

b) While Kate was still open at "a)", I did the following to see what filename
was passed to Kate:

Code:

$ ps ax | grep kate
4893 tty5    Sl    0:01 kate -b file:///home/knoppix/my%20notes

c) I changed the default launch application from Kate to KWrite. When I
double-clicked "my notes", KWrite opened a NEW file called "my%20notes".

d) I changed the default launch application to Leafpad. When I double-clicked
"my notes", Leafpad CORRECTLY opened "my notes".

2) Using nautilus file manager:

I set the default launch application to Kate. When I double-clicked "my notes",
Kate CORRECTLY opened "my notes" (ie no %20 used).

CONCLUSIONS so far:

It seems to be ONLY pcmanfm (not other file managers, such as nautilus) that
"causes" %20 to be used in Kate. Also it seems to be KDE launch applications
(Kate and KWrite) in which the %20 problem occurs - but only via pcmanfm. I
don't think pcmanfm itself is a KDE application.

HOWEVER, I still don't know what the cure is.

DavidMcCann 06-06-2018 10:34 AM

I think the answer just given at Stack Exchange is probably on the right track: Pcmanfm is passing the name as a url. There might be something in the Pcmanfm configuration files you can alter, or else there are just four options: use one of the two opening methods that work, add .txt to the file name so that the file type is clear (I'm not sure that would work), or remove the space.

@hydrurga
Do you not know the difference between "allowed" and "acceptable"?
Have you nothing better to do than to make silly comments about other peoples' posts?

Timothy Miller 06-06-2018 11:36 AM

Quote:

Originally Posted by DavidMcCann (Post 5864346)
I think the answer just given at Stack Exchange is probably on the right track: Pcmanfm is passing the name as a url. There might be something in the Pcmanfm configuration files you can alter, or else there are just four options: use one of the two opening methods that work, add .txt to the file name so that the file type is clear (I'm not sure that would work), or remove the space.

@hydrurga
Do you not know the difference between "allowed" and "acceptable"?
Have you nothing better to do than to make silly comments about other peoples' posts?


I'm betting this is correct. %20 is the url code for a space, so passing the directory as a URL not as a straight directory would definitely cause this behavior.

winger9 06-08-2018 02:36 PM

Solved!
 
I've found the cure!

I'm using the LXDE desktop environment, and did the following to fix the
problem.

Select the KMenu icon at the left end of the Desktop Panel at the bottom of the
screen. Select Accessories/MainMenu. When the MainMenu application appears,
click on Accessories in the left box, then click on Kate in the middle box, then
click on Properties at the right.

In the "Command" box, replace "kate -b %U" with "kate -b".

When I now double-click a text file in pcmanfm, Kate correctly opens the file,
ie spaces aren't replaced with %20.

I don't have much knowlegde of the percent parameters (like %U), but I've a
feeling that %U might mean "Treat the argument supplied to Kate as a URL" (not
as a normal file).

Thanks very much for the help that you've all given.

hydrurga 06-08-2018 04:26 PM

Nice one!

Here is a list of the parameter options recommended in the freedesktop.org standard (half-way down the page).

https://standards.freedesktop.org/de...ec-latest.html

You will notice that %U allows multiple files to be passed to the target application (e.g. you could highlight several files and then open them all in Kate). So, a better bet might be to replace the %U by %F.

Try this out and let us know how it goes.


All times are GMT -5. The time now is 06:18 AM.