Home

Awesome

<div align = "center"> <h1><a href="https://github.com/2kabhishek/utils.nvim">utils.nvim</a></h1> <a href="https://github.com/2KAbhishek/utils.nvim/blob/main/LICENSE"> <img alt="License" src="https://img.shields.io/github/license/2kabhishek/utils.nvim?style=flat&color=eee&label="> </a> <a href="https://github.com/2KAbhishek/utils.nvim/graphs/contributors"> <img alt="People" src="https://img.shields.io/github/contributors/2kabhishek/utils.nvim?style=flat&color=ffaaf2&label=People"> </a> <a href="https://github.com/2KAbhishek/utils.nvim/stargazers"> <img alt="Stars" src="https://img.shields.io/github/stars/2kabhishek/utils.nvim?style=flat&color=98c379&label=Stars"></a> <a href="https://github.com/2KAbhishek/utils.nvim/network/members"> <img alt="Forks" src="https://img.shields.io/github/forks/2kabhishek/utils.nvim?style=flat&color=66a8e0&label=Forks"> </a> <a href="https://github.com/2KAbhishek/utils.nvim/watchers"> <img alt="Watches" src="https://img.shields.io/github/watchers/2kabhishek/utils.nvim?style=flat&color=f5d08b&label=Watches"> </a> <a href="https://github.com/2KAbhishek/utils.nvim/pulse"> <img alt="Last Updated" src="https://img.shields.io/github/last-commit/2kabhishek/utils.nvim?style=flat&color=e06c75&label="> </a> <h3>Powerful Utilities for Neovim Plugin Devs πŸ› οΈπŸ§°</h3> </div>

utils.nvim is a Neovim plugin that provides a collection of utilities to simplify the development of other Neovim plugins.

✨ Features

⚑ Setup

βš™οΈ Requirements

πŸ’» Installation

utils.nvim is not meant to be installed by itself, but rather as a dependency for another plugin.

If you are building a plugin that requires the utilities provided by utils.nvim, you can add it as a dependency as shown below:

-- Lazy
{
    'yourname/plugin.nvim',
    dependencies = {
        '2kabhishek/utils.nvim'
    },
},

πŸš€ Usage

Functions

The utilities provided by utils.nvim can be directly used in your plugin as shown below:

local utils = require('utils')

utils.show_notification('Hello World!')

Below is a list of all the functions provided by utils.nvim.

utils.queue_notification(message: string, level?: number, title?: string, timeout?: number)

Adds a notification to the queue, to be processed and displayed later.

utils.show_notification(message: string, level?: number, title?: string, timeout?: number)

Immediately shows a notification to the user.

utils.open_command(command: string)

Opens the given command in the default browser/terminal, depending on the system.

utils.open_dir(dir: string)

Opens a directory inside a tmux session if running within tmux, or directly navigates in Neovim otherwise.

utils.async_shell_execute(command: string, callback: fun(result: string))

Executes a shell command asynchronously and calls the callback with the result.

utils.safe_json_decode(str: string) -> table|nil

Safely decodes a JSON string into a Lua table, with error handling.

utils.get_data_from_cache(cache_key: string, command: string, callback: fun(data: any), cache_timeout: number)

Fetches data from a cached file or executes a command to get fresh data if the cache is expired or missing.

utils.human_time(timestamp: string) -> string

Converts an ISO 8601 timestamp into a human-readable format.

utils.clear_cache(prefix: string)

Clears the cache by deleting all cached files.

Commands

utils.nvim adds the following command:

Help

Run :help nerdy for more details.

πŸ—οΈ What's Next

Planning to add <feature/module>.

βœ… To-Do

β›… Behind The Code

🌈 Inspiration

utils.nvim was created while working on octohub.nvim which relied on a lot of common utilities like async shell execution, notifications, and caching.

πŸ’‘ Challenges/Learnings

πŸ” More Info

<hr> <div align="center">

<strong>⭐ hit the star button if you found this useful ⭐</strong><br>

<a href="https://github.com/2KAbhishek/utils.nvim">Source</a> | <a href="https://2kabhishek.github.io/blog" target="_blank">Blog </a> | <a href="https://twitter.com/2kabhishek" target="_blank">Twitter </a> | <a href="https://linkedin.com/in/2kabhishek" target="_blank">LinkedIn </a> | <a href="https://2kabhishek.github.io/links" target="_blank">More Links </a> | <a href="https://2kabhishek.github.io/projects" target="_blank">Other Projects </a>

</div>