How do Thunar and MC decide how to open a file? - mime-types

It seems that Thunar and Midnight Commander (any maybe other tools) don't use Mailcap to decide how to open a file. What do they use instead?
Background of the question: On my system, Thunar and Midnight Commander open all ODT files with Okular instead of LibreOffice.
I tried to debug this by checking ~/.mailcap and /etc/mailcap, which do contain Okular rules for ODT, but the LibreOffice (soffice) rules clearly take precedence.
I verified this by running mailcap directly on an ODT file:
run-mailcap --norun /tmp/example.odt
The output is exactly what I expect:
soffice --nologo --writer '/tmp/example.odt'
Also, if I run that command, LibreOffice is indeed started and opens the file.
So to my understanding, MC and Thunar should open ODT files with LibreOffice. But they use Okular. Why?

To answer my own question, these applications use xdg-open instead of run-mailcap.
And indeed the following command runs Okular instead of LibreOffice:
Command:
xdg-open /tmp/example.odt
I can verify the assigned MIME type with:
Command:
xdg-mime query filetype /tmp/example.odt
Output:
application/vnd.oasis.opendocument.text
Then, I can check which application is assigned to that MIME type:
Command:
xdg-mime query default application/vnd.oasis.opendocument.text
Output:
kde4-okularApplication_ooo.desktop
This explains the issue. When I uninstall Okular, it leads to the correct response:
Output:
libreoffice-writer.desktop
So there's something wrong in either the Okular or the LibreOffice package.

Related

Windows BAT script for cp alias produces error

I wrote a file called cp.bat and the content of this file is: DOSKEY cp=COPY $* copy. I saved this file in c:\users\myname\aliases. I also added this path to my environment so cmd can execute it.
When I now type cp in my cmd the output is a strange character for the c in cp.
I need this script to work because I want to install chicken scheme eggs on my machine, but the chicken-install command executes multiple cp commands and those are not recognized in the cmd.
I also tried to alter the build script of the eggs, but it gets newly generated everytime I call the chicken-install command.
It would also help if someone could explain me how to install chicken eggs on a windows machine correctly. I feel this workaround shouldn't be necessary. Thanks in advance.
Like Magoo mentioned:
In all probability, your editor is the root of your problem. Batch files should be created in strict ANSI format using a text-editor, not a word-processor. Notepad is barely adequate; Notepad++ is far better - I use Editplus
The encoding was messed up and it was set to UTF-8-BOM, so I changed it to ANSI and it worked flawlessly.
If you're using CHICKEN 5, it should not be emitting cp commands; it should emit batch files which use the builtin Windows commands only if you're using the mingw platform target. Have you used the PLATFORM=mingw option with every make invocation?
If you're using the mingw-msys (or cygwin) platform, then it will be emitting UNIX style commands.

Find multiple files from the command line

Description:
I am searching a very large server for files that is on a different server. right now I open command prompt and type
DIR [FILE NAME] /S/4
This returns the server location of the file with some other stuff that is not really needed.
Question:
I have a lot of files to search and one by one input into the above command could take forever. Is there a way I could input all of the names of all the files and only search once and the search results would only need to show file name and location?
First, I hope you don't mean DOS, but rather Windows cmd or batch.
You can certainly write a script that will run your DIR command once per file being sought.
But what you most likely want instead is to search once and print the path of each file found. For this you can use PowerShell's FindChildItem or the improved one posted here: http://windows-powershell-scripts.blogspot.in/2009/08/unix-linux-find-equivalent-in.html
It will be something like:
Find-ChildItem -Name "firstfile.txt|secondfile.txt|..."
Another approach is to install msys or cygwin or another Linux tools environment for Windows and use the Linux find command.

Running a shell script through Cygwin on Windows

