Skip to content

Latest commit

 

History

History
133 lines (102 loc) · 5.63 KB

README.md

File metadata and controls

133 lines (102 loc) · 5.63 KB

Telescope Themes

An extension for Telescope plugin to switch colorschemes with preview. It will read all your installed themes

demo

Installation

Using lazy.nvim

{
    'andrew-george/telescope-themes',
    config = function()
        require('telescope').load_extension('themes')
    end
}

OR

As a dependancy in telescope config file (example in lazy.nvim)

{
    'nvim-telescope/telescope.nvim',
    cmd = 'Telescope',
    lazy = true,
    dependencies = {
        'andrew-george/telescope-themes',
        -- other dependencies
    },
    config = function()
        -- load extension
        local telescope = require('telescope')
        telescope.load_extension('themes')
    end
}

Usage

:Telescope themes

or map it to a key

vim.keymap.set("n", "<leader>th", ":Telescope themes<CR>", {noremap = true, silent = true, desc = "Theme Switcher"})

Configuration

The extension can receive any telescope option in addition to custom options

NOTE: All configurations should go under extensions table in telescope config file

Example Configuration ( NOT DEFAULT ):

{
    "nvim-telescope/telescope.nvim",
    dependencies = {
        "andrew-george/telescope-themes",
        -- other dependencies
        },
    config = function ()
        -- get builtin schemes list
        local builtin_schemes = require("telescope._extensions.themes").builtin_schemes

        require("telescope").setup({
            extensions = {
                themes = {
                    -- you can add regular telescope config
                    -- that you want to apply on this picker only
                    layout_config = {
                        horizontal = {
                            width = 0.8,
                            height = 0.7,
                        },
                    },

                    -- extension specific config

                    -- (boolean) -> show/hide previewer window
                    enable_previewer = true,

                    -- (boolean) -> enable/disable live preview
                    enable_live_preview = false,

                    -- all builtin themes are ignored by default
                    -- (list) -> provide table of theme names to overwrite builtins list
                    ignore = { "default", "desert", "elflord", "habamax" },
                    -- OR
                    -- extend the required `builtin_schemes` list to ignore other
                    -- schemes in addition to builtin schemes
                    ignore = vim.list_extend(builtin_schemes, { "embark" }),

                    persist = {
                        -- enable persisting last theme choice
                        enabled = true,

                        -- override path to file that execute colorscheme command
                        path = vim.fn.stdpath("config") .. "/lua/colorscheme.lua"
                    }
                },
            },
        })
    end
}

Options

Key Value Description
enable_previewer boolean Show / Hide previewer window
enable_live_preview boolean Enable / Disable live preview
ignore list of themes names Ignore specific themes from appearing in the list
persist { enabled: boolean, path: string} - Enable / Disable persisting last theme choice,
- Override file path to write your colorscheme command
WARNING: THIS MUST BE AN EMPTY FILE AS IT WILL BE COMPLETELY OVERWRITTEN
Default file path : {root_nvim_config}/lua/current-theme.lua

IMPORTANT

As the extension is writing the colorscheme command in your config, and neovim configs are very indvidual and unique, I wouldn't be able to predict which part to manipulate, so the extension creates a file named current-theme.lua will be generated in root of /lua directory, it contains the command responsible for persisting latest theme selection, and it's overwritten by the extension on every new selection.

Now you have to require current-theme.lua in your init.lua

Credits

  • It is inspired by NvChad's theme switcher, but written to work with any configuration. Now you have to require current-theme.lua at the end of your init.lua to apply that theme on every startup.