mirror of
https://github.com/notwa/rc
synced 2025-02-05 07:43:22 -08:00
improve shebang detection with regex
This commit is contained in:
parent
d7089c2ff4
commit
ba907e97fa
1 changed files with 3 additions and 7 deletions
10
home/vimrc
10
home/vimrc
|
@ -176,13 +176,9 @@ fu! DetectShebang()
|
||||||
" vim has some rudimentary detection, but sometimes i want to override it.
|
" vim has some rudimentary detection, but sometimes i want to override it.
|
||||||
" vim's version is typically found here: /usr/share/vim/vim82/scripts.vim
|
" vim's version is typically found here: /usr/share/vim/vim82/scripts.vim
|
||||||
let l = getline(1)
|
let l = getline(1)
|
||||||
let p = ''
|
if l[:1] !=# '#!' | return | endif
|
||||||
|
let l = trim(l[2:], ' ', 1) " sometimes there are spaces after the #!
|
||||||
if l =~# '^#!/usr/bin/env -S ' | let p = get(split(l, ' '), 2)
|
let p = matchstr(l, '^\%(/usr\)\=/s\=bin/\%(env\%( \+-S\)\= \+\)\=\zs[^ ]*\ze')
|
||||||
elseif l =~# '^#!/usr/bin/env ' | let p = get(split(l, ' '), 1)
|
|
||||||
elseif l =~# '^#!/usr/bin/.' | let p = get(split(l, '/'), 3)
|
|
||||||
elseif l =~# '^#!/s\?bin/.' | let p = get(split(l, '/'), 2)
|
|
||||||
endif
|
|
||||||
|
|
||||||
if p ==# 'bash' | setlocal ft=bash | endif
|
if p ==# 'bash' | setlocal ft=bash | endif
|
||||||
if p ==# 'dash' | setlocal ft=bash | endif
|
if p ==# 'dash' | setlocal ft=bash | endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue