Move nvim related things to separate repo
This commit is contained in:
parent
25c5382905
commit
38c18601b7
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,6 +1,4 @@
|
||||||
.netrwhist
|
|
||||||
*.swp
|
*.swp
|
||||||
.python-version
|
.python-version
|
||||||
.DS_Store
|
.DS_Store
|
||||||
__pycache__
|
__pycache__
|
||||||
.luarc.json
|
|
||||||
|
|
42
Makefile
42
Makefile
|
@ -1,32 +1,33 @@
|
||||||
$(eval HOSTNAME=$(shell hostname))
|
$(eval HOSTNAME=$(shell hostname))
|
||||||
CONFIG_REPO := git@gitlab.com:elitherl/nixos.git
|
NIXOS_REPO := git@git.xenia.me.uk:xenia/nixos.git
|
||||||
HOMEMANAGER_CONFIG := $(PWD)/home/$(HOSTNAME)-$(USER).nix
|
NVIM_REPO := git@git.xenia.me.uk:xenia/nvim.git
|
||||||
|
HOMEMANAGER_CONFIG := $(PWD)/home/$(HOSTNAME)/$(USER).nix
|
||||||
CONFIG_DIR := $(if $(XDG_CONFIG_HOME), $(XDG_CONFIG_HOME), $(HOME)/.config)
|
CONFIG_DIR := $(if $(XDG_CONFIG_HOME), $(XDG_CONFIG_HOME), $(HOME)/.config)
|
||||||
BIN_DIR := $(HOME)/.local/bin
|
BIN_DIR := $(HOME)/.local/bin
|
||||||
HOMEMANAGER_CONFIG_DIR := $(CONFIG_DIR)/home-manager
|
HOMEMANAGER_CONFIG_DIR := $(CONFIG_DIR)/home-manager
|
||||||
|
|
||||||
.PHONY: default all clean nixos home legacy lclean
|
.PHONY: default all clean nixos home nvim
|
||||||
|
|
||||||
default:
|
default:
|
||||||
[ -e /etc/nixos/ ] && make nixos || make home
|
[ -e /etc/nixos/ ] && make nixos || make home
|
||||||
|
|
||||||
all: install nixos home
|
all: default nvim
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf $(HOME)/.local/share/nvim
|
|
||||||
rm -rf $(HOME)/.local/state/nvim
|
|
||||||
[ -e $(HOMEMANAGER_CONFIG_DIR) ] && rm -rf $(HOMEMANAGER_CONFIG_DIR)
|
[ -e $(HOMEMANAGER_CONFIG_DIR) ] && rm -rf $(HOMEMANAGER_CONFIG_DIR)
|
||||||
|
|
||||||
/nix:
|
|
||||||
command -v nix > /dev/null && echo "Nix already installed" || ./scripts/installers/nix.sh --daemon
|
|
||||||
|
|
||||||
/etc/nixos/config:
|
|
||||||
sudo git clone $(CONFIG_REPO) /etc/nixos/config
|
|
||||||
|
|
||||||
nixos: /etc/nixos/config
|
nixos: /etc/nixos/config
|
||||||
|
|
||||||
home: $(HOMEMANAGER_CONFIG_DIR)/home.nix
|
home: $(HOMEMANAGER_CONFIG_DIR)/home.nix
|
||||||
|
|
||||||
|
nvim: $(CONFIG_DIR)/nvim
|
||||||
|
|
||||||
|
/nix:
|
||||||
|
command -v nix > /dev/null || echo "Install nix package manager before continuing"; exit 1
|
||||||
|
|
||||||
|
/etc/nixos/config:
|
||||||
|
sudo git clone $(NIXOS_REPO) $@
|
||||||
|
|
||||||
$(HOMEMANAGER_CONFIG_DIR)/home.nix: $(HOMEMANAGER_CONFIG_DIR) /nix
|
$(HOMEMANAGER_CONFIG_DIR)/home.nix: $(HOMEMANAGER_CONFIG_DIR) /nix
|
||||||
[ -f $(HOMEMANAGER_CONFIG) ] || touch $(HOMEMANAGER_CONFIG)
|
[ -f $(HOMEMANAGER_CONFIG) ] || touch $(HOMEMANAGER_CONFIG)
|
||||||
ln -s $(HOMEMANAGER_CONFIG) $@
|
ln -s $(HOMEMANAGER_CONFIG) $@
|
||||||
|
@ -34,18 +35,5 @@ $(HOMEMANAGER_CONFIG_DIR)/home.nix: $(HOMEMANAGER_CONFIG_DIR) /nix
|
||||||
$(CONFIG_DIR) $(HOMEMANAGER_CONFIG_DIR) $(BIN_DIR):
|
$(CONFIG_DIR) $(HOMEMANAGER_CONFIG_DIR) $(BIN_DIR):
|
||||||
mkdir -p $@
|
mkdir -p $@
|
||||||
|
|
||||||
legacy: $(CONFIG_DIR) $(BIN_DIR)
|
$(CONFIG_DIR)/nvim: $(CONFIG_DIR)
|
||||||
fc-list | grep -iE "(fira.*code)*(nerd.*font)" > /dev/null || ./scripts/installers/firacode.sh && fc-cache
|
git clone $(NVIM_REPO) $@
|
||||||
command -v nvim > /dev/null || ./scripts/installers/nvim.sh
|
|
||||||
[ -e $(CONFIG_DIR)/nvim ] || ln -s $(PWD)/home/tui/config/nvim $(CONFIG_DIR)/
|
|
||||||
command -v starship > /dev/null || ./scripts/installers/starship.sh --yes --bin-dir $(BIN_DIR)
|
|
||||||
[ -e $(CONFIG_DIR)/starship.toml ] || ln -s $(PWD)/home/env/config/starship.toml $(CONFIG_DIR)/
|
|
||||||
command -v direnv > /dev/null || bin_path="$(BIN_DIR)" ./scripts/installers/direnv.sh
|
|
||||||
|
|
||||||
lclean: clean
|
|
||||||
[ -e $(HOME)/.fonts/FiraCode ] && rm -rf $(HOME)/.fonts/FiraCode
|
|
||||||
[ -e $(BIN_DIR)/nvim ] && rm $(BIN_DIR)/nvim
|
|
||||||
[ -e $(CONFIG_DIR)/nvim ] && rm $(CONFIG_DIR)/nvim
|
|
||||||
[ -e $(BIN_DIR)/starship ] && rm $(BIN_DIR)/starship
|
|
||||||
[ -e $(CONFIG_DIR)/starship.toml ] && rm $(CONFIG_DIR)/starship.toml
|
|
||||||
[ -e $(BIN_DIR)/direnv ] && rm $(BIN_DIR)/direnv
|
|
||||||
|
|
|
@ -1,78 +0,0 @@
|
||||||
vim.g.mapleader = " "
|
|
||||||
|
|
||||||
-- bootstrap lazy.nvim
|
|
||||||
local lazypath = vim.fn.stdpath "data" .. "/lazy/lazy.nvim"
|
|
||||||
if not vim.loop.fs_stat(lazypath) then
|
|
||||||
vim.fn.system {
|
|
||||||
"git",
|
|
||||||
"clone",
|
|
||||||
"--filter=blob:none",
|
|
||||||
"https://github.com/folke/lazy.nvim.git",
|
|
||||||
"--branch=stable", -- latest stable release
|
|
||||||
lazypath,
|
|
||||||
}
|
|
||||||
end
|
|
||||||
vim.opt.rtp:prepend(lazypath)
|
|
||||||
require("lazy").setup {
|
|
||||||
root = vim.fn.stdpath "data" .. "/lazy",
|
|
||||||
spec = "plugins",
|
|
||||||
lockfile = vim.fn.stdpath "data" .. "/lazy-lock.json",
|
|
||||||
dev = { path = "~/Projects/lua/nvim" },
|
|
||||||
install = { colorscheme = { "catppuccin" } },
|
|
||||||
ui = {
|
|
||||||
border = "rounded",
|
|
||||||
icons = { lazy = " " },
|
|
||||||
},
|
|
||||||
diff = { cmd = "diffview.nvim" },
|
|
||||||
checker = { enabled = true, frequency = 3600 },
|
|
||||||
performance = {
|
|
||||||
rtp = {
|
|
||||||
disabled_plugins = {
|
|
||||||
"gzip",
|
|
||||||
"matchit",
|
|
||||||
"matchparen",
|
|
||||||
"netrwPlugin",
|
|
||||||
"tarPlugin",
|
|
||||||
"tohtml",
|
|
||||||
"tutor",
|
|
||||||
"zipPlugin",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Set vim options
|
|
||||||
vim.opt.laststatus = 3
|
|
||||||
vim.opt.showtabline = 1
|
|
||||||
vim.opt.shiftwidth = 4
|
|
||||||
vim.opt.expandtab = true
|
|
||||||
vim.opt.number = true
|
|
||||||
vim.opt.relativenumber = true
|
|
||||||
vim.opt.listchars = { lead = ".", trail = ".", tab = ">-" }
|
|
||||||
vim.opt.list = true
|
|
||||||
vim.opt.splitbelow = true
|
|
||||||
vim.opt.splitright = true
|
|
||||||
|
|
||||||
-- Global
|
|
||||||
vim.g.loaded_perl_provider = 0
|
|
||||||
|
|
||||||
-- Common keymaps
|
|
||||||
vim.keymap.set("i", "jk", "<esc>")
|
|
||||||
vim.keymap.set("n", "<leader>l", "<cmd>Lazy<CR>")
|
|
||||||
|
|
||||||
vim.opt.winblend = 15
|
|
||||||
vim.opt.pumblend = 15
|
|
||||||
|
|
||||||
-- neovide
|
|
||||||
if vim.g.neovide then
|
|
||||||
vim.g.neovide_padding_top = 5
|
|
||||||
vim.g.neovide_padding_bottom = 5
|
|
||||||
vim.g.neovide_padding_left = 5
|
|
||||||
vim.g.neovide_padding_right = 5
|
|
||||||
|
|
||||||
vim.g.neovide_floating_blur_amount_x = 2.0
|
|
||||||
vim.g.neovide_floating_blur_amount_y = 2.0
|
|
||||||
|
|
||||||
vim.g.neovide_hide_mouse_when_typing = false
|
|
||||||
vim.g.neovide_remember_window_size = false
|
|
||||||
end
|
|
|
@ -1,27 +0,0 @@
|
||||||
-- Use an on_attach function to only map the following keys
|
|
||||||
-- after the language server attaches to the current buffer
|
|
||||||
local on_attach = function(client, bufnr)
|
|
||||||
-- Mappings.
|
|
||||||
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
|
||||||
local bufopts = { noremap = true, silent = true, buffer = bufnr }
|
|
||||||
vim.keymap.set("n", "gD", vim.lsp.buf.definition, bufopts)
|
|
||||||
vim.keymap.set("n", "gd", "<cmd>Trouble lsp_definitions<cr>", bufopts)
|
|
||||||
vim.keymap.set("n", "gR", vim.lsp.buf.references, bufopts)
|
|
||||||
vim.keymap.set("n", "gr", "<cmd>Trouble lsp_references<cr>", bufopts)
|
|
||||||
vim.keymap.set("n", "gI", vim.lsp.buf.implementation, bufopts)
|
|
||||||
vim.keymap.set("n", "gi", "<cmd>Trouble lsp_implementations<cr>", bufopts)
|
|
||||||
vim.keymap.set("n", "K", vim.lsp.buf.hover, bufopts)
|
|
||||||
vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, bufopts)
|
|
||||||
vim.keymap.set("n", "<leader>wa", vim.lsp.buf.add_workspace_folder, bufopts)
|
|
||||||
vim.keymap.set("n", "<leader>wr", vim.lsp.buf.remove_workspace_folder, bufopts)
|
|
||||||
vim.keymap.set("n", "<leader>wl", function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end, bufopts)
|
|
||||||
vim.keymap.set("n", "<leader>D", vim.lsp.buf.type_definition, bufopts)
|
|
||||||
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, bufopts)
|
|
||||||
vim.keymap.set("n", "<leader>ca", vim.lsp.buf.code_action, bufopts)
|
|
||||||
vim.keymap.set("n", "<leader>i", require "lsp.formatting", bufopts)
|
|
||||||
if client.server_capabilities.documentSymbolProvider then
|
|
||||||
require("nvim-navic").attach(client, bufnr)
|
|
||||||
require("nvim-navbuddy").attach(client, bufnr)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return on_attach
|
|
|
@ -1,98 +0,0 @@
|
||||||
local cmp = require "cmp"
|
|
||||||
local luasnip = require "luasnip"
|
|
||||||
local cmp_autopairs = require "nvim-autopairs.completion.cmp"
|
|
||||||
|
|
||||||
require("luasnip.loaders.from_vscode").lazy_load()
|
|
||||||
|
|
||||||
cmp.setup {
|
|
||||||
snippet = {
|
|
||||||
expand = function(args)
|
|
||||||
luasnip.lsp_expand(args.body) -- For `luasnip` users.
|
|
||||||
end,
|
|
||||||
},
|
|
||||||
mapping = cmp.mapping.preset.insert {
|
|
||||||
["<C-u>"] = cmp.mapping.scroll_docs(-4), -- Up
|
|
||||||
["<C-d>"] = cmp.mapping.scroll_docs(4), -- Down
|
|
||||||
["<C-Space>"] = cmp.mapping.complete(),
|
|
||||||
["<CR>"] = cmp.mapping.confirm {
|
|
||||||
behavior = cmp.ConfirmBehavior.Replace,
|
|
||||||
select = true,
|
|
||||||
},
|
|
||||||
["<Tab>"] = cmp.mapping(function(fallback)
|
|
||||||
if cmp.visible() then
|
|
||||||
cmp.select_next_item()
|
|
||||||
elseif luasnip.expand_or_jumpable() then
|
|
||||||
luasnip.expand_or_jump()
|
|
||||||
else
|
|
||||||
fallback()
|
|
||||||
end
|
|
||||||
end, { "i", "s" }),
|
|
||||||
["<S-Tab>"] = cmp.mapping(function(fallback)
|
|
||||||
if cmp.visible() then
|
|
||||||
cmp.select_prev_item()
|
|
||||||
elseif luasnip.jumpable(-1) then
|
|
||||||
luasnip.jump(-1)
|
|
||||||
else
|
|
||||||
fallback()
|
|
||||||
end
|
|
||||||
end, { "i", "s" }),
|
|
||||||
},
|
|
||||||
sources = {
|
|
||||||
{ name = "nvim_lsp" },
|
|
||||||
{ name = "luasnip" },
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Set configuration for specific filetype.
|
|
||||||
cmp.setup.filetype("python", {
|
|
||||||
sources = {
|
|
||||||
{ name = "nvim_lsp" },
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
cmp.setup.filetype("nix", {
|
|
||||||
sources = {
|
|
||||||
{ name = "nvim_lsp" },
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
cmp.setup.filetype("gitcommit", {
|
|
||||||
sources = {
|
|
||||||
{ name = "nvim_lsp" },
|
|
||||||
{ name = "git" },
|
|
||||||
{ name = "spell" },
|
|
||||||
{ name = "commit" },
|
|
||||||
{ name = "buffer" },
|
|
||||||
{ name = "luasnip" },
|
|
||||||
{ name = "latex_symbols" },
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
cmp.setup.filetype("markdown", {
|
|
||||||
sources = {
|
|
||||||
{ name = "nvim_lsp" },
|
|
||||||
{ name = "spell" },
|
|
||||||
{ name = "buffer" },
|
|
||||||
{ name = "luasnip" },
|
|
||||||
{ name = "latex_symbols" },
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
cmp.setup.cmdline("/", {
|
|
||||||
mapping = cmp.mapping.preset.cmdline(),
|
|
||||||
sources = {
|
|
||||||
{ name = "nvim_lsp" },
|
|
||||||
{ name = "buffer" },
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
cmp.setup.cmdline(":", {
|
|
||||||
mapping = cmp.mapping.preset.cmdline(),
|
|
||||||
sources = {
|
|
||||||
{ name = "nvim_lsp" },
|
|
||||||
{ name = "path" },
|
|
||||||
{ name = "cmdline" },
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done())
|
|
|
@ -1,39 +0,0 @@
|
||||||
local M = {}
|
|
||||||
|
|
||||||
-- Mappings.
|
|
||||||
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
|
|
||||||
local opts = { noremap = true, silent = true }
|
|
||||||
vim.keymap.set("n", "<leader>e", vim.diagnostic.open_float, opts)
|
|
||||||
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, opts)
|
|
||||||
vim.keymap.set("n", "]d", vim.diagnostic.goto_next, opts)
|
|
||||||
vim.keymap.set("n", "<leader>q", vim.diagnostic.setloclist, opts)
|
|
||||||
|
|
||||||
local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " }
|
|
||||||
for type, icon in pairs(signs) do
|
|
||||||
local hl = "DiagnosticSign" .. type
|
|
||||||
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl })
|
|
||||||
end
|
|
||||||
|
|
||||||
require("neodev").setup()
|
|
||||||
|
|
||||||
M.on_attach = require "lsp.attach"
|
|
||||||
M.lsp_flags = require "lsp.flags"
|
|
||||||
M.capabilities = require("cmp_nvim_lsp").default_capabilities()
|
|
||||||
|
|
||||||
local servers = { "jedi_language_server", "lua_ls", "rnix", "nil_ls", "fortls" }
|
|
||||||
for _, name in ipairs(servers) do
|
|
||||||
require("lspconfig")[name].setup {
|
|
||||||
on_attach = M.on_attach,
|
|
||||||
flags = M.lsp_flags,
|
|
||||||
capabilities = M.capabilities,
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
require("null-ls").setup {
|
|
||||||
sources = require "lsp.null_ls_sources",
|
|
||||||
on_attach = M.on_attach,
|
|
||||||
flags = M.lsp_flags,
|
|
||||||
capabilities = M.capabilities,
|
|
||||||
}
|
|
||||||
|
|
||||||
return M
|
|
|
@ -1,5 +0,0 @@
|
||||||
local lsp_flags = {
|
|
||||||
-- This is the default in Nvim 0.7+
|
|
||||||
debounce_text_changes = 150,
|
|
||||||
}
|
|
||||||
return lsp_flags
|
|
|
@ -1,11 +0,0 @@
|
||||||
local lsp_formatting = function(bufnr)
|
|
||||||
vim.lsp.buf.format {
|
|
||||||
bufnr = bufnr,
|
|
||||||
timeout_ms = 2000,
|
|
||||||
async = true,
|
|
||||||
filter = function(client)
|
|
||||||
return client.name ~= "jedi_language_server" and client.name ~= "lua_ls"
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
end
|
|
||||||
return lsp_formatting
|
|
|
@ -1,13 +0,0 @@
|
||||||
local null_ls = require "null-ls"
|
|
||||||
return {
|
|
||||||
null_ls.builtins.code_actions.gitsigns,
|
|
||||||
null_ls.builtins.diagnostics.zsh,
|
|
||||||
null_ls.builtins.diagnostics.mypy,
|
|
||||||
null_ls.builtins.diagnostics.ruff,
|
|
||||||
null_ls.builtins.formatting.black,
|
|
||||||
null_ls.builtins.formatting.isort,
|
|
||||||
null_ls.builtins.formatting.stylua,
|
|
||||||
null_ls.builtins.formatting.prettier,
|
|
||||||
null_ls.builtins.formatting.trim_whitespace,
|
|
||||||
null_ls.builtins.hover.dictionary,
|
|
||||||
}
|
|
|
@ -1,58 +0,0 @@
|
||||||
return {
|
|
||||||
"goolord/alpha-nvim",
|
|
||||||
event = "VimEnter",
|
|
||||||
opts = function()
|
|
||||||
local dashboard = require "alpha.themes.dashboard"
|
|
||||||
local logo = [[
|
|
||||||
██╗ █████╗ ███████╗██╗ ██╗██╗ ██╗██╗███╗ ███╗ Z
|
|
||||||
██║ ██╔══██╗╚══███╔╝╚██╗ ██╔╝██║ ██║██║████╗ ████║ Z
|
|
||||||
██║ ███████║ ███╔╝ ╚████╔╝ ██║ ██║██║██╔████╔██║ z
|
|
||||||
██║ ██╔══██║ ███╔╝ ╚██╔╝ ╚██╗ ██╔╝██║██║╚██╔╝██║ z
|
|
||||||
███████╗██║ ██║███████╗ ██║ ╚████╔╝ ██║██║ ╚═╝ ██║
|
|
||||||
╚══════╝╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═══╝ ╚═╝╚═╝ ╚═╝
|
|
||||||
]]
|
|
||||||
|
|
||||||
dashboard.section.header.val = vim.split(logo, "\n")
|
|
||||||
dashboard.section.buttons.val = {
|
|
||||||
dashboard.button("f", " " .. " Find file", ":Telescope find_files <CR>"),
|
|
||||||
dashboard.button("e", " " .. " Edit new file", ":ene <BAR> startinsert <CR>"),
|
|
||||||
dashboard.button("r", " " .. " Recent files", ":Telescope oldfiles <CR>"),
|
|
||||||
dashboard.button("n", " " .. " Neotree", ":Neotree left <CR>"),
|
|
||||||
dashboard.button("g", " " .. " Git status", ":Neogit <CR>"),
|
|
||||||
dashboard.button("c", " " .. " Config", ":e $MYVIMRC <CR>"),
|
|
||||||
dashboard.button("l", " " .. " Lazy", ":Lazy<CR>"),
|
|
||||||
dashboard.button("q", " " .. " Quit", ":qa<CR>"),
|
|
||||||
}
|
|
||||||
for _, button in ipairs(dashboard.section.buttons.val) do
|
|
||||||
button.opts.hl = "AlphaButtons"
|
|
||||||
button.opts.hl_shortcut = "AlphaShortcut"
|
|
||||||
end
|
|
||||||
dashboard.section.header.opts.hl = "AlphaHeader"
|
|
||||||
dashboard.section.buttons.opts.hl = "AlphaButtons"
|
|
||||||
dashboard.section.footer.opts.hl = "AlphaFooter"
|
|
||||||
dashboard.opts.layout[1].val = 8
|
|
||||||
return dashboard
|
|
||||||
end,
|
|
||||||
config = function(_, dashboard)
|
|
||||||
-- close Lazy and re-open when the dashboard is ready
|
|
||||||
if vim.o.filetype == "lazy" then
|
|
||||||
vim.cmd.close()
|
|
||||||
vim.api.nvim_create_autocmd("User", {
|
|
||||||
pattern = "AlphaReady",
|
|
||||||
callback = function() require("lazy").show() end,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
require("alpha").setup(dashboard.opts)
|
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd("User", {
|
|
||||||
pattern = "LazyVimStarted",
|
|
||||||
callback = function()
|
|
||||||
local stats = require("lazy").stats()
|
|
||||||
local ms = (math.floor(stats.startuptime * 100 + 0.5) / 100)
|
|
||||||
dashboard.section.footer.val = "⚡ Neovim loaded " .. stats.count .. " plugins in " .. ms .. "ms"
|
|
||||||
pcall(vim.cmd.AlphaRedraw)
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
end,
|
|
||||||
}
|
|
|
@ -1,48 +0,0 @@
|
||||||
local config = {
|
|
||||||
flavour = "macchiato",
|
|
||||||
term_colors = true,
|
|
||||||
transparent_background = true,
|
|
||||||
integrations = {
|
|
||||||
alpha = true,
|
|
||||||
gitsigns = true,
|
|
||||||
hop = true,
|
|
||||||
indent_blankline = {
|
|
||||||
enabled = true,
|
|
||||||
colored_indent_levels = true,
|
|
||||||
},
|
|
||||||
cmp = true,
|
|
||||||
markdown = true,
|
|
||||||
mini = true,
|
|
||||||
native_lsp = {
|
|
||||||
enabled = true,
|
|
||||||
},
|
|
||||||
neogit = true,
|
|
||||||
neotree = true,
|
|
||||||
noice = true,
|
|
||||||
notify = true,
|
|
||||||
navic = {
|
|
||||||
enabled = true,
|
|
||||||
custom_bg = "NONE",
|
|
||||||
},
|
|
||||||
treesitter = true,
|
|
||||||
treesitter_context = true,
|
|
||||||
telescope = true,
|
|
||||||
lsp_trouble = true,
|
|
||||||
which_key = true,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
"catppuccin/nvim",
|
|
||||||
name = "catppuccin",
|
|
||||||
lazy = false,
|
|
||||||
priority = 1000,
|
|
||||||
init = function()
|
|
||||||
vim.opt.termguicolors = true
|
|
||||||
require "ui.fillchars"
|
|
||||||
end,
|
|
||||||
config = function()
|
|
||||||
require("catppuccin").setup(config)
|
|
||||||
vim.cmd.colorscheme "catppuccin"
|
|
||||||
end,
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
return {
|
|
||||||
"numToStr/Comment.nvim",
|
|
||||||
keys = { "gcc", "gcb" },
|
|
||||||
event = { "BufReadPre" },
|
|
||||||
config = true,
|
|
||||||
opts = { ignore = "^$" },
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
return {
|
|
||||||
"sindrets/diffview.nvim",
|
|
||||||
dependencies = { "nvim-lua/plenary.nvim", "nvim-tree/nvim-web-devicons" },
|
|
||||||
cmd = {
|
|
||||||
"DiffviewFileHistory",
|
|
||||||
"DiffviewOpen",
|
|
||||||
},
|
|
||||||
config = true,
|
|
||||||
opts = {
|
|
||||||
enhanced_diff_hl = true,
|
|
||||||
file_panel = {
|
|
||||||
listing_style = "list",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
return {
|
|
||||||
"https://github.com/direnv/direnv.vim.git",
|
|
||||||
name = "direnv.vim",
|
|
||||||
lazy = false,
|
|
||||||
config = function()
|
|
||||||
vim.g.direnv_auto = 1
|
|
||||||
vim.g.direnv_silent_load = 1
|
|
||||||
end,
|
|
||||||
}
|
|
|
@ -1 +0,0 @@
|
||||||
return { "stevearc/dressing.nvim", event = "VeryLazy" }
|
|
|
@ -1,50 +0,0 @@
|
||||||
return {
|
|
||||||
"lewis6991/gitsigns.nvim",
|
|
||||||
event = { "BufReadPre", "BufNewFile" },
|
|
||||||
config = true,
|
|
||||||
opts = {
|
|
||||||
signcolumn = true,
|
|
||||||
numhl = true,
|
|
||||||
linehl = false,
|
|
||||||
current_line_blame = true,
|
|
||||||
word_diff = false,
|
|
||||||
on_attach = function(bufnr)
|
|
||||||
local gs = package.loaded.gitsigns
|
|
||||||
|
|
||||||
local function map(mode, l, r, opts)
|
|
||||||
opts = opts or {}
|
|
||||||
opts.buffer = bufnr
|
|
||||||
vim.keymap.set(mode, l, r, opts)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Navigation
|
|
||||||
map("n", "]c", function()
|
|
||||||
if vim.wo.diff then return "]c" end
|
|
||||||
vim.schedule(function() gs.next_hunk() end)
|
|
||||||
return "<Ignore>"
|
|
||||||
end, { expr = true })
|
|
||||||
|
|
||||||
map("n", "[c", function()
|
|
||||||
if vim.wo.diff then return "[c" end
|
|
||||||
vim.schedule(function() gs.prev_hunk() end)
|
|
||||||
return "<Ignore>"
|
|
||||||
end, { expr = true })
|
|
||||||
|
|
||||||
-- Actions
|
|
||||||
map({ "n", "v" }, "<leader>hs", ":Gitsigns stage_hunk<CR>")
|
|
||||||
map({ "n", "v" }, "<leader>hr", ":Gitsigns reset_hunk<CR>")
|
|
||||||
map("n", "<leader>hS", gs.stage_buffer)
|
|
||||||
map("n", "<leader>hu", gs.undo_stage_hunk)
|
|
||||||
map("n", "<leader>hR", gs.reset_buffer)
|
|
||||||
map("n", "<leader>hp", gs.preview_hunk)
|
|
||||||
map("n", "<leader>hb", function() gs.blame_line { full = true } end)
|
|
||||||
map("n", "<leader>tb", gs.toggle_current_line_blame)
|
|
||||||
map("n", "<leader>hd", gs.diffthis)
|
|
||||||
map("n", "<leader>hD", function() gs.diffthis "~" end)
|
|
||||||
map("n", "<leader>td", gs.toggle_deleted)
|
|
||||||
|
|
||||||
-- Text object
|
|
||||||
map({ "o", "x" }, "ih", ":<C-U>Gitsigns select_hunk<CR>")
|
|
||||||
end,
|
|
||||||
},
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
return {
|
|
||||||
"phaazon/hop.nvim",
|
|
||||||
cmd = { "HopWord", "HopLine" },
|
|
||||||
init = function()
|
|
||||||
vim.keymap.set("n", "<leader>hw", "<cmd>HopWord<cr>")
|
|
||||||
vim.keymap.set("n", "<leader>hl", "<cmd>HopLine<cr>")
|
|
||||||
end,
|
|
||||||
config = true,
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
return {
|
|
||||||
"lukas-reineke/indent-blankline.nvim",
|
|
||||||
event = { "BufReadPre", "BufNewFile" },
|
|
||||||
config = true,
|
|
||||||
opts = {
|
|
||||||
show_current_context = true,
|
|
||||||
show_current_context_start = false,
|
|
||||||
},
|
|
||||||
}
|
|
|
@ -1,3 +0,0 @@
|
||||||
return {
|
|
||||||
{ "folke/lazy.nvim", cmd = "Lazy" },
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
return {
|
|
||||||
"neovim/nvim-lspconfig",
|
|
||||||
event = { "BufReadPre", "BufNewFile", "BufEnter" },
|
|
||||||
cmd = {
|
|
||||||
"LspLog",
|
|
||||||
"LspStop",
|
|
||||||
"LspStart",
|
|
||||||
"LspRestart",
|
|
||||||
"LspInfo",
|
|
||||||
},
|
|
||||||
dependencies = {
|
|
||||||
{ "hrsh7th/nvim-cmp" },
|
|
||||||
{ "rafamadriz/friendly-snippets" },
|
|
||||||
{ "windwp/nvim-autopairs" },
|
|
||||||
{ "jose-elias-alvarez/null-ls.nvim", lazy = true },
|
|
||||||
{ "mfussenegger/nvim-dap", lazy = true },
|
|
||||||
{ "folke/neodev.nvim", dependencies = { "hrsh7th/nvim-cmp" }, lazy = true },
|
|
||||||
{ "SmiteshP/nvim-navic" },
|
|
||||||
{ "SmiteshP/nvim-navbuddy" },
|
|
||||||
},
|
|
||||||
config = function()
|
|
||||||
require "lsp.config"
|
|
||||||
require "lsp.cmp"
|
|
||||||
end,
|
|
||||||
}
|
|
|
@ -1,32 +0,0 @@
|
||||||
return {
|
|
||||||
"nvim-lualine/lualine.nvim",
|
|
||||||
dependencies = { "nvim-tree/nvim-web-devicons", "SmiteshP/nvim-navic", "folke/noice.nvim" },
|
|
||||||
event = { "BufEnter" },
|
|
||||||
config = true,
|
|
||||||
opts = {
|
|
||||||
options = {
|
|
||||||
theme = "catppuccin",
|
|
||||||
component_separators = "|",
|
|
||||||
section_separators = { left = "", right = "" },
|
|
||||||
globalstatus = true,
|
|
||||||
},
|
|
||||||
sections = {
|
|
||||||
lualine_a = { "mode" },
|
|
||||||
lualine_b = { "filename", { "branch", icon = "" }, "diff" },
|
|
||||||
lualine_c = { "diagnostics", "require('noice').api.status.lsp.get_hl()" },
|
|
||||||
lualine_x = { "filetype", "fileformat", "encoding" },
|
|
||||||
lualine_y = { "progress" },
|
|
||||||
lualine_z = { "selectioncount", "location" },
|
|
||||||
},
|
|
||||||
tabline = {
|
|
||||||
lualine_a = {},
|
|
||||||
lualine_b = {},
|
|
||||||
lualine_c = { "require('nvim-navic').get_location()" },
|
|
||||||
lualine_x = { "windows" },
|
|
||||||
lualine_y = {},
|
|
||||||
lualine_z = {},
|
|
||||||
},
|
|
||||||
winbar = {},
|
|
||||||
extensions = { "aerial", "fzf", "lazy", "neo-tree", "toggleterm", "trouble" },
|
|
||||||
},
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
return {
|
|
||||||
"numToStr/Navigator.nvim",
|
|
||||||
cmd = {
|
|
||||||
"NavigatorUp",
|
|
||||||
"NavigatorDown",
|
|
||||||
"NavigatorLeft",
|
|
||||||
"NavigatorRight",
|
|
||||||
"NavigatorPrevious",
|
|
||||||
},
|
|
||||||
init = function()
|
|
||||||
vim.keymap.set({ "n", "t" }, "<A-h>", "<CMD>NavigatorLeft<CR>")
|
|
||||||
vim.keymap.set({ "n", "t" }, "<A-l>", "<CMD>NavigatorRight<CR>")
|
|
||||||
vim.keymap.set({ "n", "t" }, "<A-k>", "<CMD>NavigatorUp<CR>")
|
|
||||||
vim.keymap.set({ "n", "t" }, "<A-j>", "<CMD>NavigatorDown<CR>")
|
|
||||||
vim.keymap.set({ "n", "t" }, "<A-p>", "<CMD>NavigatorPrevious<CR>")
|
|
||||||
end,
|
|
||||||
config = true,
|
|
||||||
}
|
|
|
@ -1,24 +0,0 @@
|
||||||
return {
|
|
||||||
"TimUntersberger/neogit",
|
|
||||||
dependencies = {
|
|
||||||
"nvim-lua/plenary.nvim",
|
|
||||||
"sindrets/diffview.nvim",
|
|
||||||
},
|
|
||||||
cmd = "Neogit",
|
|
||||||
init = function()
|
|
||||||
vim.keymap.set("n", "<leader>gg", "<cmd>Neogit<CR>")
|
|
||||||
vim.keymap.set("n", "<leader>cc", "<cmd>Neogit commit<CR>")
|
|
||||||
vim.keymap.set("n", "<leader>gp", "<cmd>Neogit pull<CR>")
|
|
||||||
vim.keymap.set("n", "<leader>gP", "<cmd>Neogit push<CR>")
|
|
||||||
end,
|
|
||||||
config = true,
|
|
||||||
opts = {
|
|
||||||
disable_commit_confirmation = true,
|
|
||||||
disable_builtin_notifications = true,
|
|
||||||
-- kind = "floating",
|
|
||||||
-- commit_popup = { kind = "floating" },
|
|
||||||
-- preview_buffer = { kind = "floating" },
|
|
||||||
-- popup = { kind = "floating" },
|
|
||||||
integrations = { diffview = true },
|
|
||||||
},
|
|
||||||
}
|
|
|
@ -1,48 +0,0 @@
|
||||||
return {
|
|
||||||
"nvim-neo-tree/neo-tree.nvim",
|
|
||||||
branch = "v2.x",
|
|
||||||
dependencies = {
|
|
||||||
"nvim-lua/plenary.nvim",
|
|
||||||
"nvim-tree/nvim-web-devicons", -- not strictly required, but recommended
|
|
||||||
"MunifTanjim/nui.nvim",
|
|
||||||
},
|
|
||||||
cmd = "NeoTree",
|
|
||||||
event = { "BufEnter" },
|
|
||||||
init = function()
|
|
||||||
vim.g.loaded_netrw = 1
|
|
||||||
vim.g.loaded_netrwPlugin = 1
|
|
||||||
vim.g.neo_tree_remove_legacy_commands = 1
|
|
||||||
vim.keymap.set("n", "<leader>nn", "<cmd>Neotree left reveal reveal_force_cwd<cr>")
|
|
||||||
vim.keymap.set("n", "<leader>nb", "<cmd>Neotree toggle show buffers right<cr>")
|
|
||||||
end,
|
|
||||||
config = true,
|
|
||||||
opts = {
|
|
||||||
close_if_last_window = true,
|
|
||||||
use_popups_for_input = false,
|
|
||||||
filesystem = {
|
|
||||||
window = {
|
|
||||||
mappings = {
|
|
||||||
["Z"] = "expand_all_nodes",
|
|
||||||
["<tab>"] = "toggle_node",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
filtered_items = {
|
|
||||||
hide_dotfiles = false,
|
|
||||||
},
|
|
||||||
group_empty_dirs = true,
|
|
||||||
hijack_netrw_behavior = "open_current",
|
|
||||||
},
|
|
||||||
buffers = {
|
|
||||||
bind_to_cwd = true,
|
|
||||||
follow_current_file = true,
|
|
||||||
group_empty_dirs = true,
|
|
||||||
},
|
|
||||||
git_status = {
|
|
||||||
group_empty_dirs = true,
|
|
||||||
},
|
|
||||||
source_selector = {
|
|
||||||
winbar = true,
|
|
||||||
statusline = false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
|
@ -1,44 +0,0 @@
|
||||||
return {
|
|
||||||
"folke/noice.nvim",
|
|
||||||
dependencies = {
|
|
||||||
"MunifTanjim/nui.nvim",
|
|
||||||
"rcarriga/nvim-notify",
|
|
||||||
},
|
|
||||||
config = true,
|
|
||||||
opts = {
|
|
||||||
lsp = {
|
|
||||||
progress = {
|
|
||||||
enabled = true,
|
|
||||||
format = {
|
|
||||||
"({data.progress.percentage}%) ",
|
|
||||||
{ "{spinner} ", hl_group = "NoiceLspProgressSpinner" },
|
|
||||||
{ "{data.progress.title} ", hl_group = "NoiceLspProgressTitle" },
|
|
||||||
{ "{data.progress.client} ", hl_group = "NoiceLspProgressClient" },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
-- override markdown rendering so that **cmp** and other plugins use **Treesitter**
|
|
||||||
override = {
|
|
||||||
["vim.lsp.util.convert_input_to_markdown_lines"] = true,
|
|
||||||
["vim.lsp.util.stylize_markdown"] = true,
|
|
||||||
["cmp.entry.get_documentation"] = true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
views = {
|
|
||||||
mini = {
|
|
||||||
position = { row = -2 },
|
|
||||||
border = { style = "rounded" },
|
|
||||||
win_options = { winblend = 0 },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
status = { lsp = { event = "lsp", kind = "progress" } },
|
|
||||||
routes = { { view = "mini", filter = { event = "lsp", kind = "progress" }, opts = { skip = true } } },
|
|
||||||
-- you can enable a preset for easier configuration
|
|
||||||
presets = {
|
|
||||||
bottom_search = false, -- use a classic bottom cmdline for search
|
|
||||||
command_palette = true, -- position the cmdline and popupmenu together
|
|
||||||
long_message_to_split = false, -- long messages will be sent to a splitnoice
|
|
||||||
inc_rename = true, -- enables an input dialog for inc-rename.nvim
|
|
||||||
lsp_doc_border = true, -- add a border to hover docs and signature help
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
return {
|
|
||||||
"rcarriga/nvim-notify",
|
|
||||||
config = true,
|
|
||||||
opts = {
|
|
||||||
background_colour = "#000000",
|
|
||||||
fps = 60,
|
|
||||||
render = "default", -- "minimal", "simple"
|
|
||||||
},
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
return {
|
|
||||||
"hrsh7th/nvim-cmp",
|
|
||||||
dependencies = {
|
|
||||||
{ "hrsh7th/cmp-nvim-lsp" },
|
|
||||||
{ "hrsh7th/cmp-buffer" },
|
|
||||||
{ "hrsh7th/cmp-path" },
|
|
||||||
{ "hrsh7th/cmp-cmdline" },
|
|
||||||
{ "f3fora/cmp-spell" },
|
|
||||||
{ "petertriho/cmp-git" },
|
|
||||||
{ "Dosx001/cmp-commit" },
|
|
||||||
{ "kdheepak/cmp-latex-symbols" },
|
|
||||||
{ "L3MON4D3/LuaSnip" },
|
|
||||||
{ "saadparwaiz1/cmp_luasnip" },
|
|
||||||
},
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
return {
|
|
||||||
"windwp/nvim-autopairs",
|
|
||||||
lazy = true,
|
|
||||||
dependencies = {
|
|
||||||
"nvim-treesitter/nvim-treesitter",
|
|
||||||
"hrsh7th/nvim-cmp",
|
|
||||||
},
|
|
||||||
config = true,
|
|
||||||
opts = {
|
|
||||||
disable_in_macro = true,
|
|
||||||
disable_in_visualblock = true,
|
|
||||||
check_ts = true,
|
|
||||||
},
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
return {
|
|
||||||
"SmiteshP/nvim-navbuddy",
|
|
||||||
dependencies = { "SmiteshP/nvim-navic", "MunifTanjim/nui.nvim" },
|
|
||||||
cmd = { "Navbuddy" },
|
|
||||||
init = function() vim.keymap.set("n", "<leader>na", "<cmd>Navbuddy<cr>") end,
|
|
||||||
config = true,
|
|
||||||
opts = {
|
|
||||||
icons = require "ui.navic_icons",
|
|
||||||
window = {
|
|
||||||
border = "none",
|
|
||||||
size = "80%",
|
|
||||||
sections = {
|
|
||||||
left = { border = "rounded" },
|
|
||||||
mid = { border = "rounded" },
|
|
||||||
right = { border = "rounded", preview = "leaf" },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
node_markers = {
|
|
||||||
enabled = true,
|
|
||||||
icons = {
|
|
||||||
leaf = " ",
|
|
||||||
leaf_selected = " → ",
|
|
||||||
branch = " ",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
return {
|
|
||||||
"SmiteshP/nvim-navic",
|
|
||||||
dependencies = "neovim/nvim-lspconfig",
|
|
||||||
lazy = true,
|
|
||||||
config = true,
|
|
||||||
opts = {
|
|
||||||
safe_output = true,
|
|
||||||
click = true,
|
|
||||||
icons = require "ui.navic_icons",
|
|
||||||
},
|
|
||||||
}
|
|
|
@ -1,28 +0,0 @@
|
||||||
return {
|
|
||||||
"klen/nvim-test",
|
|
||||||
cmd = {
|
|
||||||
"TestFile",
|
|
||||||
"TestEdit",
|
|
||||||
"TestNearest",
|
|
||||||
"TestLast",
|
|
||||||
"TestVisit",
|
|
||||||
"TestInfo",
|
|
||||||
"TestSuite",
|
|
||||||
},
|
|
||||||
init = function()
|
|
||||||
vim.keymap.set("n", "<leader>ts", "<cmd>TestSuite<cr>")
|
|
||||||
vim.keymap.set("n", "<leader>tf", "<cmd>TestFile<cr>")
|
|
||||||
vim.keymap.set("n", "<leader>te", "<cmd>TestEdit<cr>")
|
|
||||||
vim.keymap.set("n", "<leader>tn", "<cmd>TestNearest<cr>")
|
|
||||||
vim.keymap.set("n", "<leader>tl", "<cmd>TestLast<cr>")
|
|
||||||
vim.keymap.set("n", "<leader>tv", "<cmd>TestVisit<cr>")
|
|
||||||
vim.keymap.set("n", "<leader>ti", "<cmd>TestInfo<cr>")
|
|
||||||
end,
|
|
||||||
config = true,
|
|
||||||
otps = {
|
|
||||||
termOpts = {
|
|
||||||
direction = "horizontal",
|
|
||||||
keep_one = true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
return {
|
|
||||||
"ahmedkhalf/project.nvim",
|
|
||||||
name = "project_nvim",
|
|
||||||
event = { "BufEnter" },
|
|
||||||
config = true,
|
|
||||||
opts = {
|
|
||||||
ignore_lsp = { "efm", "null-ls" },
|
|
||||||
show_hidden = true,
|
|
||||||
silent_chdir = true,
|
|
||||||
},
|
|
||||||
}
|
|
|
@ -1,61 +0,0 @@
|
||||||
return {
|
|
||||||
"nvim-telescope/telescope.nvim",
|
|
||||||
branch = "0.1.x",
|
|
||||||
dependencies = {
|
|
||||||
{
|
|
||||||
"nvim-lua/plenary.nvim",
|
|
||||||
{ "nvim-telescope/telescope-fzf-native.nvim", build = "make" },
|
|
||||||
{ "tsakirist/telescope-lazy.nvim", dependencies = { "folke/lazy.nvim" } },
|
|
||||||
"folke/noice.nvim",
|
|
||||||
{ "benfowler/telescope-luasnip.nvim", dependencies = { "L3MON4D3/LuaSnip" } },
|
|
||||||
{
|
|
||||||
"paopaol/telescope-git-diffs.nvim",
|
|
||||||
dependencies = { "nvim-lua/plenary.nvim", "sindrets/diffview.nvim" },
|
|
||||||
},
|
|
||||||
"FeiyouG/command_center.nvim",
|
|
||||||
{ "barrett-ruth/telescope-http.nvim", dependencies = { "savq/paq-nvim" } },
|
|
||||||
"aaronhallaert/advanced-git-search.nvim",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
cmd = "Telescope",
|
|
||||||
init = function()
|
|
||||||
vim.keymap.set("n", "<leader>;", "<cmd>Telescope builtin<cr>")
|
|
||||||
vim.keymap.set("n", "<leader>ff", "<cmd>Telescope find_files<cr>")
|
|
||||||
vim.keymap.set("n", "<leader>fr", "<cmd>Telescope oldfiles<cr>")
|
|
||||||
vim.keymap.set("n", "<leader>fg", "<cmd>Telescope live_grep<cr>")
|
|
||||||
vim.keymap.set("n", "<leader>fb", "<cmd>Telescope buffers<cr>")
|
|
||||||
vim.keymap.set("n", "<leader>fs", "<cmd>Telescope lsp_document_symbols<cr>")
|
|
||||||
vim.keymap.set("n", "<leader>fe", "<cmd>Telescope diagnostics<cr>")
|
|
||||||
vim.keymap.set("n", "<leader>ft", "<cmd>Telescope treesitter<cr>")
|
|
||||||
vim.keymap.set("n", "<leader>fz", "<cmd>Telescope current_buffer_fuzzy_find<cr>")
|
|
||||||
end,
|
|
||||||
config = function()
|
|
||||||
local trouble = require "trouble.providers.telescope"
|
|
||||||
require("telescope").setup {
|
|
||||||
defaults = {
|
|
||||||
layout_strategy = "flex",
|
|
||||||
mappings = {
|
|
||||||
i = { ["<c-t>"] = trouble.open_with_trouble },
|
|
||||||
n = { ["<c-t>"] = trouble.open_with_trouble },
|
|
||||||
},
|
|
||||||
winblend = vim.o.winblend,
|
|
||||||
},
|
|
||||||
extensions = {
|
|
||||||
fzf = {
|
|
||||||
fuzzy = true, -- false will only do exact matching
|
|
||||||
override_generic_sorter = true, -- override the generic sorter
|
|
||||||
override_file_sorter = true, -- override the file sorter
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
require("telescope").load_extension "fzf"
|
|
||||||
require("telescope").load_extension "lazy"
|
|
||||||
require("telescope").load_extension "noice"
|
|
||||||
require("telescope").load_extension "luasnip"
|
|
||||||
require("telescope").load_extension "git_diffs"
|
|
||||||
require("telescope").load_extension "command_center"
|
|
||||||
require("telescope").load_extension "http"
|
|
||||||
require("telescope").load_extension "advanced_git_search"
|
|
||||||
require("telescope").load_extension "projects"
|
|
||||||
end,
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
return {
|
|
||||||
"akinsho/toggleterm.nvim",
|
|
||||||
version = "*",
|
|
||||||
cmd = { "ToggleTerm" },
|
|
||||||
init = function() vim.keymap.set("n", "<leader>tt", "<cmd>ToggleTerm direction=horizontal<CR>") end,
|
|
||||||
config = true,
|
|
||||||
}
|
|
|
@ -1,51 +0,0 @@
|
||||||
return {
|
|
||||||
"nvim-treesitter/nvim-treesitter",
|
|
||||||
event = { "BufReadPre", "BufNewFile" },
|
|
||||||
dependencies = { "nvim-treesitter/nvim-treesitter-refactor" },
|
|
||||||
config = function(_, opts)
|
|
||||||
if type(opts.ensure_installed) == "table" then
|
|
||||||
-- @type table<string, boolean>
|
|
||||||
local added = {}
|
|
||||||
opts.ensure_installed = vim.tbl_filter(function(lang)
|
|
||||||
if added[lang] then return false end
|
|
||||||
added[lang] = true
|
|
||||||
return true
|
|
||||||
end, opts.ensure_installed)
|
|
||||||
end
|
|
||||||
require("nvim-treesitter.configs").setup(opts)
|
|
||||||
end,
|
|
||||||
opts = {
|
|
||||||
ensure_installed = "all",
|
|
||||||
auto_install = true,
|
|
||||||
highlight = {
|
|
||||||
enable = true,
|
|
||||||
additional_vim_regex_highlighting = false,
|
|
||||||
},
|
|
||||||
incremental_selection = {
|
|
||||||
enable = true,
|
|
||||||
keymaps = {
|
|
||||||
init_selection = "gnn",
|
|
||||||
node_incremental = "gnr",
|
|
||||||
scope_incremental = "gnc",
|
|
||||||
node_decremental = "gnm",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
indent = {
|
|
||||||
enable = true,
|
|
||||||
},
|
|
||||||
refactor = {
|
|
||||||
smart_rename = {
|
|
||||||
enable = true,
|
|
||||||
keymaps = {
|
|
||||||
smart_rename = "grr",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
navigation = {
|
|
||||||
enable = true,
|
|
||||||
keymaps = {
|
|
||||||
goto_definition_lsp_fallback = "gnd",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
|
@ -1,20 +0,0 @@
|
||||||
return {
|
|
||||||
"folke/trouble.nvim",
|
|
||||||
dependencies = "nvim-tree/nvim-web-devicons",
|
|
||||||
cmd = "TroubleToggle",
|
|
||||||
init = function()
|
|
||||||
vim.keymap.set("n", "<leader>xx", "<cmd>TroubleToggle<cr>")
|
|
||||||
vim.keymap.set("n", "<leader>xw", "<cmd>TroubleToggle workspace_diagnostics<cr>")
|
|
||||||
vim.keymap.set("n", "<leader>xd", "<cmd>TroubleToggle document_diagnostics<cr>")
|
|
||||||
vim.keymap.set("n", "<leader>xq", "<cmd>TroubleToggle quickfix<cr>")
|
|
||||||
vim.keymap.set("n", "<leader>xl", "<cmd>TroubleToggle loclist<cr>")
|
|
||||||
end,
|
|
||||||
config = true,
|
|
||||||
opts = {
|
|
||||||
mode = "workspace_diagnostics",
|
|
||||||
auto_open = false,
|
|
||||||
auto_close = false,
|
|
||||||
auto_preview = true,
|
|
||||||
auto_jump = { "lsp_definitions", "lsp_references", "lsp_implementations" },
|
|
||||||
},
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
return {
|
|
||||||
"folke/twilight.nvim",
|
|
||||||
dependencies = { "nvim-treesitter" },
|
|
||||||
cmd = "Twilight",
|
|
||||||
config = true,
|
|
||||||
opts = { context = 10, treesitter = true },
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
return {
|
|
||||||
"folke/which-key.nvim",
|
|
||||||
config = function()
|
|
||||||
vim.o.timeout = true
|
|
||||||
vim.o.timeoutlen = 300
|
|
||||||
require("which-key").setup {}
|
|
||||||
end,
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
return {
|
|
||||||
"folke/zen-mode.nvim",
|
|
||||||
dependencies = { "folke/twilight.nvim" },
|
|
||||||
cmd = { "ZenMode" },
|
|
||||||
init = function() vim.keymap.set("n", "<leader>z", "<cmd>ZenMode<CR>") end,
|
|
||||||
config = true,
|
|
||||||
opts = {
|
|
||||||
window = {
|
|
||||||
options = {
|
|
||||||
signcolumn = "no", -- disable signcolumn
|
|
||||||
number = false, -- disable number column
|
|
||||||
relativenumber = false, -- disable relative numbers
|
|
||||||
cursorline = false, -- disable cursorline
|
|
||||||
cursorcolumn = false, -- disable cursor column
|
|
||||||
foldcolumn = "0", -- disable fold column
|
|
||||||
list = false, -- disable whitespace characters
|
|
||||||
},
|
|
||||||
},
|
|
||||||
plugins = {
|
|
||||||
options = {
|
|
||||||
enabled = true,
|
|
||||||
},
|
|
||||||
twilight = { enabled = true },
|
|
||||||
gitsigns = { enabled = true },
|
|
||||||
tmux = { enabled = true },
|
|
||||||
},
|
|
||||||
on_open = function(win) vim.wo.scrolloff = 999 end,
|
|
||||||
on_close = function(win) vim.wo.scrolloff = 0 end,
|
|
||||||
},
|
|
||||||
}
|
|
|
@ -1,478 +0,0 @@
|
||||||
local M = {}
|
|
||||||
|
|
||||||
local C = require("catppuccin.palettes").get_palette()
|
|
||||||
local lsp = require "feline.providers.lsp"
|
|
||||||
|
|
||||||
local assets = {
|
|
||||||
left_separator = "",
|
|
||||||
right_separator = "",
|
|
||||||
mode_icon = "",
|
|
||||||
dir = "",
|
|
||||||
file = "",
|
|
||||||
lsp = {
|
|
||||||
server = "",
|
|
||||||
error = "",
|
|
||||||
warning = "",
|
|
||||||
info = "",
|
|
||||||
hint = "",
|
|
||||||
},
|
|
||||||
git = {
|
|
||||||
branch = "",
|
|
||||||
added = "",
|
|
||||||
changed = "",
|
|
||||||
removed = "",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
local sett = {
|
|
||||||
text = C.surface0,
|
|
||||||
bkg = C.surface0,
|
|
||||||
diffs = C.mauve,
|
|
||||||
extras = C.overlay1,
|
|
||||||
curr_file = C.maroon,
|
|
||||||
curr_dir = C.flamingo,
|
|
||||||
show_modified = false,
|
|
||||||
}
|
|
||||||
|
|
||||||
if require("catppuccin").flavour == "latte" then
|
|
||||||
local latte = require("catppuccin.palettes").get_palette "latte"
|
|
||||||
sett.text = latte.base
|
|
||||||
sett.bkg = latte.crust
|
|
||||||
end
|
|
||||||
|
|
||||||
if require("catppuccin").options.transparent_background then sett.bkg = "NONE" end
|
|
||||||
|
|
||||||
local mode_colors = {
|
|
||||||
["n"] = { "NORMAL", C.lavender },
|
|
||||||
["no"] = { "N-PENDING", C.lavender },
|
|
||||||
["i"] = { "INSERT", C.green },
|
|
||||||
["ic"] = { "INSERT", C.green },
|
|
||||||
["t"] = { "TERMINAL", C.green },
|
|
||||||
["v"] = { "VISUAL", C.flamingo },
|
|
||||||
["V"] = { "V-LINE", C.flamingo },
|
|
||||||
[""] = { "V-BLOCK", C.flamingo },
|
|
||||||
["R"] = { "REPLACE", C.maroon },
|
|
||||||
["Rv"] = { "V-REPLACE", C.maroon },
|
|
||||||
["s"] = { "SELECT", C.maroon },
|
|
||||||
["S"] = { "S-LINE", C.maroon },
|
|
||||||
[""] = { "S-BLOCK", C.maroon },
|
|
||||||
["c"] = { "COMMAND", C.peach },
|
|
||||||
["cv"] = { "COMMAND", C.peach },
|
|
||||||
["ce"] = { "COMMAND", C.peach },
|
|
||||||
["r"] = { "PROMPT", C.teal },
|
|
||||||
["rm"] = { "MORE", C.teal },
|
|
||||||
["r?"] = { "CONFIRM", C.mauve },
|
|
||||||
["!"] = { "SHELL", C.green },
|
|
||||||
}
|
|
||||||
|
|
||||||
function M.setup(opts)
|
|
||||||
if opts then
|
|
||||||
opts.assets = opts.assets or {}
|
|
||||||
opts.sett = opts.sett or {}
|
|
||||||
opts.mode_colors = opts.mode_colors or {}
|
|
||||||
else
|
|
||||||
opts = {}
|
|
||||||
end
|
|
||||||
assets = vim.tbl_deep_extend("force", assets, opts.assets)
|
|
||||||
sett = vim.tbl_deep_extend("force", sett, opts.sett)
|
|
||||||
mode_colors = vim.tbl_deep_extend("force", mode_colors, opts.mode_colors)
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.get()
|
|
||||||
local shortline = false
|
|
||||||
|
|
||||||
local components = {
|
|
||||||
active = { {}, {} }, -- left, right
|
|
||||||
inactive = { {} },
|
|
||||||
}
|
|
||||||
|
|
||||||
local function is_enabled(min_width)
|
|
||||||
if shortline then return true end
|
|
||||||
|
|
||||||
return vim.api.nvim_win_get_width(0) > min_width
|
|
||||||
end
|
|
||||||
|
|
||||||
-- global components
|
|
||||||
local invi_sep = {
|
|
||||||
str = " ",
|
|
||||||
hl = {
|
|
||||||
fg = sett.bkg,
|
|
||||||
bg = sett.bkg,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
-- helpers
|
|
||||||
local function any_git_changes()
|
|
||||||
local gst = vim.b.gitsigns_status_dict -- git stats
|
|
||||||
if gst then
|
|
||||||
if
|
|
||||||
gst["added"] and gst["added"] > 0
|
|
||||||
or gst["removed"] and gst["removed"] > 0
|
|
||||||
or gst["changed"] and gst["changed"] > 0
|
|
||||||
then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
-- #################### STATUSLINE ->
|
|
||||||
|
|
||||||
-- ######## Left
|
|
||||||
|
|
||||||
-- Current vi mode ------>
|
|
||||||
local vi_mode_hl = function()
|
|
||||||
return {
|
|
||||||
fg = sett.text,
|
|
||||||
bg = mode_colors[vim.fn.mode()][2],
|
|
||||||
style = "bold",
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
components.active[1][1] = {
|
|
||||||
provider = " " .. assets.mode_icon .. " ",
|
|
||||||
hl = function()
|
|
||||||
return {
|
|
||||||
fg = sett.text,
|
|
||||||
bg = mode_colors[vim.fn.mode()][2],
|
|
||||||
}
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
|
|
||||||
components.active[1][2] = {
|
|
||||||
provider = function() return mode_colors[vim.fn.mode()][1] .. " " end,
|
|
||||||
hl = vi_mode_hl,
|
|
||||||
}
|
|
||||||
|
|
||||||
-- there is a dilema: we need to hide Diffs if ther is no git info. We can do that, but this will
|
|
||||||
-- leave the right_separator colored with purple, and since we can't change the color conditonally
|
|
||||||
-- then the solution is to create two right_separators: one with a mauve sett.bkg and the other one normal
|
|
||||||
-- sett.bkg; both have the same fg (vi mode). The mauve one appears if there is git info, else the one with
|
|
||||||
-- the normal sett.bkg appears. Fixed :)
|
|
||||||
|
|
||||||
-- enable if git diffs are not available
|
|
||||||
components.active[1][3] = {
|
|
||||||
provider = assets.right_separator,
|
|
||||||
hl = function()
|
|
||||||
return {
|
|
||||||
fg = mode_colors[vim.fn.mode()][2],
|
|
||||||
bg = sett.bkg,
|
|
||||||
}
|
|
||||||
end,
|
|
||||||
enabled = function() return not any_git_changes() end,
|
|
||||||
}
|
|
||||||
|
|
||||||
-- enable if git diffs are available
|
|
||||||
components.active[1][4] = {
|
|
||||||
provider = assets.right_separator,
|
|
||||||
hl = function()
|
|
||||||
return {
|
|
||||||
fg = mode_colors[vim.fn.mode()][2],
|
|
||||||
bg = sett.diffs,
|
|
||||||
}
|
|
||||||
end,
|
|
||||||
enabled = function() return any_git_changes() end,
|
|
||||||
}
|
|
||||||
-- Current vi mode ------>
|
|
||||||
|
|
||||||
-- Diffs ------>
|
|
||||||
components.active[1][5] = {
|
|
||||||
provider = "git_diff_added",
|
|
||||||
hl = {
|
|
||||||
fg = sett.text,
|
|
||||||
bg = sett.diffs,
|
|
||||||
},
|
|
||||||
icon = " " .. assets.git.added .. " ",
|
|
||||||
}
|
|
||||||
|
|
||||||
components.active[1][6] = {
|
|
||||||
provider = "git_diff_changed",
|
|
||||||
hl = {
|
|
||||||
fg = sett.text,
|
|
||||||
bg = sett.diffs,
|
|
||||||
},
|
|
||||||
icon = " " .. assets.git.changed .. " ",
|
|
||||||
}
|
|
||||||
|
|
||||||
components.active[1][7] = {
|
|
||||||
provider = "git_diff_removed",
|
|
||||||
hl = {
|
|
||||||
fg = sett.text,
|
|
||||||
bg = sett.diffs,
|
|
||||||
},
|
|
||||||
icon = " " .. assets.git.removed .. " ",
|
|
||||||
}
|
|
||||||
|
|
||||||
components.active[1][8] = {
|
|
||||||
provider = " ",
|
|
||||||
hl = {
|
|
||||||
fg = sett.bkg,
|
|
||||||
bg = sett.diffs,
|
|
||||||
},
|
|
||||||
enabled = function() return any_git_changes() end,
|
|
||||||
}
|
|
||||||
|
|
||||||
components.active[1][9] = {
|
|
||||||
provider = assets.right_separator,
|
|
||||||
hl = {
|
|
||||||
fg = sett.diffs,
|
|
||||||
bg = sett.bkg,
|
|
||||||
},
|
|
||||||
enabled = function() return any_git_changes() end,
|
|
||||||
}
|
|
||||||
-- Diffs ------>
|
|
||||||
|
|
||||||
-- Extras ------>
|
|
||||||
|
|
||||||
-- file progess
|
|
||||||
components.active[1][10] = {
|
|
||||||
provider = function()
|
|
||||||
local current_line = vim.fn.line "."
|
|
||||||
local total_line = vim.fn.line "$"
|
|
||||||
|
|
||||||
if current_line == 1 then
|
|
||||||
return "Top"
|
|
||||||
elseif current_line == vim.fn.line "$" then
|
|
||||||
return "Bot"
|
|
||||||
end
|
|
||||||
local result, _ = math.modf((current_line / total_line) * 100)
|
|
||||||
return result .. "%%"
|
|
||||||
end,
|
|
||||||
-- enabled = shortline or function(winid)
|
|
||||||
-- return vim.api.nvim_win_get_width(winid) > 90
|
|
||||||
-- end,
|
|
||||||
hl = {
|
|
||||||
fg = sett.extras,
|
|
||||||
bg = sett.bkg,
|
|
||||||
},
|
|
||||||
left_sep = invi_sep,
|
|
||||||
}
|
|
||||||
|
|
||||||
-- position
|
|
||||||
components.active[1][11] = {
|
|
||||||
provider = "position",
|
|
||||||
-- enabled = shortline or function(winid)
|
|
||||||
-- return vim.api.nvim_win_get_width(winid) > 90
|
|
||||||
-- end,
|
|
||||||
hl = {
|
|
||||||
fg = sett.extras,
|
|
||||||
bg = sett.bkg,
|
|
||||||
},
|
|
||||||
left_sep = invi_sep,
|
|
||||||
}
|
|
||||||
|
|
||||||
-- macro
|
|
||||||
components.active[1][12] = {
|
|
||||||
provider = "macro",
|
|
||||||
enabled = function() return vim.api.nvim_get_option "cmdheight" == 0 end,
|
|
||||||
hl = {
|
|
||||||
fg = sett.extras,
|
|
||||||
bg = sett.bkg,
|
|
||||||
},
|
|
||||||
left_sep = invi_sep,
|
|
||||||
}
|
|
||||||
|
|
||||||
-- search count
|
|
||||||
components.active[1][13] = {
|
|
||||||
provider = "search_count",
|
|
||||||
enabled = function() return vim.api.nvim_get_option "cmdheight" == 0 end,
|
|
||||||
hl = {
|
|
||||||
fg = sett.extras,
|
|
||||||
bg = sett.bkg,
|
|
||||||
},
|
|
||||||
left_sep = invi_sep,
|
|
||||||
}
|
|
||||||
-- Extras ------>
|
|
||||||
|
|
||||||
-- ######## Left
|
|
||||||
-- treesitter position
|
|
||||||
-- components.active[1][14] = {
|
|
||||||
-- provider = function()
|
|
||||||
-- -- if not require("vim.treesitter.language").require_language("lua") then
|
|
||||||
-- -- return ""
|
|
||||||
-- -- end
|
|
||||||
-- local pos = require("nvim-treesitter").statusline {
|
|
||||||
-- indicator_size = 50,
|
|
||||||
-- transform_fn = function(line) return line:gsub("%s*[%[%(%{]+.*$", "") end,
|
|
||||||
-- }
|
|
||||||
-- if pos and pos ~= "" then return pos end
|
|
||||||
-- return ""
|
|
||||||
-- end,
|
|
||||||
-- hl = {
|
|
||||||
-- fg = sett.extras,
|
|
||||||
-- bg = sett.bkg,
|
|
||||||
-- },
|
|
||||||
-- left_sep = invi_sep,
|
|
||||||
-- }
|
|
||||||
|
|
||||||
-- ######## Right
|
|
||||||
|
|
||||||
-- Diagnostics ------>
|
|
||||||
-- workspace loader
|
|
||||||
components.active[2][1] = {
|
|
||||||
provider = function()
|
|
||||||
local Lsp = vim.lsp.util.get_progress_messages()[1]
|
|
||||||
|
|
||||||
if Lsp then
|
|
||||||
local msg = Lsp.message or ""
|
|
||||||
local percentage = Lsp.percentage
|
|
||||||
if not percentage then return "" end
|
|
||||||
local title = Lsp.title or ""
|
|
||||||
local spinners = {
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
}
|
|
||||||
local success_icon = {
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
}
|
|
||||||
local ms = vim.loop.hrtime() / 1000000
|
|
||||||
local frame = math.floor(ms / 120) % #spinners
|
|
||||||
|
|
||||||
if percentage >= 70 then
|
|
||||||
return string.format(" %%<%s %s %s (%s%%%%) ", success_icon[frame + 1], title, msg, percentage)
|
|
||||||
end
|
|
||||||
|
|
||||||
return string.format(" %%<%s %s %s (%s%%%%) ", spinners[frame + 1], title, msg, percentage)
|
|
||||||
end
|
|
||||||
|
|
||||||
return ""
|
|
||||||
end,
|
|
||||||
enabled = is_enabled(80),
|
|
||||||
hl = {
|
|
||||||
fg = sett.extras,
|
|
||||||
bg = sett.bkg,
|
|
||||||
},
|
|
||||||
right_sep = invi_sep,
|
|
||||||
}
|
|
||||||
|
|
||||||
components.active[2][2] = {
|
|
||||||
provider = "git_branch",
|
|
||||||
enabled = is_enabled(70),
|
|
||||||
hl = {
|
|
||||||
fg = sett.extras,
|
|
||||||
bg = sett.bkg,
|
|
||||||
},
|
|
||||||
icon = assets.git.branch .. " ",
|
|
||||||
right_sep = invi_sep,
|
|
||||||
}
|
|
||||||
|
|
||||||
components.active[2][3] = {
|
|
||||||
provider = function()
|
|
||||||
if next(vim.lsp.buf_get_clients()) ~= nil then
|
|
||||||
return assets.lsp.server .. " " .. "Lsp"
|
|
||||||
else
|
|
||||||
return ""
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
hl = {
|
|
||||||
fg = sett.extras,
|
|
||||||
bg = sett.bkg,
|
|
||||||
},
|
|
||||||
right_sep = invi_sep,
|
|
||||||
}
|
|
||||||
|
|
||||||
-- genral diagnostics (errors, warnings. info and hints)
|
|
||||||
components.active[2][4] = {
|
|
||||||
provider = "diagnostic_errors",
|
|
||||||
enabled = function() return lsp.diagnostics_exist(vim.diagnostic.severity.ERROR) end,
|
|
||||||
|
|
||||||
hl = {
|
|
||||||
fg = C.red,
|
|
||||||
bg = sett.bkg,
|
|
||||||
},
|
|
||||||
icon = " " .. assets.lsp.error .. " ",
|
|
||||||
right_sep = invi_sep,
|
|
||||||
}
|
|
||||||
|
|
||||||
components.active[2][5] = {
|
|
||||||
provider = "diagnostic_warnings",
|
|
||||||
enabled = function() return lsp.diagnostics_exist(vim.diagnostic.severity.WARN) end,
|
|
||||||
hl = {
|
|
||||||
fg = C.yellow,
|
|
||||||
bg = sett.bkg,
|
|
||||||
},
|
|
||||||
icon = " " .. assets.lsp.warning .. " ",
|
|
||||||
right_sep = invi_sep,
|
|
||||||
}
|
|
||||||
|
|
||||||
components.active[2][6] = {
|
|
||||||
provider = "diagnostic_info",
|
|
||||||
enabled = function() return lsp.diagnostics_exist(vim.diagnostic.severity.INFO) end,
|
|
||||||
hl = {
|
|
||||||
fg = C.sky,
|
|
||||||
bg = sett.bkg,
|
|
||||||
},
|
|
||||||
icon = " " .. assets.lsp.info .. " ",
|
|
||||||
right_sep = invi_sep,
|
|
||||||
}
|
|
||||||
|
|
||||||
components.active[2][7] = {
|
|
||||||
provider = "diagnostic_hints",
|
|
||||||
enabled = function() return lsp.diagnostics_exist(vim.diagnostic.severity.HINT) end,
|
|
||||||
hl = {
|
|
||||||
fg = C.rosewater,
|
|
||||||
bg = sett.bkg,
|
|
||||||
},
|
|
||||||
icon = " " .. assets.lsp.hint .. " ",
|
|
||||||
right_sep = invi_sep,
|
|
||||||
}
|
|
||||||
-- Diagnostics ------>
|
|
||||||
|
|
||||||
components.active[2][8] = {
|
|
||||||
provider = function()
|
|
||||||
local filename = vim.fn.expand "%:t"
|
|
||||||
local extension = vim.fn.expand "%:e"
|
|
||||||
local present, icons = pcall(require, "nvim-web-devicons")
|
|
||||||
local icon = present and icons.get_icon(filename, extension) or assets.file
|
|
||||||
return (sett.show_modified and "%m" or "") .. " " .. icon .. " " .. filename .. " "
|
|
||||||
end,
|
|
||||||
enabled = is_enabled(70),
|
|
||||||
hl = {
|
|
||||||
fg = sett.text,
|
|
||||||
bg = sett.curr_file,
|
|
||||||
},
|
|
||||||
left_sep = {
|
|
||||||
str = assets.left_separator,
|
|
||||||
hl = {
|
|
||||||
fg = sett.curr_file,
|
|
||||||
bg = sett.bkg,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
components.active[2][9] = {
|
|
||||||
provider = function()
|
|
||||||
local dir_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":t")
|
|
||||||
return " " .. assets.dir .. " " .. dir_name .. " "
|
|
||||||
end,
|
|
||||||
enabled = is_enabled(80),
|
|
||||||
hl = {
|
|
||||||
fg = sett.text,
|
|
||||||
bg = sett.curr_dir,
|
|
||||||
},
|
|
||||||
left_sep = {
|
|
||||||
str = assets.left_separator,
|
|
||||||
hl = {
|
|
||||||
fg = sett.curr_dir,
|
|
||||||
bg = sett.curr_file,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
-- ######## Right
|
|
||||||
|
|
||||||
-- Inanctive components
|
|
||||||
components.inactive[1][1] = {
|
|
||||||
provider = function() return " " .. string.upper(vim.bo.ft) .. " " end,
|
|
||||||
hl = {
|
|
||||||
fg = C.overlay2,
|
|
||||||
bg = C.mantle,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
return components
|
|
||||||
end
|
|
||||||
|
|
||||||
return M
|
|
|
@ -1,9 +0,0 @@
|
||||||
vim.opt.fillchars:append {
|
|
||||||
horiz = "━",
|
|
||||||
horizup = "┻",
|
|
||||||
horizdown = "┳",
|
|
||||||
vert = "┃",
|
|
||||||
vertleft = "┨",
|
|
||||||
vertright = "┣",
|
|
||||||
verthoriz = "╋",
|
|
||||||
}
|
|
|
@ -1,28 +0,0 @@
|
||||||
return {
|
|
||||||
File = " ",
|
|
||||||
Module = " ",
|
|
||||||
Namespace = " ",
|
|
||||||
Package = " ",
|
|
||||||
Class = " ",
|
|
||||||
Method = " ",
|
|
||||||
Property = " ",
|
|
||||||
Field = " ",
|
|
||||||
Constructor = " ",
|
|
||||||
Enum = " ",
|
|
||||||
Interface = " ",
|
|
||||||
Function = " ",
|
|
||||||
Variable = " ",
|
|
||||||
Constant = " ",
|
|
||||||
String = " ",
|
|
||||||
Number = " ",
|
|
||||||
Boolean = " ",
|
|
||||||
Array = " ",
|
|
||||||
Object = " ",
|
|
||||||
Key = " ",
|
|
||||||
Null = " ",
|
|
||||||
EnumMember = " ",
|
|
||||||
Struct = " ",
|
|
||||||
Event = " ",
|
|
||||||
Operator = " ",
|
|
||||||
TypeParameter = " ",
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# usage: import-gsettings
|
|
||||||
config="${XDG_CONFIG_HOME:-$HOME/.config}/gtk-3.0/settings.ini"
|
|
||||||
if [ ! -f "$config" ]; then exit 1; fi
|
|
||||||
|
|
||||||
gnome_schema="org.gnome.desktop.interface"
|
|
||||||
gtk_theme="$(grep 'gtk-theme-name' "$config" | sed 's/.*\s*=\s*//')"
|
|
||||||
icon_theme="$(grep 'gtk-icon-theme-name' "$config" | sed 's/.*\s*=\s*//')"
|
|
||||||
cursor_theme="$(grep 'gtk-cursor-theme-name' "$config" | sed 's/.*\s*=\s*//')"
|
|
||||||
font_name="$(grep 'gtk-font-name' "$config" | sed 's/.*\s*=\s*//')"
|
|
||||||
gsettings set "$gnome_schema" gtk-theme "$gtk_theme"
|
|
||||||
gsettings set "$gnome_schema" icon-theme "$icon_theme"
|
|
||||||
gsettings set "$gnome_schema" cursor-theme "$cursor_theme"
|
|
||||||
gsettings set "$gnome_schema" font-name "$font_name"
|
|
|
@ -1,109 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
#
|
|
||||||
# A good old bash | curl script for direnv.
|
|
||||||
#
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
{ # Prevent execution if this script was only partially downloaded
|
|
||||||
|
|
||||||
log() {
|
|
||||||
echo "[installer] $*" >&2
|
|
||||||
}
|
|
||||||
|
|
||||||
die() {
|
|
||||||
log "$@"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
at_exit() {
|
|
||||||
ret=$?
|
|
||||||
if [[ $ret -gt 0 ]]; then
|
|
||||||
log "the script failed with error $ret.\n" \
|
|
||||||
"\n" \
|
|
||||||
"To report installation errors, submit an issue to\n" \
|
|
||||||
" https://github.com/direnv/direnv/issues/new/choose"
|
|
||||||
fi
|
|
||||||
exit "$ret"
|
|
||||||
}
|
|
||||||
trap at_exit EXIT
|
|
||||||
|
|
||||||
kernel=$(uname -s | tr "[:upper:]" "[:lower:]")
|
|
||||||
case "${kernel}" in
|
|
||||||
mingw*)
|
|
||||||
kernel=windows
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
case "$(uname -m)" in
|
|
||||||
x86_64)
|
|
||||||
machine=amd64
|
|
||||||
;;
|
|
||||||
i686 | i386)
|
|
||||||
machine=386
|
|
||||||
;;
|
|
||||||
aarch64 | arm64)
|
|
||||||
machine=arm64
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
die "Machine $(uname -m) not supported by the installer.\n" \
|
|
||||||
"Go to https://direnv for alternate installation methods."
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
log "kernel=$kernel machine=$machine"
|
|
||||||
|
|
||||||
: "${use_sudo:=}"
|
|
||||||
: "${bin_path:=}"
|
|
||||||
|
|
||||||
if [[ -z "$bin_path" ]]; then
|
|
||||||
log "bin_path is not set, you can set bin_path to specify the installation path"
|
|
||||||
log "e.g. export bin_path=/path/to/installation before installing"
|
|
||||||
log "looking for a writeable path from PATH environment variable"
|
|
||||||
for path in $(echo "$PATH" | tr ':' '\n'); do
|
|
||||||
if [[ -w $path ]]; then
|
|
||||||
bin_path=$path
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
if [[ -z "$bin_path" ]]; then
|
|
||||||
die "did not find a writeable path in $PATH"
|
|
||||||
fi
|
|
||||||
echo "bin_path=$bin_path"
|
|
||||||
|
|
||||||
if [[ -n "${version:-}" ]]; then
|
|
||||||
release="tags/${version}"
|
|
||||||
else
|
|
||||||
release="latest"
|
|
||||||
fi
|
|
||||||
echo "release=$release"
|
|
||||||
|
|
||||||
log "looking for a download URL"
|
|
||||||
download_url=$(
|
|
||||||
curl -fL "https://api.github.com/repos/direnv/direnv/releases/$release" \
|
|
||||||
| grep browser_download_url \
|
|
||||||
| cut -d '"' -f 4 \
|
|
||||||
| grep "direnv.$kernel.$machine"
|
|
||||||
)
|
|
||||||
echo "download_url=$download_url"
|
|
||||||
|
|
||||||
log "downloading"
|
|
||||||
curl -o "$bin_path/direnv" -fL "$download_url"
|
|
||||||
chmod a+x "$bin_path/direnv"
|
|
||||||
|
|
||||||
cat <<DONE
|
|
||||||
|
|
||||||
The direnv binary is now available in:
|
|
||||||
|
|
||||||
$bin_path/direnv
|
|
||||||
|
|
||||||
The last step is to configure your shell to use it. For example for bash, add
|
|
||||||
the following lines at the end of your ~/.bashrc:
|
|
||||||
|
|
||||||
eval "\$(direnv hook bash)"
|
|
||||||
|
|
||||||
Then restart the shell.
|
|
||||||
|
|
||||||
For other shells, see https://direnv.net/docs/hook.html
|
|
||||||
|
|
||||||
Thanks!
|
|
||||||
DONE
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
mkdir -p $HOME/.fonts
|
|
||||||
cd $HOME/.fonts
|
|
||||||
curl -sSLO https://github.com/ryanoasis/nerd-fonts/releases/download/v3.0.0/FiraCode.zip
|
|
||||||
unzip FiraCode.zip -d FiraCode
|
|
||||||
rm FiraCode.zip
|
|
||||||
fc-cache
|
|
|
@ -1,119 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# This script installs the Nix package manager on your system by
|
|
||||||
# downloading a binary distribution and running its installer script
|
|
||||||
# (which in turn creates and populates /nix).
|
|
||||||
|
|
||||||
{ # Prevent execution if this script was only partially downloaded
|
|
||||||
oops() {
|
|
||||||
echo "$0:" "$@" >&2
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
umask 0022
|
|
||||||
|
|
||||||
tmpDir="$(mktemp -d -t nix-binary-tarball-unpack.XXXXXXXXXX || \
|
|
||||||
oops "Can't create temporary directory for downloading the Nix binary tarball")"
|
|
||||||
cleanup() {
|
|
||||||
rm -rf "$tmpDir"
|
|
||||||
}
|
|
||||||
trap cleanup EXIT INT QUIT TERM
|
|
||||||
|
|
||||||
require_util() {
|
|
||||||
command -v "$1" > /dev/null 2>&1 ||
|
|
||||||
oops "you do not have '$1' installed, which I need to $2"
|
|
||||||
}
|
|
||||||
|
|
||||||
case "$(uname -s).$(uname -m)" in
|
|
||||||
Linux.x86_64)
|
|
||||||
hash=1bdf98f951ce82ad1a12b9e6874f5858cb2aa2e402907e8c3079d8482cb8430b
|
|
||||||
path=dw0gkcqnig9qwyhkrq0sjrzai63zi6wy/nix-2.15.0-x86_64-linux.tar.xz
|
|
||||||
system=x86_64-linux
|
|
||||||
;;
|
|
||||||
Linux.i?86)
|
|
||||||
hash=c868bed9bfff72a363b1a41f95bce971f8ccca111e5e3c9f8e2fa5e9bde91f75
|
|
||||||
path=ayl7z135hkqhf4px5pacv47b4njqb9yj/nix-2.15.0-i686-linux.tar.xz
|
|
||||||
system=i686-linux
|
|
||||||
;;
|
|
||||||
Linux.aarch64)
|
|
||||||
hash=3a08669bf8d27b5994fceb2bc4653fddab189832a8bd111d013591862eb45961
|
|
||||||
path=26zpxva102pm9jz8nkb391ws3c7six2j/nix-2.15.0-aarch64-linux.tar.xz
|
|
||||||
system=aarch64-linux
|
|
||||||
;;
|
|
||||||
Linux.armv6l)
|
|
||||||
hash=88736c6fda47d2c244d38ec81250111263c6756a5c9e5232fb56d5e1245f3aae
|
|
||||||
path=1m9il80f2y41qsarmarf3dkb23ryg2h8/nix-2.15.0-armv6l-linux.tar.xz
|
|
||||||
system=armv6l-linux
|
|
||||||
;;
|
|
||||||
Linux.armv7l)
|
|
||||||
hash=44010bc59ad7504274533daf5d23d6773a286c5b7ac87960d330cc0580149462
|
|
||||||
path=v2z7fhd4rq2n5s2svdk2dh6mf112w7ca/nix-2.15.0-armv7l-linux.tar.xz
|
|
||||||
system=armv7l-linux
|
|
||||||
;;
|
|
||||||
Darwin.x86_64)
|
|
||||||
hash=d8b6a6e89f82113fcbce3d946fa501d5d2cf7cb35c88fb2017f3c12ef8392e7d
|
|
||||||
path=m01jb6iyf73jiyzdn6vfap8da347nmwf/nix-2.15.0-x86_64-darwin.tar.xz
|
|
||||||
system=x86_64-darwin
|
|
||||||
;;
|
|
||||||
Darwin.arm64|Darwin.aarch64)
|
|
||||||
hash=2d4a8060e12077f174e0635ec06d94daeee0460166165414698dfdf0ef87915a
|
|
||||||
path=aa9fsy71mdsqp6kgf5sag6kv50zavhj5/nix-2.15.0-aarch64-darwin.tar.xz
|
|
||||||
system=aarch64-darwin
|
|
||||||
;;
|
|
||||||
*) oops "sorry, there is no binary distribution of Nix for your platform";;
|
|
||||||
esac
|
|
||||||
|
|
||||||
# Use this command-line option to fetch the tarballs using nar-serve or Cachix
|
|
||||||
if [ "${1:-}" = "--tarball-url-prefix" ]; then
|
|
||||||
if [ -z "${2:-}" ]; then
|
|
||||||
oops "missing argument for --tarball-url-prefix"
|
|
||||||
fi
|
|
||||||
url=${2}/${path}
|
|
||||||
shift 2
|
|
||||||
else
|
|
||||||
url=https://releases.nixos.org/nix/nix-2.15.0/nix-2.15.0-$system.tar.xz
|
|
||||||
fi
|
|
||||||
|
|
||||||
tarball=$tmpDir/nix-2.15.0-$system.tar.xz
|
|
||||||
|
|
||||||
require_util tar "unpack the binary tarball"
|
|
||||||
if [ "$(uname -s)" != "Darwin" ]; then
|
|
||||||
require_util xz "unpack the binary tarball"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if command -v curl > /dev/null 2>&1; then
|
|
||||||
fetch() { curl --fail -L "$1" -o "$2"; }
|
|
||||||
elif command -v wget > /dev/null 2>&1; then
|
|
||||||
fetch() { wget "$1" -O "$2"; }
|
|
||||||
else
|
|
||||||
oops "you don't have wget or curl installed, which I need to download the binary tarball"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "downloading Nix 2.15.0 binary tarball for $system from '$url' to '$tmpDir'..."
|
|
||||||
fetch "$url" "$tarball" || oops "failed to download '$url'"
|
|
||||||
|
|
||||||
if command -v sha256sum > /dev/null 2>&1; then
|
|
||||||
hash2="$(sha256sum -b "$tarball" | cut -c1-64)"
|
|
||||||
elif command -v shasum > /dev/null 2>&1; then
|
|
||||||
hash2="$(shasum -a 256 -b "$tarball" | cut -c1-64)"
|
|
||||||
elif command -v openssl > /dev/null 2>&1; then
|
|
||||||
hash2="$(openssl dgst -r -sha256 "$tarball" | cut -c1-64)"
|
|
||||||
else
|
|
||||||
oops "cannot verify the SHA-256 hash of '$url'; you need one of 'shasum', 'sha256sum', or 'openssl'"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$hash" != "$hash2" ]; then
|
|
||||||
oops "SHA-256 hash mismatch in '$url'; expected $hash, got $hash2"
|
|
||||||
fi
|
|
||||||
|
|
||||||
unpack=$tmpDir/unpack
|
|
||||||
mkdir -p "$unpack"
|
|
||||||
tar -xJf "$tarball" -C "$unpack" || oops "failed to unpack '$url'"
|
|
||||||
|
|
||||||
script=$(echo "$unpack"/*/install)
|
|
||||||
|
|
||||||
[ -e "$script" ] || oops "installation script is missing from the binary tarball!"
|
|
||||||
export INVOKED_FROM_INSTALL_IN=1
|
|
||||||
"$script" "$@"
|
|
||||||
|
|
||||||
} # End of wrapping
|
|
|
@ -1,9 +0,0 @@
|
||||||
curl -sSLO https://github.com/neovim/neovim/releases/download/stable/nvim.appimage
|
|
||||||
curl -sSLO https://github.com/neovim/neovim/releases/download/stable/nvim.appimage.sha256sum
|
|
||||||
sha256sum -c nvim.appimage.sha256sum || {
|
|
||||||
rm nvim.appimage nvim.appimage.sha256sum
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
rm nvim.appimage.sha256sum
|
|
||||||
chmod a+x nvim.appimage
|
|
||||||
mv nvim.appimage $HOME/.local/bin/nvim
|
|
|
@ -1,517 +0,0 @@
|
||||||
#!/usr/bin/env sh
|
|
||||||
|
|
||||||
set -eu
|
|
||||||
printf '\n'
|
|
||||||
|
|
||||||
BOLD="$(tput bold 2>/dev/null || printf '')"
|
|
||||||
GREY="$(tput setaf 0 2>/dev/null || printf '')"
|
|
||||||
UNDERLINE="$(tput smul 2>/dev/null || printf '')"
|
|
||||||
RED="$(tput setaf 1 2>/dev/null || printf '')"
|
|
||||||
GREEN="$(tput setaf 2 2>/dev/null || printf '')"
|
|
||||||
YELLOW="$(tput setaf 3 2>/dev/null || printf '')"
|
|
||||||
BLUE="$(tput setaf 4 2>/dev/null || printf '')"
|
|
||||||
MAGENTA="$(tput setaf 5 2>/dev/null || printf '')"
|
|
||||||
NO_COLOR="$(tput sgr0 2>/dev/null || printf '')"
|
|
||||||
|
|
||||||
SUPPORTED_TARGETS="x86_64-unknown-linux-gnu x86_64-unknown-linux-musl \
|
|
||||||
i686-unknown-linux-musl aarch64-unknown-linux-musl \
|
|
||||||
arm-unknown-linux-musleabihf x86_64-apple-darwin \
|
|
||||||
aarch64-apple-darwin x86_64-pc-windows-msvc \
|
|
||||||
i686-pc-windows-msvc aarch64-pc-windows-msvc \
|
|
||||||
x86_64-unknown-freebsd"
|
|
||||||
|
|
||||||
info() {
|
|
||||||
printf '%s\n' "${BOLD}${GREY}>${NO_COLOR} $*"
|
|
||||||
}
|
|
||||||
|
|
||||||
warn() {
|
|
||||||
printf '%s\n' "${YELLOW}! $*${NO_COLOR}"
|
|
||||||
}
|
|
||||||
|
|
||||||
error() {
|
|
||||||
printf '%s\n' "${RED}x $*${NO_COLOR}" >&2
|
|
||||||
}
|
|
||||||
|
|
||||||
completed() {
|
|
||||||
printf '%s\n' "${GREEN}✓${NO_COLOR} $*"
|
|
||||||
}
|
|
||||||
|
|
||||||
has() {
|
|
||||||
command -v "$1" 1>/dev/null 2>&1
|
|
||||||
}
|
|
||||||
|
|
||||||
# Make sure user is not using zsh or non-POSIX-mode bash, which can cause issues
|
|
||||||
verify_shell_is_posix_or_exit() {
|
|
||||||
if [ -n "${ZSH_VERSION+x}" ]; then
|
|
||||||
error "Running installation script with \`zsh\` is known to cause errors."
|
|
||||||
error "Please use \`sh\` instead."
|
|
||||||
exit 1
|
|
||||||
elif [ -n "${BASH_VERSION+x}" ] && [ -z "${POSIXLY_CORRECT+x}" ]; then
|
|
||||||
error "Running installation script with non-POSIX \`bash\` may cause errors."
|
|
||||||
error "Please use \`sh\` instead."
|
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
true # No-op: no issues detected
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Gets path to a temporary file, even if
|
|
||||||
get_tmpfile() {
|
|
||||||
suffix="$1"
|
|
||||||
if has mktemp; then
|
|
||||||
printf "%s.%s" "$(mktemp)" "${suffix}"
|
|
||||||
else
|
|
||||||
# No really good options here--let's pick a default + hope
|
|
||||||
printf "/tmp/starship.%s" "${suffix}"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Test if a location is writeable by trying to write to it. Windows does not let
|
|
||||||
# you test writeability other than by writing: https://stackoverflow.com/q/1999988
|
|
||||||
test_writeable() {
|
|
||||||
path="${1:-}/test.txt"
|
|
||||||
if touch "${path}" 2>/dev/null; then
|
|
||||||
rm "${path}"
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
download() {
|
|
||||||
file="$1"
|
|
||||||
url="$2"
|
|
||||||
|
|
||||||
if has curl; then
|
|
||||||
cmd="curl --fail --silent --location --output $file $url"
|
|
||||||
elif has wget; then
|
|
||||||
cmd="wget --quiet --output-document=$file $url"
|
|
||||||
elif has fetch; then
|
|
||||||
cmd="fetch --quiet --output=$file $url"
|
|
||||||
else
|
|
||||||
error "No HTTP download program (curl, wget, fetch) found, exiting…"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
$cmd && return 0 || rc=$?
|
|
||||||
|
|
||||||
error "Command failed (exit code $rc): ${BLUE}${cmd}${NO_COLOR}"
|
|
||||||
printf "\n" >&2
|
|
||||||
info "This is likely due to Starship not yet supporting your configuration."
|
|
||||||
info "If you would like to see a build for your configuration,"
|
|
||||||
info "please create an issue requesting a build for ${MAGENTA}${TARGET}${NO_COLOR}:"
|
|
||||||
info "${BOLD}${UNDERLINE}https://github.com/starship/starship/issues/new/${NO_COLOR}"
|
|
||||||
return $rc
|
|
||||||
}
|
|
||||||
|
|
||||||
unpack() {
|
|
||||||
archive=$1
|
|
||||||
bin_dir=$2
|
|
||||||
sudo=${3-}
|
|
||||||
|
|
||||||
case "$archive" in
|
|
||||||
*.tar.gz)
|
|
||||||
flags=$(test -n "${VERBOSE-}" && echo "-xzvof" || echo "-xzof")
|
|
||||||
${sudo} tar "${flags}" "${archive}" -C "${bin_dir}"
|
|
||||||
return 0
|
|
||||||
;;
|
|
||||||
*.zip)
|
|
||||||
flags=$(test -z "${VERBOSE-}" && echo "-qqo" || echo "-o")
|
|
||||||
UNZIP="${flags}" ${sudo} unzip "${archive}" -d "${bin_dir}"
|
|
||||||
return 0
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
error "Unknown package extension."
|
|
||||||
printf "\n"
|
|
||||||
info "This almost certainly results from a bug in this script--please file a"
|
|
||||||
info "bug report at https://github.com/starship/starship/issues"
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
usage() {
|
|
||||||
printf "%s\n" \
|
|
||||||
"install.sh [option]" \
|
|
||||||
"" \
|
|
||||||
"Fetch and install the latest version of starship, if starship is already" \
|
|
||||||
"installed it will be updated to the latest version."
|
|
||||||
|
|
||||||
printf "\n%s\n" "Options"
|
|
||||||
printf "\t%s\n\t\t%s\n\n" \
|
|
||||||
"-V, --verbose" "Enable verbose output for the installer" \
|
|
||||||
"-f, -y, --force, --yes" "Skip the confirmation prompt during installation" \
|
|
||||||
"-p, --platform" "Override the platform identified by the installer [default: ${PLATFORM}]" \
|
|
||||||
"-b, --bin-dir" "Override the bin installation directory [default: ${BIN_DIR}]" \
|
|
||||||
"-a, --arch" "Override the architecture identified by the installer [default: ${ARCH}]" \
|
|
||||||
"-B, --base-url" "Override the base URL used for downloading releases [default: ${BASE_URL}]" \
|
|
||||||
"-h, --help" "Display this help message"
|
|
||||||
}
|
|
||||||
|
|
||||||
elevate_priv() {
|
|
||||||
if ! has sudo; then
|
|
||||||
error 'Could not find the command "sudo", needed to get permissions for install.'
|
|
||||||
info "If you are on Windows, please run your shell as an administrator, then"
|
|
||||||
info "rerun this script. Otherwise, please run this script as root, or install"
|
|
||||||
info "sudo."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
if ! sudo -v; then
|
|
||||||
error "Superuser not granted, aborting installation"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
install() {
|
|
||||||
ext="$1"
|
|
||||||
|
|
||||||
if test_writeable "${BIN_DIR}"; then
|
|
||||||
sudo=""
|
|
||||||
msg="Installing Starship, please wait…"
|
|
||||||
else
|
|
||||||
warn "Escalated permissions are required to install to ${BIN_DIR}"
|
|
||||||
elevate_priv
|
|
||||||
sudo="sudo"
|
|
||||||
msg="Installing Starship as root, please wait…"
|
|
||||||
fi
|
|
||||||
info "$msg"
|
|
||||||
|
|
||||||
archive=$(get_tmpfile "$ext")
|
|
||||||
|
|
||||||
# download to the temp file
|
|
||||||
download "${archive}" "${URL}"
|
|
||||||
|
|
||||||
# unpack the temp file to the bin dir, using sudo if required
|
|
||||||
unpack "${archive}" "${BIN_DIR}" "${sudo}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Currently supporting:
|
|
||||||
# - win (Git Bash)
|
|
||||||
# - darwin
|
|
||||||
# - linux
|
|
||||||
# - linux_musl (Alpine)
|
|
||||||
# - freebsd
|
|
||||||
detect_platform() {
|
|
||||||
platform="$(uname -s | tr '[:upper:]' '[:lower:]')"
|
|
||||||
|
|
||||||
case "${platform}" in
|
|
||||||
msys_nt*) platform="pc-windows-msvc" ;;
|
|
||||||
cygwin_nt*) platform="pc-windows-msvc";;
|
|
||||||
# mingw is Git-Bash
|
|
||||||
mingw*) platform="pc-windows-msvc" ;;
|
|
||||||
# use the statically compiled musl bins on linux to avoid linking issues.
|
|
||||||
linux) platform="unknown-linux-musl" ;;
|
|
||||||
darwin) platform="apple-darwin" ;;
|
|
||||||
freebsd) platform="unknown-freebsd" ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
printf '%s' "${platform}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Currently supporting:
|
|
||||||
# - x86_64
|
|
||||||
# - i386
|
|
||||||
# - arm
|
|
||||||
# - arm64
|
|
||||||
detect_arch() {
|
|
||||||
arch="$(uname -m | tr '[:upper:]' '[:lower:]')"
|
|
||||||
|
|
||||||
case "${arch}" in
|
|
||||||
amd64) arch="x86_64" ;;
|
|
||||||
armv*) arch="arm" ;;
|
|
||||||
arm64) arch="aarch64" ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
# `uname -m` in some cases mis-reports 32-bit OS as 64-bit, so double check
|
|
||||||
if [ "${arch}" = "x86_64" ] && [ "$(getconf LONG_BIT)" -eq 32 ]; then
|
|
||||||
arch=i686
|
|
||||||
elif [ "${arch}" = "aarch64" ] && [ "$(getconf LONG_BIT)" -eq 32 ]; then
|
|
||||||
arch=arm
|
|
||||||
fi
|
|
||||||
|
|
||||||
printf '%s' "${arch}"
|
|
||||||
}
|
|
||||||
|
|
||||||
detect_target() {
|
|
||||||
arch="$1"
|
|
||||||
platform="$2"
|
|
||||||
target="$arch-$platform"
|
|
||||||
|
|
||||||
if [ "${target}" = "arm-unknown-linux-musl" ]; then
|
|
||||||
target="${target}eabihf"
|
|
||||||
fi
|
|
||||||
|
|
||||||
printf '%s' "${target}"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
confirm() {
|
|
||||||
if [ -z "${FORCE-}" ]; then
|
|
||||||
printf "%s " "${MAGENTA}?${NO_COLOR} $* ${BOLD}[y/N]${NO_COLOR}"
|
|
||||||
set +e
|
|
||||||
read -r yn </dev/tty
|
|
||||||
rc=$?
|
|
||||||
set -e
|
|
||||||
if [ $rc -ne 0 ]; then
|
|
||||||
error "Error reading from prompt (please re-run with the '--yes' option)"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
if [ "$yn" != "y" ] && [ "$yn" != "yes" ]; then
|
|
||||||
error 'Aborting (please answer "yes" to continue)'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
check_bin_dir() {
|
|
||||||
bin_dir="${1%/}"
|
|
||||||
|
|
||||||
if [ ! -d "$BIN_DIR" ]; then
|
|
||||||
error "Installation location $BIN_DIR does not appear to be a directory"
|
|
||||||
info "Make sure the location exists and is a directory, then try again."
|
|
||||||
usage
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# https://stackoverflow.com/a/11655875
|
|
||||||
good=$(
|
|
||||||
IFS=:
|
|
||||||
for path in $PATH; do
|
|
||||||
if [ "${path%/}" = "${bin_dir}" ]; then
|
|
||||||
printf 1
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
)
|
|
||||||
|
|
||||||
if [ "${good}" != "1" ]; then
|
|
||||||
warn "Bin directory ${bin_dir} is not in your \$PATH"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
print_install() {
|
|
||||||
# if the shell does not fit the default case change the config file
|
|
||||||
# and or the config cmd variable
|
|
||||||
for s in "bash" "zsh" "ion" "tcsh" "xonsh" "fish"
|
|
||||||
do
|
|
||||||
# shellcheck disable=SC2088
|
|
||||||
# we don't want these '~' expanding
|
|
||||||
config_file="~/.${s}rc"
|
|
||||||
config_cmd="eval \"\$(starship init ${s})\""
|
|
||||||
|
|
||||||
case ${s} in
|
|
||||||
ion )
|
|
||||||
# shellcheck disable=SC2088
|
|
||||||
config_file="~/.config/ion/initrc"
|
|
||||||
config_cmd="eval \$(starship init ${s})"
|
|
||||||
;;
|
|
||||||
fish )
|
|
||||||
# shellcheck disable=SC2088
|
|
||||||
config_file="~/.config/fish/config.fish"
|
|
||||||
config_cmd="starship init fish | source"
|
|
||||||
;;
|
|
||||||
tcsh )
|
|
||||||
config_cmd="eval \`starship init ${s}\`"
|
|
||||||
;;
|
|
||||||
xonsh )
|
|
||||||
config_cmd="execx(\$(starship init xonsh))"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
printf " %s\n Add the following to the end of %s:\n\n\t%s\n\n" \
|
|
||||||
"${BOLD}${UNDERLINE}${s}${NO_COLOR}" \
|
|
||||||
"${BOLD}${config_file}${NO_COLOR}" \
|
|
||||||
"${config_cmd}"
|
|
||||||
done
|
|
||||||
|
|
||||||
for s in "elvish" "nushell"
|
|
||||||
do
|
|
||||||
|
|
||||||
warning="${BOLD}Warning${NO_COLOR}"
|
|
||||||
case ${s} in
|
|
||||||
elvish )
|
|
||||||
# shellcheck disable=SC2088
|
|
||||||
config_file="~/.elvish/rc.elv"
|
|
||||||
config_cmd="eval (starship init elvish)"
|
|
||||||
warning="${warning} Only elvish v0.17 or higher is supported."
|
|
||||||
;;
|
|
||||||
nushell )
|
|
||||||
# shellcheck disable=SC2088
|
|
||||||
config_file="${BOLD}your nu config file${NO_COLOR} (find it by running ${BOLD}\$nu.config-path${NO_COLOR} in Nushell)"
|
|
||||||
config_cmd="mkdir ~/.cache/starship
|
|
||||||
starship init nu | save -f ~/.cache/starship/init.nu
|
|
||||||
source ~/.cache/starship/init.nu"
|
|
||||||
warning="${warning} This will change in the future.
|
|
||||||
Only Nushell v0.73 or higher is supported.
|
|
||||||
Add the following to the end of ${BOLD}your Nushell env file${NO_COLOR} (find it by running ${BOLD}\$nu.env-path${NO_COLOR} in Nushell): \"mkdir ~/.cache/starship; starship init nu | save -f ~/.cache/starship/init.nu\""
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
printf " %s\n %s\n And add the following to the end of %s:\n\n\t%s\n\n" \
|
|
||||||
"${BOLD}${UNDERLINE}${s}${NO_COLOR}" \
|
|
||||||
"${warning}" \
|
|
||||||
"${config_file}" \
|
|
||||||
"${config_cmd}"
|
|
||||||
done
|
|
||||||
|
|
||||||
printf " %s\n Add the following to the end of %s:\n %s\n\n\t%s\n\n" \
|
|
||||||
"${BOLD}${UNDERLINE}PowerShell${NO_COLOR}" \
|
|
||||||
"${BOLD}Microsoft.PowerShell_profile.ps1${NO_COLOR}" \
|
|
||||||
"You can check the location of this file by querying the \$PROFILE variable in PowerShell.
|
|
||||||
Typically the path is ~\Documents\PowerShell\Microsoft.PowerShell_profile.ps1 or ~/.config/powershell/Microsoft.PowerShell_profile.ps1 on -Nix." \
|
|
||||||
"Invoke-Expression (&starship init powershell)"
|
|
||||||
|
|
||||||
printf " %s\n You need to use Clink (v1.2.30+) with Cmd. Add the following to a file %s and place this file in Clink scripts directory:\n\n\t%s\n\n" \
|
|
||||||
"${BOLD}${UNDERLINE}Cmd${NO_COLOR}" \
|
|
||||||
"${BOLD}starship.lua${NO_COLOR}" \
|
|
||||||
"load(io.popen('starship init cmd'):read(\"*a\"))()"
|
|
||||||
|
|
||||||
printf "\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
is_build_available() {
|
|
||||||
arch="$1"
|
|
||||||
platform="$2"
|
|
||||||
target="$3"
|
|
||||||
|
|
||||||
good=$(
|
|
||||||
IFS=" "
|
|
||||||
for t in $SUPPORTED_TARGETS; do
|
|
||||||
if [ "${t}" = "${target}" ]; then
|
|
||||||
printf 1
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
)
|
|
||||||
|
|
||||||
if [ "${good}" != "1" ]; then
|
|
||||||
error "${arch} builds for ${platform} are not yet available for Starship"
|
|
||||||
printf "\n" >&2
|
|
||||||
info "If you would like to see a build for your configuration,"
|
|
||||||
info "please create an issue requesting a build for ${MAGENTA}${target}${NO_COLOR}:"
|
|
||||||
info "${BOLD}${UNDERLINE}https://github.com/starship/starship/issues/new/${NO_COLOR}"
|
|
||||||
printf "\n"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# defaults
|
|
||||||
if [ -z "${PLATFORM-}" ]; then
|
|
||||||
PLATFORM="$(detect_platform)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "${BIN_DIR-}" ]; then
|
|
||||||
BIN_DIR=/usr/local/bin
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "${ARCH-}" ]; then
|
|
||||||
ARCH="$(detect_arch)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "${BASE_URL-}" ]; then
|
|
||||||
BASE_URL="https://github.com/starship/starship/releases"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Non-POSIX shells can break once executing code due to semantic differences
|
|
||||||
verify_shell_is_posix_or_exit
|
|
||||||
|
|
||||||
# parse argv variables
|
|
||||||
while [ "$#" -gt 0 ]; do
|
|
||||||
case "$1" in
|
|
||||||
-p | --platform)
|
|
||||||
PLATFORM="$2"
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
-b | --bin-dir)
|
|
||||||
BIN_DIR="$2"
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
-a | --arch)
|
|
||||||
ARCH="$2"
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
-B | --base-url)
|
|
||||||
BASE_URL="$2"
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
|
|
||||||
-V | --verbose)
|
|
||||||
VERBOSE=1
|
|
||||||
shift 1
|
|
||||||
;;
|
|
||||||
-f | -y | --force | --yes)
|
|
||||||
FORCE=1
|
|
||||||
shift 1
|
|
||||||
;;
|
|
||||||
-h | --help)
|
|
||||||
usage
|
|
||||||
exit
|
|
||||||
;;
|
|
||||||
|
|
||||||
-p=* | --platform=*)
|
|
||||||
PLATFORM="${1#*=}"
|
|
||||||
shift 1
|
|
||||||
;;
|
|
||||||
-b=* | --bin-dir=*)
|
|
||||||
BIN_DIR="${1#*=}"
|
|
||||||
shift 1
|
|
||||||
;;
|
|
||||||
-a=* | --arch=*)
|
|
||||||
ARCH="${1#*=}"
|
|
||||||
shift 1
|
|
||||||
;;
|
|
||||||
-B=* | --base-url=*)
|
|
||||||
BASE_URL="${1#*=}"
|
|
||||||
shift 1
|
|
||||||
;;
|
|
||||||
-V=* | --verbose=*)
|
|
||||||
VERBOSE="${1#*=}"
|
|
||||||
shift 1
|
|
||||||
;;
|
|
||||||
-f=* | -y=* | --force=* | --yes=*)
|
|
||||||
FORCE="${1#*=}"
|
|
||||||
shift 1
|
|
||||||
;;
|
|
||||||
|
|
||||||
*)
|
|
||||||
error "Unknown option: $1"
|
|
||||||
usage
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
TARGET="$(detect_target "${ARCH}" "${PLATFORM}")"
|
|
||||||
|
|
||||||
is_build_available "${ARCH}" "${PLATFORM}" "${TARGET}"
|
|
||||||
|
|
||||||
printf " %s\n" "${UNDERLINE}Configuration${NO_COLOR}"
|
|
||||||
info "${BOLD}Bin directory${NO_COLOR}: ${GREEN}${BIN_DIR}${NO_COLOR}"
|
|
||||||
info "${BOLD}Platform${NO_COLOR}: ${GREEN}${PLATFORM}${NO_COLOR}"
|
|
||||||
info "${BOLD}Arch${NO_COLOR}: ${GREEN}${ARCH}${NO_COLOR}"
|
|
||||||
|
|
||||||
# non-empty VERBOSE enables verbose untarring
|
|
||||||
if [ -n "${VERBOSE-}" ]; then
|
|
||||||
VERBOSE=v
|
|
||||||
info "${BOLD}Verbose${NO_COLOR}: yes"
|
|
||||||
else
|
|
||||||
VERBOSE=
|
|
||||||
fi
|
|
||||||
|
|
||||||
printf '\n'
|
|
||||||
|
|
||||||
EXT=tar.gz
|
|
||||||
if [ "${PLATFORM}" = "pc-windows-msvc" ]; then
|
|
||||||
EXT=zip
|
|
||||||
fi
|
|
||||||
|
|
||||||
URL="${BASE_URL}/latest/download/starship-${TARGET}.${EXT}"
|
|
||||||
info "Tarball URL: ${UNDERLINE}${BLUE}${URL}${NO_COLOR}"
|
|
||||||
confirm "Install Starship ${GREEN}latest${NO_COLOR} to ${BOLD}${GREEN}${BIN_DIR}${NO_COLOR}?"
|
|
||||||
check_bin_dir "${BIN_DIR}"
|
|
||||||
|
|
||||||
install "${EXT}"
|
|
||||||
completed "Starship installed"
|
|
||||||
|
|
||||||
printf '\n'
|
|
||||||
info "Please follow the steps for your shell to complete the installation:"
|
|
||||||
|
|
||||||
print_install
|
|
|
@ -1,189 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
#
|
|
||||||
# Use rofi/zenity to change system runstate thanks to systemd.
|
|
||||||
#
|
|
||||||
# Note: this currently relies on associative array support in the shell.
|
|
||||||
#
|
|
||||||
# Inspired from i3pystatus wiki:
|
|
||||||
# https://github.com/enkore/i3pystatus/wiki/Shutdown-Menu
|
|
||||||
#
|
|
||||||
# Copyright 2015 Benjamin Chrétien <chretien at lirmm dot fr>
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
# power-profiles-daemon implementation:
|
|
||||||
# needs package power-profiles-daemon installed and the service running see here:
|
|
||||||
# https://wiki.archlinux.org/title/CPU_frequency_scaling#power-profiles-daemon
|
|
||||||
# used in i3-blocks: ~/.config/i3/i3blocks.conf together with: ~/.config/i3/scripts/ppd-status
|
|
||||||
|
|
||||||
|
|
||||||
#######################################################################
|
|
||||||
# BEGIN CONFIG #
|
|
||||||
#######################################################################
|
|
||||||
|
|
||||||
# Use a custom lock script
|
|
||||||
#LOCKSCRIPT="i3lock-extra -m pixelize"
|
|
||||||
|
|
||||||
# Colors: FG (foreground), BG (background), HL (highlighted)
|
|
||||||
FG_COLOR="#bbbbbb"
|
|
||||||
BG_COLOR="#111111"
|
|
||||||
HLFG_COLOR="#111111"
|
|
||||||
HLBG_COLOR="#bbbbbb"
|
|
||||||
BORDER_COLOR="#222222"
|
|
||||||
|
|
||||||
# Options not related to colors
|
|
||||||
#ROFI_TEXT=":"
|
|
||||||
#ROFI_OPTIONS=(-width -11 -location 0 -hide-scrollbar -bw 30 -color-window "#dd310027,#dd0310027,#dd310027" -padding 5)
|
|
||||||
#ROFI_OPTIONS=(-width -18 -location 4 -hide-scrollbar -color-window "#cc310027,#00a0009a,#cc310027" -padding 5 -font "Sourcecode Pro Regular 10, FontAwesome 9")
|
|
||||||
#ROFI_OPTIONS=(-theme ~/.dotfiles/rofi/power-profiles.rasi)
|
|
||||||
# Zenity options
|
|
||||||
ZENITY_TITLE="Power Profiles"
|
|
||||||
ZENITY_TEXT="Set Profiles:"
|
|
||||||
ZENITY_OPTIONS=(--column= --hide-header)
|
|
||||||
|
|
||||||
#######################################################################
|
|
||||||
# END CONFIG #
|
|
||||||
#######################################################################
|
|
||||||
|
|
||||||
# Whether to ask for user's confirmation
|
|
||||||
enable_confirmation=false
|
|
||||||
|
|
||||||
# Preferred launcher if both are available
|
|
||||||
preferred_launcher="rofi"
|
|
||||||
|
|
||||||
usage="$(basename "$0") [-h] [-c] [-p name] -- display a menu for shutdown, reboot, lock etc.
|
|
||||||
|
|
||||||
where:
|
|
||||||
-h show this help text
|
|
||||||
-c ask for user confirmation
|
|
||||||
-p preferred launcher (rofi or zenity)
|
|
||||||
|
|
||||||
This script depends on:
|
|
||||||
- systemd,
|
|
||||||
- rofi or zenity."
|
|
||||||
|
|
||||||
# Check whether the user-defined launcher is valid
|
|
||||||
launcher_list=(rofi zenity)
|
|
||||||
function check_launcher() {
|
|
||||||
if [[ ! "${launcher_list[@]}" =~ (^|[[:space:]])"$1"($|[[:space:]]) ]]; then
|
|
||||||
echo "Supported launchers: ${launcher_list[*]}"
|
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
# Get array with unique elements and preferred launcher first
|
|
||||||
# Note: uniq expects a sorted list, so we cannot use it
|
|
||||||
i=1
|
|
||||||
launcher_list=($(for l in "$1" "${launcher_list[@]}"; do printf "%i %s\n" "$i" "$l"; let i+=1; done \
|
|
||||||
| sort -uk2 | sort -nk1 | cut -d' ' -f2- | tr '\n' ' '))
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Parse CLI arguments
|
|
||||||
while getopts "hcp:" option; do
|
|
||||||
case "${option}" in
|
|
||||||
h) echo "${usage}"
|
|
||||||
exit 0
|
|
||||||
;;
|
|
||||||
c) enable_confirmation=true
|
|
||||||
;;
|
|
||||||
p) preferred_launcher="${OPTARG}"
|
|
||||||
check_launcher "${preferred_launcher}"
|
|
||||||
;;
|
|
||||||
*) exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
# Check whether a command exists
|
|
||||||
function command_exists() {
|
|
||||||
command -v "$1" &> /dev/null 2>&1
|
|
||||||
}
|
|
||||||
|
|
||||||
# systemctl required
|
|
||||||
if ! command_exists systemctl ; then
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# menu defined as an associative array
|
|
||||||
typeset -A menu
|
|
||||||
|
|
||||||
# Menu with keys/commands
|
|
||||||
|
|
||||||
menu=(
|
|
||||||
[ Performance]="powerprofilesctl set performance"
|
|
||||||
[ Balanced]="powerprofilesctl set balanced"
|
|
||||||
[ Power Saver]="powerprofilesctl set power-saver"
|
|
||||||
[ Cancel]=""
|
|
||||||
)
|
|
||||||
|
|
||||||
menu_nrows=${#menu[@]}
|
|
||||||
|
|
||||||
# Menu entries that may trigger a confirmation message
|
|
||||||
menu_confirm="Shutdown Reboot Hibernate Suspend Halt Logout"
|
|
||||||
|
|
||||||
launcher_exe=""
|
|
||||||
launcher_options=""
|
|
||||||
rofi_colors=""
|
|
||||||
|
|
||||||
function prepare_launcher() {
|
|
||||||
if [[ "$1" == "rofi" ]]; then
|
|
||||||
rofi_colors=(-bc "${BORDER_COLOR}" -bg "${BG_COLOR}" -fg "${FG_COLOR}" \
|
|
||||||
-hlfg "${HLFG_COLOR}" -hlbg "${HLBG_COLOR}")
|
|
||||||
launcher_exe="rofi"
|
|
||||||
launcher_options=(-dmenu -i -lines "${menu_nrows}" -p "${ROFI_TEXT}" \
|
|
||||||
"${rofi_colors}" "${ROFI_OPTIONS[@]}")
|
|
||||||
elif [[ "$1" == "zenity" ]]; then
|
|
||||||
launcher_exe="zenity"
|
|
||||||
launcher_options=(--list --title="${ZENITY_TITLE}" --text="${ZENITY_TEXT}" \
|
|
||||||
"${ZENITY_OPTIONS[@]}")
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
for l in "${launcher_list[@]}"; do
|
|
||||||
if command_exists "${l}" ; then
|
|
||||||
prepare_launcher "${l}"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# No launcher available
|
|
||||||
if [[ -z "${launcher_exe}" ]]; then
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
launcher=(${launcher_exe} "${launcher_options[@]}")
|
|
||||||
selection="$(printf '%s\n' "${!menu[@]}" | sort | "${launcher[@]}")"
|
|
||||||
|
|
||||||
function ask_confirmation() {
|
|
||||||
if [ "${launcher_exe}" == "rofi" ]; then
|
|
||||||
confirmed=$(echo -e "Yes\nNo" | rofi -dmenu -i -lines 2 -p "${selection}?" \
|
|
||||||
"${rofi_colors}" "${ROFI_OPTIONS[@]}")
|
|
||||||
[ "${confirmed}" == "Yes" ] && confirmed=0
|
|
||||||
elif [ "${launcher_exe}" == "zenity" ]; then
|
|
||||||
zenity --question --text "Are you sure you want to ${selection,,}?"
|
|
||||||
confirmed=$?
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "${confirmed}" == 0 ]; then
|
|
||||||
${menu[${selection}]}
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
if [[ $? -eq 0 && ! -z ${selection} ]]; then
|
|
||||||
if [[ "${enable_confirmation}" = true && \
|
|
||||||
${menu_confirm} =~ (^|[[:space:]])"${selection}"($|[[:space:]]) ]]; then
|
|
||||||
ask_confirmation
|
|
||||||
else
|
|
||||||
${menu[${selection}]}
|
|
||||||
fi
|
|
||||||
fi
|
|
|
@ -1,185 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
#
|
|
||||||
# Use rofi/zenity to change system runstate thanks to systemd.
|
|
||||||
#
|
|
||||||
# Note: this currently relies on associative array support in the shell.
|
|
||||||
#
|
|
||||||
# Inspired from i3pystatus wiki:
|
|
||||||
# https://github.com/enkore/i3pystatus/wiki/Shutdown-Menu
|
|
||||||
#
|
|
||||||
# Copyright 2015 Benjamin Chrétien <chretien at lirmm dot fr>
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
# modified to work with latest rofi update by joekamprad <joekamprad@endeavouros.com>
|
|
||||||
|
|
||||||
#######################################################################
|
|
||||||
# BEGIN CONFIG #
|
|
||||||
#######################################################################
|
|
||||||
|
|
||||||
# Use a custom lock script
|
|
||||||
#LOCKSCRIPT="i3lock-extra -m pixelize"
|
|
||||||
|
|
||||||
# Colors: FG (foreground), BG (background), HL (highlighted)
|
|
||||||
FG_COLOR="#bbbbbb"
|
|
||||||
BG_COLOR="#111111"
|
|
||||||
HLFG_COLOR="#111111"
|
|
||||||
HLBG_COLOR="#bbbbbb"
|
|
||||||
BORDER_COLOR="#222222"
|
|
||||||
|
|
||||||
# Options not related to colors (most rofi options do not work anymore)
|
|
||||||
#ROFI_OPTIONS=(-theme ~/.dotfiles/rofi/powermenu.rasi)
|
|
||||||
# Zenity options
|
|
||||||
ZENITY_TITLE="Power Menu"
|
|
||||||
ZENITY_TEXT="Action:"
|
|
||||||
ZENITY_OPTIONS=(--column= --hide-header)
|
|
||||||
|
|
||||||
#######################################################################
|
|
||||||
# END CONFIG #
|
|
||||||
#######################################################################
|
|
||||||
|
|
||||||
# Whether to ask for user's confirmation
|
|
||||||
enable_confirmation=false
|
|
||||||
|
|
||||||
# Preferred launcher if both are available
|
|
||||||
preferred_launcher="rofi"
|
|
||||||
|
|
||||||
usage="$(basename "$0") [-h] [-c] [-p name] -- display a menu for shutdown, reboot, lock etc.
|
|
||||||
|
|
||||||
where:
|
|
||||||
-h show this help text
|
|
||||||
-c ask for user confirmation
|
|
||||||
-p preferred launcher (rofi or zenity)
|
|
||||||
|
|
||||||
This script depends on:
|
|
||||||
- systemd,
|
|
||||||
- rofi or zenity."
|
|
||||||
|
|
||||||
# Check whether the user-defined launcher is valid
|
|
||||||
launcher_list=(rofi zenity)
|
|
||||||
function check_launcher() {
|
|
||||||
if [[ ! "${launcher_list[@]}" =~ (^|[[:space:]])"$1"($|[[:space:]]) ]]; then
|
|
||||||
echo "Supported launchers: ${launcher_list[*]}"
|
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
# Get array with unique elements and preferred launcher first
|
|
||||||
# Note: uniq expects a sorted list, so we cannot use it
|
|
||||||
i=1
|
|
||||||
launcher_list=($(for l in "$1" "${launcher_list[@]}"; do printf "%i %s\n" "$i" "$l"; let i+=1; done \
|
|
||||||
| sort -uk2 | sort -nk1 | cut -d' ' -f2- | tr '\n' ' '))
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Parse CLI arguments
|
|
||||||
while getopts "hcp:" option; do
|
|
||||||
case "${option}" in
|
|
||||||
h) echo "${usage}"
|
|
||||||
exit 0
|
|
||||||
;;
|
|
||||||
c) enable_confirmation=true
|
|
||||||
;;
|
|
||||||
p) preferred_launcher="${OPTARG}"
|
|
||||||
check_launcher "${preferred_launcher}"
|
|
||||||
;;
|
|
||||||
*) exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
# Check whether a command exists
|
|
||||||
function command_exists() {
|
|
||||||
command -v "$1" &> /dev/null 2>&1
|
|
||||||
}
|
|
||||||
|
|
||||||
# systemctl required
|
|
||||||
if ! command_exists systemctl ; then
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# menu defined as an associative array
|
|
||||||
typeset -A menu
|
|
||||||
|
|
||||||
# Menu with keys/commands
|
|
||||||
|
|
||||||
menu=(
|
|
||||||
[ Shutdown]="systemctl poweroff"
|
|
||||||
[ Reboot]="systemctl reboot"
|
|
||||||
[ Suspend]="systemctl suspend"
|
|
||||||
[ Hibernate]="systemctl hibernate"
|
|
||||||
[ Lock]="hyprctl dispatch exec swaylock"
|
|
||||||
[ Logout]="hyprctl dispatch exit"
|
|
||||||
[ Cancel]=""
|
|
||||||
)
|
|
||||||
|
|
||||||
menu_nrows=${#menu[@]}
|
|
||||||
|
|
||||||
# Menu entries that may trigger a confirmation message
|
|
||||||
menu_confirm="Shutdown Reboot Hibernate Suspend Halt Logout"
|
|
||||||
|
|
||||||
launcher_exe=""
|
|
||||||
launcher_options=""
|
|
||||||
rofi_colors=""
|
|
||||||
|
|
||||||
function prepare_launcher() {
|
|
||||||
if [[ "$1" == "rofi" ]]; then
|
|
||||||
rofi_colors=(-bc "${BORDER_COLOR}" -bg "${BG_COLOR}" -fg "${FG_COLOR}" \
|
|
||||||
-hlfg "${HLFG_COLOR}" -hlbg "${HLBG_COLOR}")
|
|
||||||
launcher_exe="rofi"
|
|
||||||
launcher_options=(-dmenu -i -lines "${menu_nrows}" -p "${ROFI_TEXT}" \
|
|
||||||
"${rofi_colors}" "${ROFI_OPTIONS[@]}")
|
|
||||||
elif [[ "$1" == "zenity" ]]; then
|
|
||||||
launcher_exe="zenity"
|
|
||||||
launcher_options=(--list --title="${ZENITY_TITLE}" --text="${ZENITY_TEXT}" \
|
|
||||||
"${ZENITY_OPTIONS[@]}")
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
for l in "${launcher_list[@]}"; do
|
|
||||||
if command_exists "${l}" ; then
|
|
||||||
prepare_launcher "${l}"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# No launcher available
|
|
||||||
if [[ -z "${launcher_exe}" ]]; then
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
launcher=(${launcher_exe} "${launcher_options[@]}")
|
|
||||||
selection="$(printf '%s\n' "${!menu[@]}" | sort | "${launcher[@]}")"
|
|
||||||
|
|
||||||
function ask_confirmation() {
|
|
||||||
if [ "${launcher_exe}" == "rofi" ]; then
|
|
||||||
confirmed=$(echo -e "Yes\nNo" | rofi -dmenu -i -lines 2 -p "${selection}?" \
|
|
||||||
"${rofi_colors}" "${ROFI_OPTIONS[@]}")
|
|
||||||
[ "${confirmed}" == "Yes" ] && confirmed=0
|
|
||||||
elif [ "${launcher_exe}" == "zenity" ]; then
|
|
||||||
zenity --question --text "Are you sure you want to ${selection,,}?"
|
|
||||||
confirmed=$?
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "${confirmed}" == 0 ]; then
|
|
||||||
${menu[${selection}]}
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
if [[ $? -eq 0 && ! -z ${selection} ]]; then
|
|
||||||
if [[ "${enable_confirmation}" = true && \
|
|
||||||
${menu_confirm} =~ (^|[[:space:]])"${selection}"($|[[:space:]]) ]]; then
|
|
||||||
ask_confirmation
|
|
||||||
else
|
|
||||||
${menu[${selection}]}
|
|
||||||
fi
|
|
||||||
fi
|
|
|
@ -1,670 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
##################################################################
|
|
||||||
# Polybar Pulseaudio Control #
|
|
||||||
# https://github.com/marioortizmanero/polybar-pulseaudio-control #
|
|
||||||
##################################################################
|
|
||||||
|
|
||||||
# Deprecated values, to be removed in a next release. This is kept around to
|
|
||||||
# be displayed for users using it in custom FORMAT
|
|
||||||
# shellcheck disable=SC2034
|
|
||||||
ICON_SINK="Replaced by ICON_NODE, see https://github.com/marioortizmanero/polybar-pulseaudio-control/releases/tag/v3.0.0"
|
|
||||||
SINK_NICKNAME="Replaced by NODE_NICKNAME, see https://github.com/marioortizmanero/polybar-pulseaudio-control/releases/tag/v3.0.0"
|
|
||||||
|
|
||||||
# Defaults for configurable values, expected to be set by command-line arguments
|
|
||||||
AUTOSYNC="no"
|
|
||||||
COLOR_MUTED="%{F#6b6b6b}"
|
|
||||||
ICON_MUTED=
|
|
||||||
ICON_NODE=
|
|
||||||
NODE_TYPE="output"
|
|
||||||
NOTIFICATIONS="no"
|
|
||||||
OSD="no"
|
|
||||||
NODE_NICKNAMES_PROP=
|
|
||||||
VOLUME_STEP=2
|
|
||||||
VOLUME_MAX=130
|
|
||||||
LISTEN_TIMEOUT=0.05
|
|
||||||
# shellcheck disable=SC2016
|
|
||||||
FORMAT='$VOL_ICON ${VOL_LEVEL}% $ICON_NODE $NODE_NICKNAME'
|
|
||||||
declare -A NODE_NICKNAMES
|
|
||||||
declare -a ICONS_VOLUME
|
|
||||||
declare -a NODE_BLACKLIST
|
|
||||||
|
|
||||||
# Special variable: within the script, pactl, grep, and awk commands are used
|
|
||||||
# on sinks or sources, depending on NODE_TYPE.
|
|
||||||
#
|
|
||||||
# The commands are almost always the same, except for the sink/source part.
|
|
||||||
# In order to reduce duplication, this variable is used for commands that behave
|
|
||||||
# the same, regardless of the NODE_TYPE.
|
|
||||||
#
|
|
||||||
# Having only the "radix" (ink/ource) and omitting the first letter enables us
|
|
||||||
# to use that single variable:
|
|
||||||
#
|
|
||||||
# S-ink , s-ink , s-ink -s, S-ink -s
|
|
||||||
# S-ource, s-ource, s-ource-s, S-ource-s
|
|
||||||
SINK_OR_SOURCE="ink"
|
|
||||||
|
|
||||||
# Environment & global constants for the script
|
|
||||||
export LC_ALL=C # Some calls depend on English outputs of pactl
|
|
||||||
END_COLOR="%{F-}" # For Polybar colors
|
|
||||||
|
|
||||||
|
|
||||||
# Saves the currently default node into a variable named `curNode`. It will
|
|
||||||
# return an error code when pulseaudio isn't running.
|
|
||||||
function getCurNode() {
|
|
||||||
if ! pactl info &>/dev/null; then return 1; fi
|
|
||||||
local curNodeName
|
|
||||||
|
|
||||||
curNodeName=$(pactl info | awk "/Default S${SINK_OR_SOURCE}: / {print \$3}")
|
|
||||||
curNode=$(pactl list "s${SINK_OR_SOURCE}s" | grep -B 4 -E "Name: $curNodeName\$" | sed -nE "s/^S${SINK_OR_SOURCE} #([0-9]+)$/\1/p")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# Saves the node passed by parameter's volume into a variable named `VOL_LEVEL`.
|
|
||||||
function getCurVol() {
|
|
||||||
VOL_LEVEL=$(pactl list "s${SINK_OR_SOURCE}s" | grep -A 15 -E "^S${SINK_OR_SOURCE} #$1\$" | grep 'Volume:' | grep -E -v 'Base Volume:' | awk -F : '{print $3; exit}' | grep -o -P '.{0,3}%' | sed 's/.$//' | tr -d ' ')
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# Saves the name of the node passed by parameter into a variable named
|
|
||||||
# `nodeName`.
|
|
||||||
function getNodeName() {
|
|
||||||
nodeName=$(pactl list "s${SINK_OR_SOURCE}s" short | awk -v sink="$1" "{ if (\$1 == sink) {print \$2} }")
|
|
||||||
portName=$(pactl list "s${SINK_OR_SOURCE}s" | grep -e "S${SINK_OR_SOURCE} #" -e 'Active Port: ' | sed -n "/^S${SINK_OR_SOURCE} #$1\$/,+1p" | awk '/Active Port: / {print $3}')
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# Saves the name to be displayed for the node passed by parameter into a
|
|
||||||
# variable called `NODE_NICKNAME`.
|
|
||||||
# If a mapping for the node name exists, that is used. Otherwise, the string
|
|
||||||
# "Node #<index>" is used.
|
|
||||||
function getNickname() {
|
|
||||||
getNodeName "$1"
|
|
||||||
unset NODE_NICKNAME
|
|
||||||
|
|
||||||
if [ -n "$nodeName" ] && [ -n "$portName" ] && [ -n "${NODE_NICKNAMES[$nodeName/$portName]}" ]; then
|
|
||||||
NODE_NICKNAME="${NODE_NICKNAMES[$nodeName/$portName]}"
|
|
||||||
elif [ -n "$nodeName" ] && [ -n "${NODE_NICKNAMES[$nodeName]}" ]; then
|
|
||||||
NODE_NICKNAME="${NODE_NICKNAMES[$nodeName]}"
|
|
||||||
elif [ -n "$nodeName" ]; then
|
|
||||||
# No exact match could be found, try a Glob Match
|
|
||||||
for glob in "${!NODE_NICKNAMES[@]}"; do
|
|
||||||
# shellcheck disable=SC2053 # Disable Shellcheck warning for Glob-Matching
|
|
||||||
if [[ "$nodeName/$portName" == $glob ]] || [[ "$nodeName" == $glob ]]; then
|
|
||||||
NODE_NICKNAME="${NODE_NICKNAMES[$glob]}"
|
|
||||||
# Cache that result for next time
|
|
||||||
NODE_NICKNAMES["$nodeName"]="$NODE_NICKNAME"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$NODE_NICKNAME" ] && [ -n "$nodeName" ] && [ -n "$NODE_NICKNAMES_PROP" ]; then
|
|
||||||
getNicknameFromProp "$NODE_NICKNAMES_PROP" "$nodeName"
|
|
||||||
# Cache that result for next time
|
|
||||||
NODE_NICKNAMES["$nodeName"]="$NODE_NICKNAME"
|
|
||||||
elif [ -z "$NODE_NICKNAME" ]; then
|
|
||||||
NODE_NICKNAME="S${SINK_OR_SOURCE} #$1"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Gets node nickname based on a given property.
|
|
||||||
function getNicknameFromProp() {
|
|
||||||
local nickname_prop="$1"
|
|
||||||
local for_name="$2"
|
|
||||||
|
|
||||||
NODE_NICKNAME=
|
|
||||||
while read -r property value; do
|
|
||||||
case "$property" in
|
|
||||||
Name:)
|
|
||||||
node_name="$value"
|
|
||||||
unset node_desc
|
|
||||||
;;
|
|
||||||
"$nickname_prop")
|
|
||||||
if [ "$node_name" != "$for_name" ]; then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
NODE_NICKNAME="${value:3:-1}"
|
|
||||||
break
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done < <(pactl list "s${SINK_OR_SOURCE}s")
|
|
||||||
}
|
|
||||||
|
|
||||||
# Saves the status of the node passed by parameter into a variable named
|
|
||||||
# `IS_MUTED`.
|
|
||||||
function getIsMuted() {
|
|
||||||
IS_MUTED=$(pactl list "s${SINK_OR_SOURCE}s" | grep -E "^S${SINK_OR_SOURCE} #$1\$" -A 15 | awk '/Mute: / {print $2}')
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# Saves all the sink inputs of the sink passed by parameter into a string
|
|
||||||
# named `sinkInputs`.
|
|
||||||
function getSinkInputs() {
|
|
||||||
sinkInputs=$(pactl list sink-inputs | grep -B 4 "Sink: $1" | sed -nE "s/^Sink Input #([0-9]+)\$/\1/p")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# Saves all the source outputs of the source passed by parameter into a string
|
|
||||||
# named `sourceOutputs`.
|
|
||||||
function getSourceOutputs() {
|
|
||||||
sourceOutputs=$(pactl list source-outputs | grep -B 4 "Source: $1" | sed -nE "s/^Source Output #([0-9]+)\$/\1/p")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function volUp() {
|
|
||||||
# Obtaining the current volume from pulseaudio into $VOL_LEVEL.
|
|
||||||
if ! getCurNode; then
|
|
||||||
echo "PulseAudio not running"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
getCurVol "$curNode"
|
|
||||||
local maxLimit=$((VOLUME_MAX - VOLUME_STEP))
|
|
||||||
|
|
||||||
# Checking the volume upper bounds so that if VOLUME_MAX was 100% and the
|
|
||||||
# increase percentage was 3%, a 99% volume would top at 100% instead
|
|
||||||
# of 102%. If the volume is above the maximum limit, nothing is done.
|
|
||||||
if [ "$VOL_LEVEL" -le "$VOLUME_MAX" ] && [ "$VOL_LEVEL" -ge "$maxLimit" ]; then
|
|
||||||
pactl "set-s${SINK_OR_SOURCE}-volume" "$curNode" "$VOLUME_MAX%"
|
|
||||||
elif [ "$VOL_LEVEL" -lt "$maxLimit" ]; then
|
|
||||||
pactl "set-s${SINK_OR_SOURCE}-volume" "$curNode" "+$VOLUME_STEP%"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ $OSD = "yes" ]; then showOSD "$curNode"; fi
|
|
||||||
if [ $AUTOSYNC = "yes" ]; then volSync; fi
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function volDown() {
|
|
||||||
# Pactl already handles the volume lower bounds so that negative values
|
|
||||||
# are ignored.
|
|
||||||
if ! getCurNode; then
|
|
||||||
echo "PulseAudio not running"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
pactl "set-s${SINK_OR_SOURCE}-volume" "$curNode" "-$VOLUME_STEP%"
|
|
||||||
|
|
||||||
if [ $OSD = "yes" ]; then showOSD "$curNode"; fi
|
|
||||||
if [ $AUTOSYNC = "yes" ]; then volSync; fi
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function volSync() {
|
|
||||||
# This will only be called if $AUTOSYNC is `yes`.
|
|
||||||
|
|
||||||
if ! getCurNode; then
|
|
||||||
echo "PulseAudio not running"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
getCurVol "$curNode"
|
|
||||||
|
|
||||||
if [[ "$NODE_TYPE" = "output" ]]; then
|
|
||||||
getSinkInputs "$curNode"
|
|
||||||
|
|
||||||
# Every output found in the active sink has their volume set to the
|
|
||||||
# current one.
|
|
||||||
for each in $sinkInputs; do
|
|
||||||
pactl "set-sink-input-volume" "$each" "$VOL_LEVEL%"
|
|
||||||
done
|
|
||||||
else
|
|
||||||
getSourceOutputs "$curNode"
|
|
||||||
|
|
||||||
# Every input found in the active source has their volume set to the
|
|
||||||
# current one.
|
|
||||||
for each in $sourceOutputs; do
|
|
||||||
pactl "set-source-output-volume" "$each" "$VOL_LEVEL%"
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function volMute() {
|
|
||||||
# Switch to mute/unmute the volume with pactl.
|
|
||||||
if ! getCurNode; then
|
|
||||||
echo "PulseAudio not running"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
if [ "$1" = "toggle" ]; then
|
|
||||||
getIsMuted "$curNode"
|
|
||||||
if [ "$IS_MUTED" = "yes" ]; then
|
|
||||||
pactl "set-s${SINK_OR_SOURCE}-mute" "$curNode" "no"
|
|
||||||
else
|
|
||||||
pactl "set-s${SINK_OR_SOURCE}-mute" "$curNode" "yes"
|
|
||||||
fi
|
|
||||||
elif [ "$1" = "mute" ]; then
|
|
||||||
pactl "set-s${SINK_OR_SOURCE}-mute" "$curNode" "yes"
|
|
||||||
elif [ "$1" = "unmute" ]; then
|
|
||||||
pactl "set-s${SINK_OR_SOURCE}-mute" "$curNode" "no"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ $OSD = "yes" ]; then showOSD "$curNode"; fi
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function nextNode() {
|
|
||||||
# The final nodes list, removing the blacklisted ones from the list of
|
|
||||||
# currently available nodes.
|
|
||||||
if ! getCurNode; then
|
|
||||||
echo "PulseAudio not running"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Obtaining a tuple of node indexes after removing the blacklisted devices
|
|
||||||
# with their name.
|
|
||||||
nodes=()
|
|
||||||
local i=0
|
|
||||||
while read -r line; do
|
|
||||||
index=$(echo "$line" | cut -f1)
|
|
||||||
name=$(echo "$line" | cut -f2)
|
|
||||||
|
|
||||||
# If it's in the blacklist, continue the main loop. Otherwise, add
|
|
||||||
# it to the list.
|
|
||||||
for node in "${NODE_BLACKLIST[@]}"; do
|
|
||||||
# shellcheck disable=SC2053 # Disable Shellcheck warning for Glob-Matching
|
|
||||||
if [[ "$name" == $node ]]; then
|
|
||||||
continue 2
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
nodes[i]="$index"
|
|
||||||
i=$((i + 1))
|
|
||||||
done < <(pactl list short "s${SINK_OR_SOURCE}s" | sort -n)
|
|
||||||
|
|
||||||
# If the resulting list is empty, nothing is done
|
|
||||||
if [ ${#nodes[@]} -eq 0 ]; then return; fi
|
|
||||||
|
|
||||||
# If the current node is greater or equal than last one, pick the first
|
|
||||||
# node in the list. Otherwise just pick the next node avaliable.
|
|
||||||
local newNode
|
|
||||||
if [ "$curNode" -ge "${nodes[-1]}" ]; then
|
|
||||||
newNode=${nodes[0]}
|
|
||||||
else
|
|
||||||
for node in "${nodes[@]}"; do
|
|
||||||
if [ "$curNode" -lt "$node" ]; then
|
|
||||||
newNode=$node
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
# The new node is set
|
|
||||||
pactl "set-default-s${SINK_OR_SOURCE}" "$newNode"
|
|
||||||
|
|
||||||
# Move all audio threads to new node
|
|
||||||
local inputs
|
|
||||||
|
|
||||||
if [[ "$NODE_TYPE" = "output" ]]; then
|
|
||||||
inputs="$(pactl list short sink-inputs | cut -f 1)"
|
|
||||||
for i in $inputs; do
|
|
||||||
pactl move-sink-input "$i" "$newNode"
|
|
||||||
done
|
|
||||||
else
|
|
||||||
outputs="$(pactl list short source-outputs | cut -f 1)"
|
|
||||||
for i in $outputs; do
|
|
||||||
pactl move-source-output "$i" "$newNode"
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ $NOTIFICATIONS = "yes" ]; then
|
|
||||||
getNickname "$newNode"
|
|
||||||
|
|
||||||
if command -v dunstify &>/dev/null; then
|
|
||||||
notify="dunstify --replace 201839192"
|
|
||||||
else
|
|
||||||
notify="notify-send"
|
|
||||||
fi
|
|
||||||
$notify "PulseAudio" "Changed $NODE_TYPE to $NODE_NICKNAME" --icon=audio-headphones-symbolic &
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# This function assumes that PulseAudio is already running. It only supports
|
|
||||||
# KDE OSDs for now. It will show a system message with the status of the
|
|
||||||
# node passed by parameter, or the currently active one by default.
|
|
||||||
function showOSD() {
|
|
||||||
if [ -z "$1" ]; then
|
|
||||||
curNode="$1"
|
|
||||||
else
|
|
||||||
getCurNode
|
|
||||||
fi
|
|
||||||
getCurVol "$curNode"
|
|
||||||
getIsMuted "$curNode"
|
|
||||||
qdbus org.kde.kded /modules/kosd showVolume "$VOL_LEVEL" "$IS_MUTED"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function listen() {
|
|
||||||
# If this is the first time start by printing the current state. Otherwise,
|
|
||||||
# directly wait for events. This is to prevent the module being empty until
|
|
||||||
# an event occurs.
|
|
||||||
output
|
|
||||||
|
|
||||||
# Listen for changes and immediately create new output for the bar.
|
|
||||||
# This is faster than having the script on an interval.
|
|
||||||
pactl subscribe 2>/dev/null | grep --line-buffered -e "on \(card\|s${SINK_OR_SOURCE}\|server\)" | {
|
|
||||||
while read -r; do
|
|
||||||
# Output the new state
|
|
||||||
output
|
|
||||||
|
|
||||||
# Read all stdin to flush unwanted pending events, i.e. if there are
|
|
||||||
# 15 events at the same time (100ms window), output is only called
|
|
||||||
# twice.
|
|
||||||
read -r -d '' -t "$LISTEN_TIMEOUT" -n 10000
|
|
||||||
|
|
||||||
# After the 100ms waiting time, output again the state, as it may
|
|
||||||
# have changed if the user did an action during the 100ms window.
|
|
||||||
output
|
|
||||||
done
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function output() {
|
|
||||||
if ! getCurNode; then
|
|
||||||
echo "PulseAudio not running"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
getCurVol "$curNode"
|
|
||||||
getIsMuted "$curNode"
|
|
||||||
|
|
||||||
# Fixed volume icons over max volume
|
|
||||||
local iconsLen=${#ICONS_VOLUME[@]}
|
|
||||||
if [ "$iconsLen" -ne 0 ]; then
|
|
||||||
local volSplit=$((VOLUME_MAX / iconsLen))
|
|
||||||
for i in $(seq 1 "$iconsLen"); do
|
|
||||||
if [ $((i * volSplit)) -ge "$VOL_LEVEL" ]; then
|
|
||||||
VOL_ICON="${ICONS_VOLUME[$((i-1))]}"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
else
|
|
||||||
VOL_ICON=""
|
|
||||||
fi
|
|
||||||
|
|
||||||
getNickname "$curNode"
|
|
||||||
|
|
||||||
# Showing the formatted message
|
|
||||||
if [ "$IS_MUTED" = "yes" ]; then
|
|
||||||
# shellcheck disable=SC2034
|
|
||||||
VOL_ICON=$ICON_MUTED
|
|
||||||
content="$(eval echo "$FORMAT")"
|
|
||||||
if [ -n "$COLOR_MUTED" ]; then
|
|
||||||
echo "${COLOR_MUTED}${content}${END_COLOR}"
|
|
||||||
else
|
|
||||||
echo "$content"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
eval echo "$FORMAT"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function usage() {
|
|
||||||
echo "\
|
|
||||||
Usage: $0 [OPTION...] ACTION
|
|
||||||
|
|
||||||
Terminology: A node represents either a sink (output) or source (input).
|
|
||||||
|
|
||||||
Options:
|
|
||||||
--autosync | --no-autosync
|
|
||||||
Whether to maintain same volume for all programs.
|
|
||||||
Default: \"$AUTOSYNC\"
|
|
||||||
--color-muted <rrggbb>
|
|
||||||
Color in which to format when muted.
|
|
||||||
Pass empty string to disable.
|
|
||||||
Default: \"${COLOR_MUTED:4:-1}\"
|
|
||||||
--notifications | --no-notifications
|
|
||||||
Whether to show notifications when changing nodes.
|
|
||||||
Default: \"$NOTIFICATIONS\"
|
|
||||||
--osd | --no-osd
|
|
||||||
Whether to display KDE's OSD message.
|
|
||||||
Default: \"$OSD\"
|
|
||||||
--icon-muted <icon>
|
|
||||||
Icon to use when muted.
|
|
||||||
Default: none
|
|
||||||
--icon-node <icon>
|
|
||||||
Icon to use for node.
|
|
||||||
Default: none
|
|
||||||
--format <string>
|
|
||||||
Use a format string to control the output.
|
|
||||||
Remember to pass this argument wrapped in single quotes (\`'\`) instead
|
|
||||||
of double quotes (\`\"\`) to avoid your shell from evaluating the
|
|
||||||
variables early.
|
|
||||||
Available variables:
|
|
||||||
* \$VOL_ICON
|
|
||||||
* \$VOL_LEVEL
|
|
||||||
* \$ICON_NODE
|
|
||||||
* \$NODE_NICKNAME
|
|
||||||
* \$IS_MUTED (yes/no)
|
|
||||||
Default: '$FORMAT'
|
|
||||||
--icons-volume <icon>[,<icon>...]
|
|
||||||
Icons for volume, from lower to higher.
|
|
||||||
Default: none
|
|
||||||
--node-type <node_type>
|
|
||||||
Whether to consider PulseAudio sinks (output) or sources (input).
|
|
||||||
All the operations of pulseaudio-control will apply to one of the two.
|
|
||||||
Pass \`input\` for the sources, e.g. a microphone.
|
|
||||||
Pass \`output\` for the sinks, e.g. speakers, headphones.
|
|
||||||
Default: \"$NODE_TYPE\"
|
|
||||||
--volume-max <int>
|
|
||||||
Maximum volume to which to allow increasing.
|
|
||||||
Default: \"$VOLUME_MAX\"
|
|
||||||
--volume-step <int>
|
|
||||||
Step size when inc/decrementing volume.
|
|
||||||
Default: \"$VOLUME_STEP\"
|
|
||||||
--node-blacklist <name>[,<name>...]
|
|
||||||
Nodes to ignore when switching. You can use globs. Don't forget to
|
|
||||||
quote the string when using globs, to avoid unwanted shell glob
|
|
||||||
extension.
|
|
||||||
Default: none
|
|
||||||
--node-nicknames-from <prop>
|
|
||||||
pactl property to use for node names, unless overridden by
|
|
||||||
--node-nickname. Its possible values are listed under the 'Properties'
|
|
||||||
key in the output of \`pactl list sinks\` and \`pactl list sources\`.
|
|
||||||
Default: none
|
|
||||||
--node-nickname <name>:<nick>
|
|
||||||
Nickname to assign to given node name, taking priority over
|
|
||||||
--node-nicknames-from. May be given multiple times, and 'name' is
|
|
||||||
exactly as listed in the output of \`pactl list sinks short | cut -f2\`
|
|
||||||
and \`pactl list sources short | cut -f2\`.
|
|
||||||
Note that you can also specify a port name for the node with
|
|
||||||
\`<name>/<port>\`.
|
|
||||||
It is also possible to use glob matching to match node and port names.
|
|
||||||
Exact matches are prioritized. Don't forget to quote the string when
|
|
||||||
using globs, to avoid unwanted shell glob extension.
|
|
||||||
Default: none
|
|
||||||
--listen-timeout-secs
|
|
||||||
The listen command updates the output as soon as it receives an event
|
|
||||||
from PulseAudio. However, events are often accompanied by many other
|
|
||||||
useless ones, which may result in unnecessary consecutive output
|
|
||||||
updates. This script buffers the following events until a timeout is
|
|
||||||
reached to avoid this scenario, which lessens the CPU load on events.
|
|
||||||
However, this may result in noticeable latency when performing many
|
|
||||||
actions quickly (e.g., updating the volume with the mouse wheel). You
|
|
||||||
can specify what timeout to use to control the responsiveness, in
|
|
||||||
seconds.
|
|
||||||
Default: \"$LISTEN_TIMEOUT\"
|
|
||||||
|
|
||||||
Actions:
|
|
||||||
help display this message and exit
|
|
||||||
output print the PulseAudio status once
|
|
||||||
listen listen for changes in PulseAudio to automatically update
|
|
||||||
this script's output
|
|
||||||
up, down increase or decrease the default node's volume
|
|
||||||
mute, unmute mute or unmute the default node's audio
|
|
||||||
togmute switch between muted and unmuted
|
|
||||||
next-node switch to the next available node
|
|
||||||
sync synchronize all the output streams volume to be the same as
|
|
||||||
the current node's volume
|
|
||||||
|
|
||||||
Author:
|
|
||||||
Mario Ortiz Manero
|
|
||||||
More info on GitHub:
|
|
||||||
https://github.com/marioortizmanero/polybar-pulseaudio-control"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Obtains the value for an option and returns 1 if no shift is needed.
|
|
||||||
function getOptVal() {
|
|
||||||
if [[ "$1" = *=* ]]; then
|
|
||||||
val="${1//*=/}"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
val="$2"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Parsing the options from the arguments
|
|
||||||
while [[ "$1" = --* ]]; do
|
|
||||||
unset arg
|
|
||||||
unset val
|
|
||||||
|
|
||||||
arg="$1"
|
|
||||||
case "$arg" in
|
|
||||||
--autosync)
|
|
||||||
AUTOSYNC=yes
|
|
||||||
;;
|
|
||||||
--no-autosync)
|
|
||||||
AUTOSYNC=no
|
|
||||||
;;
|
|
||||||
--color-muted|--colour-muted)
|
|
||||||
if getOptVal "$@"; then shift; fi
|
|
||||||
COLOR_MUTED="%{F#$val}"
|
|
||||||
;;
|
|
||||||
--notifications)
|
|
||||||
NOTIFICATIONS=yes
|
|
||||||
;;
|
|
||||||
--no-notifications)
|
|
||||||
NOTIFICATIONS=no
|
|
||||||
;;
|
|
||||||
--osd)
|
|
||||||
OSD=yes
|
|
||||||
;;
|
|
||||||
--no-osd)
|
|
||||||
OSD=no
|
|
||||||
;;
|
|
||||||
--icon-muted)
|
|
||||||
if getOptVal "$@"; then shift; fi
|
|
||||||
ICON_MUTED="$val"
|
|
||||||
;;
|
|
||||||
--icon-node)
|
|
||||||
if getOptVal "$@"; then shift; fi
|
|
||||||
# shellcheck disable=SC2034
|
|
||||||
ICON_NODE="$val"
|
|
||||||
;;
|
|
||||||
--icons-volume)
|
|
||||||
if getOptVal "$@"; then shift; fi
|
|
||||||
IFS=, read -r -a ICONS_VOLUME <<< "${val//[[:space:]]/}"
|
|
||||||
;;
|
|
||||||
--volume-max)
|
|
||||||
if getOptVal "$@"; then shift; fi
|
|
||||||
VOLUME_MAX="$val"
|
|
||||||
;;
|
|
||||||
--volume-step)
|
|
||||||
if getOptVal "$@"; then shift; fi
|
|
||||||
VOLUME_STEP="$val"
|
|
||||||
;;
|
|
||||||
--node-blacklist)
|
|
||||||
if getOptVal "$@"; then shift; fi
|
|
||||||
IFS=, read -r -a NODE_BLACKLIST <<< "${val//[[:space:]]/}"
|
|
||||||
;;
|
|
||||||
--node-nicknames-from)
|
|
||||||
if getOptVal "$@"; then shift; fi
|
|
||||||
NODE_NICKNAMES_PROP="$val"
|
|
||||||
;;
|
|
||||||
--node-nickname)
|
|
||||||
if getOptVal "$@"; then shift; fi
|
|
||||||
NODE_NICKNAMES["${val//:*/}"]="${val//*:}"
|
|
||||||
;;
|
|
||||||
--format)
|
|
||||||
if getOptVal "$@"; then shift; fi
|
|
||||||
FORMAT="$val"
|
|
||||||
;;
|
|
||||||
--node-type)
|
|
||||||
if getOptVal "$@"; then shift; fi
|
|
||||||
if [[ "$val" != "output" && "$val" != "input" ]]; then
|
|
||||||
echo "node-type must be 'output' or 'input', got '$val'" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
NODE_TYPE="$val"
|
|
||||||
SINK_OR_SOURCE=$([ "$NODE_TYPE" == "output" ] && echo "ink" || echo "ource")
|
|
||||||
;;
|
|
||||||
--listen-timeout-secs)
|
|
||||||
if getOptVal "$@"; then shift; fi
|
|
||||||
LISTEN_TIMEOUT="$val"
|
|
||||||
;;
|
|
||||||
# Deprecated options, to be removed in a next release
|
|
||||||
--icon-sink)
|
|
||||||
echo "Replaced by --icon-node, see https://github.com/marioortizmanero/polybar-pulseaudio-control/releases/tag/v3.0.0" >&2
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
--sink-blacklist)
|
|
||||||
echo "Replaced by --node-blacklist, see https://github.com/marioortizmanero/polybar-pulseaudio-control/releases/tag/v3.0.0" >&2
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
--sink-nicknames-from)
|
|
||||||
echo "Replaced by --node-nicknames-from, see https://github.com/marioortizmanero/polybar-pulseaudio-control/releases/tag/v3.0.0" >&2
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
--sink-nickname)
|
|
||||||
echo "Replaced by --node-nickname, see https://github.com/marioortizmanero/polybar-pulseaudio-control/releases/tag/v3.0.0" >&2
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
# Undocumented because the `help` action already exists, but makes the
|
|
||||||
# help message more accessible.
|
|
||||||
--help)
|
|
||||||
usage
|
|
||||||
exit 0
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Unrecognised option: $arg" >&2
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
|
|
||||||
# Parsing the action from the arguments
|
|
||||||
case "$1" in
|
|
||||||
up)
|
|
||||||
volUp
|
|
||||||
;;
|
|
||||||
down)
|
|
||||||
volDown
|
|
||||||
;;
|
|
||||||
togmute)
|
|
||||||
volMute toggle
|
|
||||||
;;
|
|
||||||
mute)
|
|
||||||
volMute mute
|
|
||||||
;;
|
|
||||||
unmute)
|
|
||||||
volMute unmute
|
|
||||||
;;
|
|
||||||
sync)
|
|
||||||
volSync
|
|
||||||
;;
|
|
||||||
listen)
|
|
||||||
listen
|
|
||||||
;;
|
|
||||||
next-node)
|
|
||||||
nextNode
|
|
||||||
;;
|
|
||||||
output)
|
|
||||||
output
|
|
||||||
;;
|
|
||||||
help)
|
|
||||||
usage
|
|
||||||
;;
|
|
||||||
# Deprecated action, to be removed in a next release
|
|
||||||
next-sink)
|
|
||||||
echo "Replaced by next-node, see https://github.com/marioortizmanero/polybar-pulseaudio-control/releases/tag/v3.0.0" >&2
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
"")
|
|
||||||
echo "No action specified. Run \`$0 help\` for more information." >&2
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Unrecognised action: $1" >&2
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
|
@ -1,64 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
bluetooth_print() {
|
|
||||||
bluetoothctl | while read -r; do
|
|
||||||
if [ "$(systemctl is-active "bluetooth.service")" = "active" ]; then
|
|
||||||
if bluetoothctl show | grep -q "Powered: no"; then
|
|
||||||
echo " "
|
|
||||||
else
|
|
||||||
printf ' '
|
|
||||||
|
|
||||||
devices_paired=$(bluetoothctl devices Paired | grep Device | cut -d ' ' -f 2)
|
|
||||||
counter=0
|
|
||||||
|
|
||||||
for device in $devices_paired; do
|
|
||||||
device_info=$(bluetoothctl info "$device")
|
|
||||||
|
|
||||||
if echo "$device_info" | grep -q "Connected: yes"; then
|
|
||||||
device_alias=$(echo "$device_info" | grep "Alias" | cut -d ' ' -f 2-)
|
|
||||||
|
|
||||||
if [ $counter -gt 0 ]; then
|
|
||||||
printf ", %s" "$device_alias"
|
|
||||||
else
|
|
||||||
printf " %s" "$device_alias"
|
|
||||||
fi
|
|
||||||
|
|
||||||
counter=$((counter + 1))
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
printf '\n'
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo " "
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
bluetooth_toggle() {
|
|
||||||
if bluetoothctl show | grep -q "Powered: no"; then
|
|
||||||
bluetoothctl power on >> /dev/null
|
|
||||||
sleep 1
|
|
||||||
|
|
||||||
devices_paired=$(bluetoothctl devices Paired | grep Device | cut -d ' ' -f 2)
|
|
||||||
echo "$devices_paired" | while read -r line; do
|
|
||||||
bluetoothctl connect "$line" >> /dev/null
|
|
||||||
done
|
|
||||||
else
|
|
||||||
devices_paired=$(bluetoothctl devices Paired | grep Device | cut -d ' ' -f 2)
|
|
||||||
echo "$devices_paired" | while read -r line; do
|
|
||||||
bluetoothctl disconnect "$line" >> /dev/null
|
|
||||||
done
|
|
||||||
|
|
||||||
bluetoothctl power off >> /dev/null
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
case "$1" in
|
|
||||||
--toggle)
|
|
||||||
bluetooth_toggle
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
bluetooth_print
|
|
||||||
;;
|
|
||||||
esac
|
|
Loading…
Reference in a new issue