├── .travis.yml ├── circle.yml ├── plugin └── shebang.vim ├── LICENSE ├── README.md ├── doc └── vim-shebang.txt └── autoload └── shebang.vim /.travis.yml: -------------------------------------------------------------------------------- 1 | language: sh 2 | 3 | install: sudo pip install vim-vint 4 | 5 | script: vint . 6 | -------------------------------------------------------------------------------- /circle.yml: -------------------------------------------------------------------------------- 1 | dependencies: 2 | pre: 3 | - sudo pip install vim-vint 4 | 5 | test: 6 | override: 7 | - vint . 8 | -------------------------------------------------------------------------------- /plugin/shebang.vim: -------------------------------------------------------------------------------- 1 | command! -bang -nargs=* ShebangInsert let s:view = winsaveview() | 2 | \ call g:shebang#CommandShebang(0, ) | 3 | \ call winrestview(s:view) 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016, Steve Dignam 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vim-shebang [![Build Status](https://travis-ci.org/sbdchd/vim-shebang.svg?branch=master)](https://travis-ci.org/sbdchd/vim-shebang) [![Circle CI](https://circleci.com/gh/sbdchd/vim-shebang.svg?style=svg)](https://circleci.com/gh/sbdchd/vim-shebang) [![Build Status](https://drone.io/github.com/sbdchd/vim-shebang/status.png)](https://drone.io/github.com/sbdchd/vim-shebang/latest) 2 | 3 | A simple plugin to insert the correct shebang of the file. 4 | 5 | ## Install 6 | 7 | [vim-plug](https://github.com/junegunn/vim-plug) 8 | 9 | ```viml 10 | Plug 'sbdchd/vim-shebang' 11 | ``` 12 | 13 | ## Usage 14 | 15 | Run the command `:ShebangInsert` or use an autocmd e.g., `au! BufNewFile * ShebangInsert`. 16 | 17 | Normally, `:ShebangInsert` will not overwrite an existing shebang. 18 | By calling the command with a bang, `:ShebangInsert!`, any existing shebang 19 | will be overwritten. 20 | 21 | Additionally, a shebang can be specified by passing a name/filetype to `:ShebangInsert`. 22 | 23 | ```viml 24 | :ShebangInsert python 25 | ``` 26 | 27 | or 28 | 29 | ```viml 30 | :ShebangInsert node 31 | ``` 32 | 33 | You can also directly pass your desired shebang to the function. 34 | 35 | ```viml 36 | :ShebangInsert #!/bin/sh 37 | ``` 38 | 39 | ## Config 40 | 41 | To add/change/remove a shebang and filetype, simple create the dictionary `g:shebang#shebangs` 42 | in your `.vimrc`. 43 | 44 | ```viml 45 | let g:shebang#shebangs = { 46 | \ 'python': '#!/bin/python', 47 | \ 'sh': '', 48 | \ 'newfiletype': '#!/bin/newshebang' 49 | \ } 50 | ``` 51 | 52 | ## Supported Filetypes 53 | 54 | - Applescript 55 | - Bash 56 | - Erlang (Escript) 57 | - Fish 58 | - Lua 59 | - Node 60 | - Perl 61 | - PHP 62 | - Python 63 | - Ruby 64 | - Sh 65 | - Zsh 66 | -------------------------------------------------------------------------------- /doc/vim-shebang.txt: -------------------------------------------------------------------------------- 1 | *vim-shebang.txt* A simple plugin to insert the correct shebang of the file. 2 | 3 | Version: 0.1 4 | 5 | CONTENTS *vim-shebang-contents* 6 | 7 | Introduction |vim-shebang-introduction| 8 | Install |vim-shebang-install| 9 | Usage |vim-shebang-usage| 10 | Configuration |vim-shebang-configuration| 11 | Supported Filetypes |vim-shebang-supported-filetypes| 12 | 13 | ============================================================================== 14 | INTRODUCTION *vim-shebang-introduction* 15 | 16 | *vim-shebang* is a simple plugin to insert the correct shebang of the file. 17 | 18 | ============================================================================== 19 | INSTALL *vim-shebang-install* 20 | 21 | Install with [vim-plug](https://github.com/junegunn/vim-plug) 22 | > 23 | Plug 'sbdchd/vim-shebang' 24 | < 25 | ============================================================================== 26 | USAGE *vim-shebang-usage* *Run* 27 | 28 | Run the command `:ShebangInsert` or use an autocmd e.g., `au! BufNewFile * ShebangInsert`. 29 | 30 | Normally, `:ShebangInsert` will not overwrite an existing shebang. 31 | By calling the command with a bang, `:ShebangInsert!`, any existing shebang 32 | will be overwritten. 33 | 34 | Additionally, a shebang can be specified by passing a name/filetype to `:ShebangInsert`. 35 | > 36 | :ShebangInsert python 37 | < 38 | or 39 | > 40 | :ShebangInsert node 41 | < 42 | You can also directly pass your desired shebang to the function. 43 | > 44 | :ShebangInsert #!/bin/sh 45 | < 46 | ============================================================================== 47 | CONFIGURATION *vim-shebang-configuration* 48 | 49 | To add/change/remove a shebang and filetype, simple create the dictionary `g:shebang#shebangs` 50 | in your `.vimrc`. 51 | 52 | > 53 | let g:shebang#shebangs = { 54 | \ 'python': '#!/bin/python', 55 | \ 'sh': '', 56 | \ 'newfiletype': '#!/bin/newshebang' 57 | \ } 58 | < 59 | 60 | ============================================================================== 61 | SUPPORTED FILETYPES *vim-shebang-supported-filetypes* 62 | 63 | - Applescript 64 | - Bash 65 | - Erlang (Escript) 66 | - Fish 67 | - Lua 68 | - Node 69 | - Perl 70 | - PHP 71 | - Python 72 | - Ruby 73 | - Sh 74 | - Zsh 75 | 76 | ============================================================================== 77 | vim:tw=78:ts=8:ft=help:norl:noet:fen:noet: 78 | -------------------------------------------------------------------------------- /autoload/shebang.vim: -------------------------------------------------------------------------------- 1 | let s:shebangs_local = { 2 | \ 'applescript': '#!/usr/bin/env osascript', 3 | \ 'bash': '#!/usr/bin/env bash', 4 | \ 'erlang': '#!/usr/bin/env escript', 5 | \ 'fish': '#!/usr/bin/env fish', 6 | \ 'lua': '#!/usr/bin/env lua', 7 | \ 'node': '#!/usr/bin/env node', 8 | \ 'perl': '#!/usr/bin/env perl', 9 | \ 'php': '#!/usr/bin/env php', 10 | \ 'py2': '#!/usr/bin/env python2', 11 | \ 'py3': '#!/usr/bin/env python3', 12 | \ 'python': '#!/usr/bin/env python', 13 | \ 'python2': '#!/usr/bin/env python2', 14 | \ 'python3': '#!/usr/bin/env python3', 15 | \ 'ruby': '#!/usr/bin/env ruby', 16 | \ 'sh': '#!/usr/bin/env sh', 17 | \ 'zsh': '#!/usr/bin/env zsh', 18 | \ } 19 | 20 | if exists('g:shebang#shebangs') 21 | "override/add specified shebangs with defaults 22 | call extend(g:shebang#shebangs, s:shebangs_local, 'keep') 23 | else 24 | let g:shebang#shebangs = s:shebangs_local 25 | endif 26 | 27 | function! g:shebang#InsertShebang(shebang) abort 28 | if a:shebang !=? '' 29 | 0put = a:shebang 30 | echom 'Shebang: inserted' a:shebang 'shebang' 31 | endif 32 | endfunction 33 | 34 | function! g:shebang#CheckShebang(...) abort 35 | "check to see that there are arguments 36 | if a:000 !=? [''] 37 | let l:argument = a:1 38 | else 39 | let l:argument = &filetype 40 | endif 41 | if l:argument =~# '#!.*' 42 | call g:shebang#InsertShebang(l:argument) 43 | return 0 44 | endif 45 | 46 | "see if specified shebang is defined in shebangs dict 47 | if has_key(g:shebang#shebangs, l:argument) 48 | call g:shebang#InsertShebang(g:shebang#shebangs[l:argument]) 49 | return 0 50 | else 51 | return 1 52 | endif 53 | endfunction 54 | 55 | function! g:shebang#CommandShebang(bang, ...) abort 56 | let l:vargs = join(a:000) 57 | if getline(1) =~? '#!.*' && a:bang 58 | if !g:shebang#CheckShebang(l:vargs) | 2delete _ | endif 59 | "check that the first line isn't a shebang 60 | elseif getline(1) !~? '#!.*' 61 | call g:shebang#CheckShebang(l:vargs) 62 | else 63 | echom 'Shebang: a shebang already exists.' 64 | endif 65 | endfunction 66 | --------------------------------------------------------------------------------