I want geany to allow me to colorize files with this hashbang by default as sh.
```cs #!/bin/busybox ash ```
Detection from shebang is hard coded [here](https://github.com/geany/geany/blob/7d1b0ca805f1b830a9276ab48ceec2d8acb239de...)
I understand, the compilers don't work for me.
If possible, it would be nice if in the next version of Geany, the user adds their own shebangs with their respective language to the settings.
Sure, but "somebody" has to do it, pull requests are welcome (after discussion about how to do it)
Alternative and already working, you can add a header line to hint Geany what filetype to use:
```sh #!/bin/busybox ash # -*- Sh -*-
.... ``` It is roughly described in https://geany.org/manual/#various-preferences (search for "extract_filetype_regex").
FWIW, patching is likely as easy as this (untested): ```diff diff --git a/src/filetypes.c b/src/filetypes.c index b1913e368..f773f1a2b 100644 --- a/src/filetypes.c +++ b/src/filetypes.c @@ -632,6 +632,10 @@ static GeanyFiletype *find_shebang(const gchar *utf8_filename, const gchar *line { /* skip "env" and read the following interpreter */ basename_interpreter += 4; } + else if (g_str_has_prefix(tmp, "busybox ")) + { + basename_interpreter += 8; + }
for (i = 0; ! ft && i < G_N_ELEMENTS(intepreter_map); i++) { ```
@eht16 That serves me well.
I have another problem, I want file explorer to recognize the script as if it were a sh.
![Captura de pantalla(1)](https://github.com/geany/geany/assets/3245767/91fbe08d-8eb7-475d-86a2-00a766...)
![Captura de pantalla(2)](https://github.com/geany/geany/assets/3245767/51399288-e160-47de-a909-32d009...)
I am using PCManFM.
How do you do that? If it does not have an extension, and has the busybox ash hashbang, it will recognize it as sh.
I was now able to associate the busybox ash to the mime so that it looks good on PCManFM.
__/usr/share/mime/packages/freedesktop.org.xml__ ```sh <mime-type type="application/x-shellscript"> <comment>Shell script</comment> <comment xml:lang="uk">скрипт оболонки</comment> <comment xml:lang="sv">Skalskript</comment> <comment xml:lang="ru">Сценарий shell</comment> <comment xml:lang="pl">Skrypt powłoki</comment> <comment xml:lang="it">Script shell</comment> <comment xml:lang="eu">Shell scripta</comment> <comment xml:lang="es">secuencia de órdenes de consola</comment> <comment xml:lang="de">Shell-Skript</comment> <comment xml:lang="be">скрыпт абалонкі</comment> <sub-class-of type="application/x-executable"/> <sub-class-of type="text/plain"/> <alias type="text/x-sh"/> <generic-icon name="text-x-script"/> <magic> <match type="string" value="# This is a shell archive" offset="10"/> <match type="string" value="/bin/bash" offset="2:16"/> <match type="string" value="/bin/nawk" offset="2:16"/> <match type="string" value="/bin/zsh" offset="2:16"/> <match type="string" value="/bin/sh" offset="2:16"/> <match type="string" value="/bin/ksh" offset="2:16"/> <match type="string" value="/bin/dash" offset="2:16"/> <match type="string" value="/bin/env sh" offset="2:16"/> <match type="string" value="/bin/env bash" offset="2:16"/> <match type="string" value="/bin/env zsh" offset="2:16"/> <match type="string" value="/bin/env ksh" offset="2:16"/> <match type="string" value="/bin/busybox sh" offset="2:16"/> <match type="string" value="/bin/busybox ash" offset="2:16"/> </magic> <glob pattern="*.sh"/> </mime-type> ```
Mime update: ```sh update-mime-database /usr/share/mime ```
Another thing I would like is that when I enter `# -*- Sh -*-` and save the file, it automatically changes the colors.
Another thing I would like is that when I enter # -*- Sh -*- and save the file, it automatically changes the colors.
The filetype is scanned only when a file is first opened in a session, this is because the user can set filetype, and if Geany then changed it that would be disobeying user selection (which is generally not allowed). But therefore you can set the filetype for the rest of the session manually `Document->Set Filetype->...`.
The user's selection does not last long, because when closing the file and reopening it, the original language returns. If so, Geany would have to save a database with the chosen language for each file.
Now I have another problem with the status bar, there is too much space between each text, and it doesn't let me see what type of file I am choosing.
![Captura de pantalla(3)](https://github.com/geany/geany/assets/3245767/8abdef73-a883-4dec-9dda-4918fb...)
If possible I would like the texts to be more compact.
By the way, I just realized that `/bin` is not necessary, because the busybox can be in the root folder `/busybox ash` and the program still works..
The mime would remain like this. ```sh <match type="string" value="/bash" offset="2:16"/> <match type="string" value="/nawk" offset="2:16"/> <match type="string" value="/zsh" offset="2:16"/> <match type="string" value="/sh" offset="2:16"/> <match type="string" value="/ksh" offset="2:16"/> <match type="string" value="/dash" offset="2:16"/> <match type="string" value="/env sh" offset="2:16"/> <match type="string" value="/env bash" offset="2:16"/> <match type="string" value="/env zsh" offset="2:16"/> <match type="string" value="/env ksh" offset="2:16"/> <match type="string" value="/busybox sh" offset="2:16"/> <match type="string" value="/busybox ash" offset="2:16"/> ```
An idea occurred to me, now that I have updated the Mime, that Geany decides the language by reading from the Mime, just as the file explorer does, if it is `application/x-shellscript`, that the language be `Sh`.
To know the Mime, do it like this: ```rb xdg-mime query filetype /init application/x-shellscript ```
The user's selection does not last long, because when closing the file and reopening it, the original language returns. If so, Geany would have to save a database with the chosen language for each file.
It lasts for the _session_ which as you point out is until its closed, note that the session persists across Geany shutdowns and restarts and so does the set filetype.
that Geany decides the language by reading from the Mime
Geany does not use the system mime types and associated "majik" because it is not accurate enough for many filetypes. It is ok when generating the wrong icon on the file manager, that is hardly the end of the world, but its seriously annoying when it happens to an IDE filetype as you have found.
I don't know in which cases it could be imprecise, but even if it becomes imprecise, it would be more precise for it to be an sh instead of no language, at least in my case, I mention that I am trying to make an initrd with Busybox.
I would like that in case it does not detect any type of file with the shebang, that it use the Mime as a final alternative. If the Mime is `text/plain`, it must not be from any language.
Its not that simple, the process is:
1. read shebang, finds various shells, perl, python, php, ruby, tcl, make, D, js, rust 2. detect HTMLy prefix, eg `<html`, but not if the file extension is perl, python, or php. 3. detect XML prefix, but not if the file extension is html, docbook, perl, php, or python 4. detect PHP prefix 5. attempt to read the filetype out of the file using the regex at `Edit->Preferences->Various->files.extract_filetype_regex` (the default regex is what detects the `-*- Sh -*-` but users can modify or add to it) 6. detect from extension using `filetypes.extensions`
Not much is left for mime, but if "somebody" made a well written PR that used the GIO interface to get mime type and a configuration file that maps mimetype to Geany filetype it might be accepted.
The problems with mimetypes that I know of are they can't distinguish .h files as C or C++, and of course C++ system headers have no extension, so file managers show them as C, not C++. But its important to open these as the right filetype to get keyword highlighting and symbol parsing to work right. There are probably others.
Closed #3884 as completed via #4016.
github-comments@lists.geany.org