GithubHelp home page GithubHelp logo

susensio / magic-bang.nvim Goto Github PK

View Code? Open in Web Editor NEW
7.0 1.0 2.0 30 KB

Neovim plugin written in pure Lua that automagically inserts a shebang line when needed

License: MIT License

Lua 100.00%
lua neovim nvim nvim-plugin shebang

magic-bang.nvim's Introduction

๐Ÿช„ #Magic Bang!

A simple Neovim plugin written in pure Lua that automagically inserts a shebang line when needed and makes the file executable.

How it works

sample

It checks if the current file is in $PATH and reads its extension to insert the corresponding shebang. If no extension is present, default shebang is used.

On exit, the file is made executable only if the shebang is still present.

:Bang command adds a shebang manually.

Installation

lazy with lazyloading

{
  "susensio/magic-bang.nvim",
  config = true,
  event = "BufNewFile",
  cmd = "Bang",
}
use {
    "susensio/magic-bang.nvim",
    config = function() require("magic-bang").setup() end
}
Plug "susensio/magic-bang.nvim"
lua require("magic-bang").setup()

Usage

If a new file is in $PATH, the :Bang command is fired automatically. A manual user command is provided :Bang [<binary>] with an optional binary argument, usefull when editing previously created files or source files without extension.

-- Try to set shebang based on extension, or insert default shebang
:Bang

-- Force specific shebang by declaring binary
:Bang python3

Customization

You can set custom shebangs or override defaults in setup with bins = { extension = binary }, using either a binary command (which will be resolved with /usr/bin/env) or a full path:

require("magic-bang").setup({
    bin = {
        ksh = "/usr/bin/ksh",
        py = "python3.11",
        scala = nil
    }
})

Default options are:

{
    bins = {
        awk = "awk",
        hs = "runhaskell",
        jl = "julia",
        lua = "lua",
        m = "octave",
        mak = "make",
        php = "php",
        pl = "perl",
        py = "python3",
        r = "Rscript",
        rb = "ruby",
        scala = "scala",
        sh = "bash",
        tcl = "tclsh",
        tk = "wish",
    },
    automatic = true,         -- insert shebang on new file when in $PATH
    command = true,           -- define Bang user command
    executable = true,        -- make file executable on exit
    default = "/bin/bash"     -- default shebang for `:Bang` without args
}

Acknowledgments

To samirettali for his shebang.nvim that inspired this pluggin.

FAQ

Q: How does it differ from forked samirettali/shebang.nvim?

A: First, it only makes a file executable if the shebang is still present on exit. This prevent false positives. Second, a :Bang user command can manually add a shebang, helping with false negatives.

magic-bang.nvim's People

Contributors

samirettali avatar susensio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

mgabs shreyas-a-s

magic-bang.nvim's Issues

Adding an option to allow automatic shebang even when current dir is not in $PATH

Hi, Nogueras. First of all, great plugin you have created. Works like a charm.

I would like the addition of an option with which even if current directory is not in $PATH, automatic shebang is applied.

Maybe something like modifying already existing variable automatic to have an extra value ignore_path would be possible I think.

I see that there is already a PR i.e. #1 by @mgabs but it only adds a new variable and nothing more as far as I can see.

I would love to contribute in adding this feature if you would like that and if the scope of this plugin allows such a feature. If not, then no problem at all.

Thanks for reading through my essay. Hoping to hear from you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.