Home

Awesome

termnames.nvim

A simple plugin that adds names to terminals

demo image

Note

termnames.nvim is a work is progress. There might be several bugs and a few quirks. If you find a bug, feel free to open an issue and if you find a fix, please open a pull request.

termnames.nvim works seamlessly with my config but you might have a few problems with yours. For the plugin to perform perfectly, it is required for TermSave or save_terminal_data() to run before mksession. termnames.nvim also needs TermRefresh or update_term_bufnr() to run after loading a session or a new working directory. This is easy to implement if your session manager provides hooks. If you find or know a way to make this automatic for a session manager or for all session managers, please open a issue or a pull request. I will be more than happy to make termnames.nvim better.

Features

Requirements

Installation

With lazy.nvim

return {
    "aaditeynair/termnames.nvim",
    cmd = {"TermOpen", "TermRename", "TermClose", "TermSave", "TermRefresh"}
}

Setup

require("termnames").setup({
    -- Add DirChanges to this if needed. When creating and updating the teminal info,
    -- termnames tries to set the current buffer as the one before a terminal was
    -- opened. However, this may cause issues where the previous buffer was deleted by say, a session manager.
    update_term_bufnr_events = {"SessionLoadPost"},

    -- Termnames sets this key combination to run TermClose for every terminal buffer it creates
    close_term_keybinding = "<leader>q",
})

Usage

Commands

TermOpen

TermRename

TermClose

TermRun

TermSave

TermRefresh

API

require("termnames").create_terminal([term_name] or [{term_name, cmd}])

require("termnames").get_terminals()

{
  "id": 1,
  "name": "term1",
  "bufnr": 3
}

require("termnames").get_terminal_name(bufnr)

require("termnames").get_current_terminal_name()

require("termnames").terminal_exists(term_name)

require("termnames").rename_terminal(args)

require("termnames").delete_terminal([ term_name ])

require("termnames").run_terminal_cmd({term_name, cmd})

require("termnames").save_terminal_data()

require("termnames").update_term_bufnr()

Example

Lualine

local function get_term_name()
    return require("termnames").get_current_terminal_name()
end

...

{
 get_term_name,
 cond = function()
     return vim.api.nvim_buf_get_name(0):find("^term://") ~= nil
 end,
},