I have a bunch of shell scripts that used to run on a Linux machine. Now, we've switched over to Windows, and I need to run these scripts there. I have Cygwin installed, but is there a way to make the script run using Cygwin, but the call is made from Windows batch?
Sure. On my (pretty vanilla) Cygwin setup, bash is in c:\cygwin\bin so I can run a bash script (say testit.sh) from a Windows batch file using a command like:
C:\cygwin\bin\bash testit.sh
... which can be included in a .bat file as easily as it can be typed at the command line, and with the same effect.
One more thing - if You edited the shell script in some Windows text editor, which produces the \r\n line-endings, cygwin's bash wouldn't accept those \r. Just run dos2unix testit.sh before executing the script:
C:\cygwin\bin\dos2unix testit.sh
C:\cygwin\bin\bash testit.sh
If you have access to the Notepad++ editor on Windows there is a feature that allows you to easily get around this problem:
Open the file that's giving the error in Notepad++.
Go under the "Edit" Menu and choose "EOL Conversion"
There is an option there for "UNIX/OSX Format." Choose that option.
Re-save the file.
I did this and it solved my problems.
Hope this helps!
Read more at http://danieladeniji.wordpress.com/2013/03/07/microsoft-windows-cygwin-error-r-command-not-found/
Just wanted to add that you can do this to apply dos2unix fix for all files under a directory, as it saved me heaps of time when we had to 'fix' a bunch of our scripts.
find . -type f -exec dos2unix.exe {} \;
I'd do it as a comment to Roman's answer, but I don't have access to commenting yet.
The existing answers all seem to run this script in a DOS console window.
This may be acceptable, but for example means that colour codes (changing text colour) don't work but instead get printed out as they are:
there is no item "[032mGroovy[0m"
I found this solution some time ago, so I'm not sure whether mintty.exe is a standard Cygwin utility or whether you have to run the setup program to get it, but I run like this:
D:\apps\cygwin64\bin\mintty.exe -i /Cygwin-Terminal.ico bash.exe .\myShellScript.sh
... this causes the script to run in a Cygwin BASH console instead of a Windows DOS console.
If you don't mind always including .sh on the script file name, then you can keep the same script for Cygwin and Unix (Macbook).
To illustrate:
1. Always include .sh to your script file name, e.g., test1.sh
2. test1.sh looks like the following as an example:
#!/bin/bash
echo '$0 = ' $0
echo '$1 = ' $1
filepath=$1
3. On Windows with Cygwin, you type "test1.sh" to run
4. On a Unix, you also type "test1.sh" to run
Note: On Windows, you need to use the file explorer to do following once:
1. Open the file explorer
2. Right-click on a file with .sh extension, like test1.sh
3. Open with... -> Select sh.exe
After this, your Windows 10 remembers to execute all .sh files with sh.exe.
Note: Using this method, you do not need to prepend your script file name with bash to run

GNU style configure batch file issues

I'm trying to create a GNU like configure script for Windows in a batch file. It seems to work ok so far except depending on the order options get ignored and in particular with the '--with-smtube' option it sometimes gets the path but again depending on the order causes it to result in:
test.cmd --enable-portable --with-smtube=C:\svn\smtube
configure: error: unrecognized option: `C:\svn\smtube'
Try `--with-smtube --help' for more information
(supposed to also say Try `test.cmd --help)
I copied the structure from another script I found but not having success. The order of arguments shouldn't matter and arguments can be omitted (all or some). Can someone steer me in the right direction?
The script is for a Qt program, it uses command prompt as the shell and not msys or cygwin or anything like that.
This is what I have so far: http://redxii.users.sourceforge.net/test.cmd

How do I view or rename a file with missing extension?

I have a strange file in my file system without the extension part. The filename is "15.". The weird thing is that it is not one of those without the dot part (like just "15"), but the one with the dot but no extension ("15.") -- it is literally an illegal filename in windows, and not sure how did it get created in the first place.
I know it is a text file and it is about 15KB in size; however, due to the weirdness in name, I can't open it with any application -- I've tried to open in notepad, wordpad, etc., have tried the 'type' command to spit it out on commans shell, tried to shell-open enclosing filename in quotes, and so on -- all methods result in a 'file not found' error except the notepad, which says '15.txt' is not found.
Due to the nature of the issue and the way search engines optimize the search, it is extemely hard to search for an answer in any of the search engines online. So, I just wanted to put this question out there and see if anybody had to deal with a similar issue and have found any way to rename the file or even to change the extension.
Filenames that are valid in NTFS but cannot be used from Windows can be created when accesing disks or shares from other operating systems like Linux.
If you don't have a Linux installation at hand, then get hold of a "live" CD, boot Linux, and change the filename.
That may sound like a hassle, but Windows-only solutions (moving stuff around, deleting the directory) are even worse.
Use REN: http://ss64.com/nt/ren.html
It is a command prompt command (run > cmd > cd wherever > ren 15. 15.txt )

Resources