I think bash is tripping over some anomalies in how accented characters are handled. You might want to grab some popcorn, because this is going to get technical for a little bit...
Unicode allows some accented characters to be represented in several different ways: as a "code point" representing the accented character, or as a series of code points representing the unaccented version of the character, followed by the accent(s). For example, "ä" could be represented either precomposed as U+00E4 (UTF-8 0xc3a4, Latin small letter 1 with diaeresis) or decomposed as U+0061 U+0308 (UTF-8 0x61cc88, Latin small letter a + combining diaeresis).
OS X's HFS+ filesystem requires that all filenames be stored in the UTF-8 representation of their fully decomposed form. In an HFS+ filename, "ä" MUST be encoded as 0x61cc88, and "ö" MUST be encoded as 0x6fcc88.
I'm pretty sure what's happening here is that when you type "Näyttökuva.png" at the command line, it's "typing" the characters in precomposed form. When the file is created, the filesystem decomposes the characters for storage. Everything is fine so far. But when you try to use tab-completion starting with "Nä", I think bash is failing to decompose the "ä" before searching for matches, and of course it doesn't find any.
To illustrate the difference, here's an example of what encoding is used when I just type "Näyttökuva.png" at the command line, vs. what's used when I store it as a filename and use tab completion to fill it in:
$ printf Näyttökuva.png | xxd # This time I pasted the it in from this web page
0000000: 4ec3 a479 7474 c3b6 6b75 7661 2e70 6e67 N..ytt..kuva.png
$ touch Näyttökuva.png # Also pasted from the web
$ printf Näyttökuva.png | xxd # This time I tab-completed it after N
0000000: 4e61 cc88 7974 746f cc88 6b75 7661 2e70 Na..ytto..kuva.p
0000010: 6e67 ng
Now, as for the matter of characters getting lost when deleting and re-tab-completing, I suspect that's closely related. Specifically, I think bash is "deleting" one code point per press of the delete key, but erasing one character from the Terminal window per press. Because one of the deleted characters ("ö" this time) consisted of two code points, but only one character, the Terminal display gets out of sync. Try tab-completing the whole filename, deleting it back to "Näytt", then re-tab-completing: bash seems to think that only the combining diaeresis was deleted, not the entire "ö", so it re-adds the combining diaeresis, but it this time it attaches to the "t":
$ echo Näytẗkuva.png
Näyttökuva.png
Note that when I press return, bash actually has the entire filename there; it's just the Terminal display that was confused.
TL;DR bash has some bugs handling decomposable accented characters.
EDIT: after some mulling, I think the only full solution is to fix bash (/wait for its developers to fix it). There might also be a way to input characters in decomposed form, but I have no idea what that would be. But I did find some partial workarounds:
Drag-and-droping a file from the Finder pastes in its correct form. Since the Finder gets the filename from the filesystem, it's already decomposed, so it just works.
You can actually tab-complete the accented character itself. For example, if you type "Na" and then tab, it'll match "Näyttökuva.png" because the canonical decomposition of "ä" starts with "a". But if you have a file named "Narwal.gif" in the same directory, that won't be very helpful...
I haven't tested this, but if you bind tab to menu-complete instead of complete, it should let you tab through possible matches so you can select the one you want even if you can't type the next letter. (Or you could bind it to a different keystroke, so you can use it only when you need to.)
For fixing the problem with the Terminal display getting out of sync, you could bind something to redraw-current-line -- it won't prevent the problem from happening, but it'll give you a way to resynchronize the display.
Best Answer
My primary OS is OS X, however I do have a Linux Mint system I use and run into similar situations in which I want to do the same thing on both systems, and when it's not directly supported I have to find another way. In a case such as this, if there wasn't a Browser Extension for
.desktop
files, like in your other question about.url
files, here is what I'd do.I'd convert the
.desktop
files to.webloc
files and or.url
files and use the Default Apps Preference Pane, RCDefaultApp by Rubicode, to change which application opens any given file extension.Here's a bash script, that I modified from a similar script I wrote years ago, which will create
.webloc
files and or.url
files from.desktop
files that have URLs in them.cd
to the directory containing the.desktop
files.Issues the following commands:
touch d2wu
open d2wu
Copy and paste the code below into the opened
d2wu
file.Save and close the
d2wu
file.Make
d2wu
executable:chmod u+x d2wu
Execute
d2wu
:./d2wu
Example script output:
Note: You can use the Default Apps Preference Pane, RCDefaultApp by Rubicode, to change which application opens a given file extension.
Also, if you need modify other default methods of file types, Apps, URLs, UTIs, etc. the the Default Apps Preference Pane is a great utility for it.
Note: As coded it will not overwrite existing
.webloc
files and or.url
files even thought when selecting 1, 2 or 3, it reports "Creating ... files.". This was done to both not step on existing files and minimize output to the screen while only outputting which.desktop
files do not contain aURL=...
line, as can be the case depending on what type of.desktop
file it is.