You are not logged in.

#1 2023-11-09 12:12:20

jerryDaBaaws
Member
Registered: 2020-06-08
Posts: 115

csv file opening as txt via xdg-open

So I am creating a csv file using df.to_csv pandas function.
when I open it using xdg-open it is opening via vscode.
On checking further , via xdg-mime query filetype file.csv it is giving me , text/plain which is set to be opened via vscodium only.
In mimeapps.list  text/csv is set to be opened via libreoffice which works if i opens it via nautilus. libreoffice-calc is also set to open csv file by default in nautilus.

any idea how to make xdg-open recognise csv file as csv instead of plain text using arch/sway if it is relevant

Offline

#2 2023-11-09 12:44:13

Hanabishi
Member
Registered: 2020-08-07
Posts: 46

Re: csv file opening as txt via xdg-open

Do you have shared-mime-info installed?
If so, check /usr/share/mime/text/csv.xml is present (it is not part of the package, but should be autogenerated upon installation).

Last edited by Hanabishi (2023-11-09 12:50:53)

Offline

#3 2023-11-09 14:31:48

jerryDaBaaws
Member
Registered: 2020-06-08
Posts: 115

Re: csv file opening as txt via xdg-open

yes it is installed and file exists as well

<?xml version="1.0" encoding="utf-8"?>
<mime-type xmlns="http://www.freedesktop.org/standards/shared-mime-info" type="text/csv">
  <!--Created automatically by update-mime-database. DO NOT EDIT!-->
  <comment>CSV document</comment>
  <comment xml:lang="zh_TW">CSV 文件</comment>
  <comment xml:lang="zh_CN">CSV 文档</comment>
  <comment xml:lang="vi">Tài liệu CSV</comment>
  <comment xml:lang="uk">документ CSV</comment>
  <comment xml:lang="tr">CSV belgesi</comment>
  <comment xml:lang="sv">CSV-dokument</comment>
  <comment xml:lang="sr">ЦСВ документ</comment>
  <comment xml:lang="sq">dokument CSV</comment>
  <comment xml:lang="sl">Dokument CSV</comment>
  <comment xml:lang="si">CSV ලේඛනය</comment>
  <comment xml:lang="sk">Dokument CSV</comment>
  <comment xml:lang="ru">Документ CSV</comment>
  <comment xml:lang="ro">Document CSV</comment>
  <comment xml:lang="pt_BR">Documento CSV</comment>
  <comment xml:lang="pt">documento CSV</comment>
  <comment xml:lang="pl">Dokument CSV</comment>
  <comment xml:lang="oc">document CSV</comment>
  <comment xml:lang="nn">CSV-dokument</comment>
  <comment xml:lang="nl">CSV-document</comment>
  <comment xml:lang="nb">CSV-dokument</comment>
  <comment xml:lang="lv">CSV dokuments</comment>
  <comment xml:lang="lt">CSV dokumentas</comment>
  <comment xml:lang="ko">CSV 문서</comment>
  <comment xml:lang="kk">CSV құжаты</comment>
  <comment xml:lang="ka">CSV დოკუმენტი</comment>
  <comment xml:lang="ja">CSV ドキュメント</comment>
  <comment xml:lang="it">Documento CSV</comment>
  <comment xml:lang="is">CSV skjal</comment>
  <comment xml:lang="id">Dokumen CSV</comment>
  <comment xml:lang="ia">Documento CSV</comment>
  <comment xml:lang="hu">CSV dokumentum</comment>
  <comment xml:lang="hr">CSV dokument</comment>
  <comment xml:lang="he">מסמך CSV</comment>
  <comment xml:lang="gl">documento CSV</comment>
  <comment xml:lang="ga">cáipéis CSV</comment>
  <comment xml:lang="fur">document CSV</comment>
  <comment xml:lang="fr">document CSV</comment>
  <comment xml:lang="fo">CSV skjal</comment>
  <comment xml:lang="fi">CSV-asiakirja</comment>
  <comment xml:lang="eu">CSV dokumentua</comment>
  <comment xml:lang="es">documento CSV</comment>
  <comment xml:lang="eo">CSV-dokumento</comment>
  <comment xml:lang="en_GB">CSV document</comment>
  <comment xml:lang="el">Έγγραφο CSV</comment>
  <comment xml:lang="de">CSV-Dokument</comment>
  <comment xml:lang="da">CSV-dokument</comment>
  <comment xml:lang="cs">dokument CSV</comment>
  <comment xml:lang="ca">document CSV</comment>
  <comment xml:lang="bg">Документ — CSV</comment>
  <comment xml:lang="be@latin">Dakument CSV</comment>
  <comment xml:lang="be">дакумент CSV</comment>
  <comment xml:lang="ast">Documentu CVS</comment>
  <comment xml:lang="ar">مستند CSV</comment>
  <comment xml:lang="af">CSV-dokument</comment>
  <acronym>CSV</acronym>
  <expanded-acronym>Comma Separated Values</expanded-acronym>
  <alias type="text/x-comma-separated-values"/>
  <alias type="text/x-csv"/>
  <sub-class-of type="text/plain"/>
  <glob pattern="*.csv"/>
