requirements.txt.vim icon indicating copy to clipboard operation
requirements.txt.vim copied to clipboard

[feature] How about detect shebang to set filetype?

Open Freed-Wu opened this issue 3 years ago • 6 comments

That is if a file's first line is

#!/usr/bin/env -S pip install -r

or

#!/usr/bin/env -S pip-compile

We set this file's filetype is requirements.

Thanks!

Freed-Wu avatar Oct 14 '22 09:10 Freed-Wu

Take a look at $VIMRUNTIME/autoload/dist/script.vim for reference on detecting filetypes based on first line.

benknoble avatar Oct 14 '22 13:10 benknoble

Interesting idea, But I don't have the practice of writing shebang on the first line of the requirements file. Would this be used often?

raimon49 avatar Oct 16 '22 10:10 raimon49

Would this be used often?

For Unix user, detect filetype by shebang should be some convention :smile:

Freed-Wu avatar Oct 16 '22 10:10 Freed-Wu

Disagree. Not everything needs to be an executable (hence not everything needs such a shebang line). But probably no harm in supporting it.

benknoble avatar Oct 16 '22 15:10 benknoble

Not everything needs to be an executable

Although I usually do this thing (add shebang for many program's input files: jq/sed/parallel/other programs which can accept a file) :smile:

probably no harm in supporting it.

Agree :smile:

Freed-Wu avatar Oct 16 '22 15:10 Freed-Wu

Take a look at $VIMRUNTIME/autoload/dist/script.vim for reference on detecting filetypes based on first line.

In neovim, it is $VIMRUNTIME/scripts.vim.

let s:line1 = getline(1)

if s:line1 =~# "^#!"
" ...

Freed-Wu avatar Oct 18 '22 14:10 Freed-Wu