GithubHelp home page GithubHelp logo

indianboy42 / yabs.nvim Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pianocomposer321/yabs.nvim

0.0 2.0 0.0 383 KB

Yet Another Build System for Neovim, written in lua

License: GNU Affero General Public License v3.0

Lua 100.00%

yabs.nvim's Introduction

yabs.nvim

Yet Another Build System for Neovim, written in lua.

About

yabs.nvim adds vscode-like tasks feature to neovim. It allows you to specify specific commands that are associated with certain filetypes (or whole projects), as well as where the output for those commands should go, and run them with a keybinding. For example, for a python file you could have a run task that runs python3 % in the terminal; for rust you could have a build task and a run task that run cargo build, sending the output to the quickfix list, and cargo run, sending the output to the terminal, respectively; and for javascript, you could have a task to start the frontend server, one to start the backend server, and one to run tests.

Installation

Packer.nvim:

use 'pianocomposer321/yabs.nvim'

vim-plug:

Plug 'pianocomposer321/yabs.nvim'

etc.

Setup

require("yabs"):setup {
    languages = {  -- List of languages in vim `filetype` format
        lua = {
            tasks = {
                run = {
                    command = "luafile %",  -- The cammand to run (% and other
                                            -- wildcards will be automatically
                                            -- expanded)
                    type = "vim"  -- The type of command (can be `vim`, `lua`, or
                                  -- `shell`, default `shell`)
                }
            }
        },
        c = {
            default_task = "build_and_run",
            tasks = {
                build = {
                    command = "gcc main.c -o main",
                    output = "quickfix",  -- Where to show output of the
                                          -- command can be `buffer`,
                                          -- `consolation`, `echo`,
                                          -- `quickfix`, `terminal`, or `none`
                    opts = {  -- Options for output (currently, the only one
                              -- is `open_on_run`, which defines the behavior
                              -- for the quickfix list opening) (can be
                              -- `never`, `always`, or `auto`, the default)
                        open_on_run = "always"
                    }
                },
                run = {  -- You can specify as many tasks as you want per
                         -- filetype
                    command = "./main",
                    output = "consolation"
                },
                build_and_run = {  -- Setting the type to lua means the command
                                   -- is a lua function
                    command = function()
                        -- The following api can be used to run a task when a
                        -- previous one finishes
                        -- WARNING: this api is experimental and subject to
                        -- changes
                        require("yabs"):run_task("build", {on_exit = function()
                            require("yabs").languages.c:run_task("run")
                        end})
                    end,
                    type = "lua"
                }
            }
        }
    },
    tasks = {  -- Same values as `language.tasks`, but global
        build = {
            command = "echo building project...",
            output = "consolation"
        },
        run = {
            command = "echo running project..",
            output = "echo"
        }
    },
    opts = {  -- Same values as `language.opts`
        output_types = {
            quickfix = {
                open_on_run = "always"
            }
        }
    }
}

Usage

local yabs = require("yabs")

-- runs the task `build` for the current language, falling back to a global
-- task with that name if it is not found for the current language
yabs:run_task("build")  

-- runs the tasks that is specified as the default (see configuration section
-- above), or the first one if not specified
yabs:run_default_task()

-- Run command `echo hello, world` directly. Output is specified by the second
-- argument (same possible values as `output` option for tasks above), and
-- additional arguments are spcified with the third argument (same as
-- `task.opts` above)
yabs.run_command("echo hello, world", "quickfix", {open_on_run = "always"})

".yabs" files

The first time you run yabs:run_task(), yabs will look for a file named .yabs in the current working directory. If found, it will be sourced as a lua file. This is useful for project-local configurations.

Telescope integration

You can execute tasks from Telescope by running :Telescope yabs tasks / :Telescope yabs current_language_tasks or :Telescope yabs global_tasks.

Advanced configuration

The language.command option in yabs:setup() can be a string or a function that returns a string. Specifying a function instead can be useful for more advanced commands.

Likewise, the language.output option can be one of the included types (buffer, consolation, echo, quickfix, terminal, or none), or a function accepting one argumet - the command to run. For example, if you are using tmux, you could write a function to send the command to a tmux pane.

Chaining tasks

You can set a task to run when a previous one finishes by setting the on_exit value of the opts table in yabs:run_task(). This api is experimental and subject to change, and is not recommended to be used in normal configurations.

Screenshots

Buffer

buffer

Echo

echo

Quickfix

quickfix

Terminal

termina

yabs.nvim's People

Contributors

pianocomposer321 avatar shatur avatar

Watchers

James Cloos avatar  avatar

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.