</mime-type>

Offline

#4 2023-11-09 14:35:24

jerryDaBaaws
Member
Registered: 2020-06-08
Posts: 115

Re: csv file opening as txt via xdg-open

another thing is that if i open file via libreoffice, and save it without doing any modification, now the output of
xdg-mime query filetype file.csv is text/csv instead

Last edited by jerryDaBaaws (2023-11-09 14:35:41)

Offline

#5 2023-11-09 14:44:58

Hanabishi
Member
Registered: 2020-08-07
Posts: 46

Re: csv file opening as txt via xdg-open

For me even completely empty (0 bytes) file gives the right mime type.

$ file file.csv
file.csv: empty

$ xdg-mime query filetype file.csv
text/csv

Afaik there is no magic value to identify csv by content. So it is only about the file extension.

Offline

#6 2023-11-09 15:19:59

jerryDaBaaws
Member
Registered: 2020-06-08
Posts: 115

Re: csv file opening as txt via xdg-open

but in my case  xdg-mime query  is giving 2 separate values for 2 files with .csv extension.
libreoffice-calc has to be adding some extra metadata while saving file as csv

Offline

#7 2023-11-09 15:38:11

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,065

Re: csv file opening as txt via xdg-open

◉ touch /tmp/foo.csv
◉ xdg-mime query filetype /tmp/foo.csv                    
inode/x-empty

Even adding some CSB (text/plain) or explcitly adding *.csv to ~/.local/share/mime/globs and running "update-mime-database ~/.local/share/mime" didn't change anything about that.

@jerryDaBaaws can you upload the files (or functionally equivalent dummies)?

Offline

#8 2023-11-10 03:17:06

jerryDaBaaws
Member
Registered: 2020-06-08
Posts: 115

Re: csv file opening as txt via xdg-open

https://file.io/FargAL49ETKz
sure , here you go

Offline

#9 2023-11-10 07:45:58

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,065

Re: csv file opening as txt via xdg-open

Deleted
The transfer you requested has been deleted.

Offline

#10 2023-11-10 09:38:00

jerryDaBaaws
Member
Registered: 2020-06-08
Posts: 115

Re: csv file opening as txt via xdg-open

my bad, uploaded them again
https://file.io/JrhcKTb1uIdZ

Offline

#11 2023-11-10 19:16:30

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,065

Re: csv file opening as txt via xdg-open

The significant difference would be the trailing newline, though both are still text/plain here (not that I particuarily care, just to mention)

Offline

#12 2023-11-13 12:30:38

jerryDaBaaws
Member
Registered: 2020-06-08
Posts: 115

Re: csv file opening as txt via xdg-open

> both are still text/plain here

on my system, one is text/plain. other is text/csv

and also i dont think newline should matter in context of mimetype

Offline

#13 2023-11-13 13:59:32

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,065

Re: csv file opening as txt via xdg-open

Did you test whether you can control the type w/ the trailing newline?

and also i dont think newline should matter in context of mimetype

Yes "should" …

Offline

Board footer

Powered by FluxBB