Coder Social home page Coder Social logo

jmanch / sunset.nvim Goto Github PK

View Code? Open in Web Editor NEW
33.0 1.0 0.0 41 KB

An automatic theme switcher for Neovim that uses precise sunrise/sunset times based on your latitude and longitude.

License: MIT License

Lua 100.00%
neovim nvim sunrise sunset theme

sunset.nvim's Introduction

Sunset.nvim ๐ŸŒ…

An automatic theme switcher for Neovim that uses precise sunrise/sunset times based on your latitude and longitude.

Sun times are calculated locally so the plugin does not require an internet connection to function. The plugin uses a libuv timer to ensure that the theme is updated whilst Neovim is open without the need for a restart.

Installation

Install using your preferred method and call the setup function to load the plugin. The function accepts a table for overriding the default configuration:

require("sunset").setup({
    latitude = 51.5072, -- north is positive, south is negative
    longitude = -0.1276, -- east is positive, west is negative
    sunrise_offset = 0, -- offset the sunrise by this many seconds
    sunset_offset = 0, -- offset the sunset by this many seconds
    sunrise_override = nil, -- accepts a time in the form "HH:MM" which will override the sunrise time
    sunset_override = nil, -- accepts a time in the form "HH:MM" which will override the sunset time
    day_callback = nil, -- function that is called when day begins
    night_callback = nil, -- function that is called when night begins
    update_interval = 60000, -- how frequently to check for sunrise/sunset changes in milliseconds
    time_format = "%H:%M", -- sun time formatting using os.date https://www.lua.org/pil/22.1.html
})

I recommend ensuring that Sunset.nvim loads after any colorscheme plugins to reduce the likelihood of issues.

Here's how I load my colorscheme plugin and sunset.nvim with lazy.nvim:

{
    "JManch/sunset.nvim",
    dependencies = {
        {
            "colorscheme plugin",
            config = function
                -- Colorscheme plugin config
            end,
        },
    },
    lazy = false,
    priority = 1000,
    opts = {
        latitude = 51.5072,
        longitude = -0.1276,
    },
}

Usage

By default, the plugin changes the background option between light and dark. If you would like the change this behaviour, you can set the day_callback or night_callback which will disable the background switching. For example:

day_callback = function()
    vim.cmd("colorscheme foo")
end

If you would like to show the sun status in your statusline, sunset.nvim sets the following global variables:

vim.g.is_day -- boolean
vim.g.sunrise -- next sunrise time string formatted using time_format option
vim.g.sunset -- next sunset time string formatted using time_format option

The plugin has the following commands:

  • SunsetTimes - view the next sunrise/sunset times
  • SunsetToggle - toggle between day and night theme

Note on highlight groups

If you find that sunset.nvim is clearing your custom highlight groups every time you switch themes, you need to set highlight groups in a ColorScheme autocommand. More info here.

sunset.nvim's People

Contributors

jmanch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.