selecting a syntax by the file's first line

Benno Schulenberg <[email protected]> Sat, 1 Aug 2020 19:40:59 +0200
Newsgroups gmane.editors.nano.general
Message-ID <[email protected]>
Hello Sébastien,

>> When nano does not apply the correct syntax to a file, one could do either:
>> 2) add or modify the first line so that nano recognizes it,
> 
> I am quite interested by this: most often, my Perl scripts do not have a name
> that ends in .pl so the following lines in my ~/.nanorc do not apply:
>     syntax perl "\.(html|mas|pl)$"
>     comment "#"
>     color brightblack "#.*"
> 
> Could you give an example of how I could tell Nano that files starting with
> #!/usr/bin/perl are to use some syntax-hilighting scheme? A pointer to the
> relevant part of the Doc would be just as good :-)

Open 'info nano' or 'man nanorc' and search for "header" (without the quotes).

Or simply do:  grep header syntax/perl.nanorc

You can make the header line more specific, if you like.  For example:

  header "^#!(/usr)?/bin/perl$"


Note, though, that if your file name matches any of the file regexes in
your nanorc files, that thát match takes precedence.

Regards,

Benno
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEv9AJBh5TUFKtDfIVDSjU0qCs6IQFAl8lqSsACgkQDSjU0qCs
6IT4WA//aySmo5eT1yiXc5D0Sj2fkfBSdLeY8GCHNrufvAmROuM3o28IGwaPU6gi
eBPFkFST9t0+GBP170/IbT0a9KwwxFA17HaALiNk+RwM8utxp0MIja5qVhQGxigi
eR/J9MD6o/BOIcsoib0XjNrFDgbjR+lkrui1L3a68OUk11fOJWuVwiHW26m3cuH+
jBX38DQPw9JFGo93VhuDaZLIRXMcvW+9uO0ytxcGSMbf+uzxpvPHsWoiEyHK5NTb
MKf0mMCaX4lI+UbeGbEVE/9EAQT13SzzYRyuOaOUbEWy+3zCdB1jwBnQKKGuUguK
Vo1+VsHObDpeBNOOYA6P8IGCVjwJzCdiBvuEr1JWJxiO0IV5tXquO+hWxw3BKdUm
Nm2ESWeYPKshEmNMIVMHrchoQrfPs5LB3J9QxS/D8Xgk8Co2jBJROrr8gQtwlAI1
EWRYTU+b+LqobyBhDpgoUuz2YHJ5opZNM+GbygJhPdxQx4gwWziVs2nk4Bm0Pyp7
5lDtBvGuCrL9WJsyWFgzR6fNWuL+TMSuOPpA/UzCr1eMwcwYdwjZ3qe/5cqURp2u
N7/L3mYKJsQGtCI36DKiJSrOSY4UbiRyOsZUzxIRk1Q4Le4p++xL0tth/G376wFe
Y4h2y5LElLum2oAK7dendSR9bxaFPCUN2/C5pP+MZVA9zAqkoo8=
=1kg7
-----END PGP SIGNATURE-----