From d93bf44ae057a3f6cf5ec78d8c0f1c351fd2fefc Mon Sep 17 00:00:00 2001 From: aleidk Date: Tue, 19 Nov 2024 15:48:29 -0300 Subject: [PATCH 1/2] add pre_deploy.sh script for dotter --- .dotter/global.toml | 24 ++++----- .dotter/handlebars_helpers/flatten_table.rhai | 30 +++++++++++ .dotter/handlebars_helpers/header.rhai | 48 +++++++++++++++++ .dotter/machines/fedora.toml | 54 +++++++++++++++++++ .dotter/pre_deploy.sh | 44 ++++++++++++++- .dotter/work-laptop.toml | 4 +- config/git/config | 4 ++ 7 files changed, 192 insertions(+), 16 deletions(-) create mode 100644 .dotter/handlebars_helpers/flatten_table.rhai create mode 100644 .dotter/handlebars_helpers/header.rhai create mode 100644 .dotter/machines/fedora.toml diff --git a/.dotter/global.toml b/.dotter/global.toml index 748bd20..42caea7 100644 --- a/.dotter/global.toml +++ b/.dotter/global.toml @@ -1,14 +1,9 @@ -[default] -depends = ["nvim"] +[settings] +default_target_type = "automatic" -[default.files] -"README.md" = "" -chezmoi = "" -config = "" -exports = "" -scripts = "" - -[default.variables] +[helpers] +flatten_table = ".dotter/handlebars_helpers/flatten_table.rhai" +header = ".dotter/handlebars_helpers/header.rhai" # CLI package [cli] @@ -22,6 +17,9 @@ depends = ["nvim", "zsh"] "config/yazi" = "~/.config/yazi" "config/zellij" = "~/.config/zellij" +[dev] +depends = ["rust"] + [dev.files] "config/git" = "~/.config/git" "config/lazygit" = { target = "~/.config/lazygit", type = "symbolic"} @@ -38,8 +36,8 @@ depends = ["nvim", "zsh"] [nushell.files] "config/nushell" = "~/.config/nushell" -[settings] -default_target_type = "automatic" - [nvim.files] "config/nvim" = "~/.config/nvim" + +[rust.variables] +cargo.packages = [] diff --git a/.dotter/handlebars_helpers/flatten_table.rhai b/.dotter/handlebars_helpers/flatten_table.rhai new file mode 100644 index 0000000..30ee4f9 --- /dev/null +++ b/.dotter/handlebars_helpers/flatten_table.rhai @@ -0,0 +1,30 @@ +/* +* Flatten a table into a list of values. +* The table has to be in the form of +* ```toml +* [table.subtable] +* variable1 = ["value1", "value2"] +* +* [table.subtable] +* variable2 = ["value3", "value4"] +* +* then we use it in handlerbars like this: +* +* {{ flatten_table table.subtable }} +* +* and it will return an array with all the arrays of subtable +*/ + +if type_of(params[0]) != "map" { + return; +} + +let table = params[0]; + +let result = []; + +for value in table.values() { + result.append(value); +} + +result diff --git a/.dotter/handlebars_helpers/header.rhai b/.dotter/handlebars_helpers/header.rhai new file mode 100644 index 0000000..1a35fc7 --- /dev/null +++ b/.dotter/handlebars_helpers/header.rhai @@ -0,0 +1,48 @@ +let x_padding = hash["padding"] ?? 50; + +let header = #{ + x_padding: x_padding, + out: "", + append: |suffix| { + this.out += suffix + "\n"; + }, + append_center: |suffix| { + + let suffix_len = suffix.len(); + let padding = this.x_padding - suffix_len / 2; + let fill = ""; + fill.pad(padding, " "); + + this.out += fill + suffix.to_upper() + fill + "\n"; + }, + append_divider: || { + let divider = ""; + divider.pad(this.x_padding * 2, "─"); + + this.append(divider); + }, + open_echo: || { + this.out += "echo -e '\n"; + }, + close_echo: || { + this.out += "'"; + }, + to_string: || { + return this.out; + } +}; + +header.open_echo(); + +header.append_divider(); + + +params.for_each(|idx| { + header.append_center(this); +}); + +header.append_divider(); +header.close_echo(); + +return header.to_string(); + diff --git a/.dotter/machines/fedora.toml b/.dotter/machines/fedora.toml new file mode 100644 index 0000000..63e5773 --- /dev/null +++ b/.dotter/machines/fedora.toml @@ -0,0 +1,54 @@ +# Dotter only support merging tables, and put the key-values into the global scope of the tables +# If we try to use the same variable name in a package, it will throw an error +# if we try to use the same key in a nested table, it will be overriden with the last value +# +# the fix to this is to have a table with unique keys, this is supported by handlerbars {{#each}} directive +# but will give us an array as value, so we need to flatten it + +[utils.variables] +pkg-install = "sudo dnf install -y" + +[cli.variables.copr] +cli = [ + "atim/lazygit", + "atim/starship" +] + +[cli.variables.packages] +cli = [ + "bat", + "dnf-plugin-system-upgrade", + "duf", + "eza", + "fd-find", + "firefox-dev", + "flatpak", + "fzf", + "git", + "lazygit", + "neovim", + "remove-retired-packages", + "ripgrep", + "sd", + "starship", + "tealdeer", + "zoxide", + "zsh", +] + +[dev.variables.packages] +dev = [ + "gcc", + "gcc-c++", + "nodejs", + "openssl", + "openssl-devel", + "tmux", + "tree-sitter-cli", +] + +[rust.variables] +cargo.packages = [ + "yazi-fm", + "yazi-cli", +] diff --git a/.dotter/pre_deploy.sh b/.dotter/pre_deploy.sh index bbb0008..2cddc64 100644 --- a/.dotter/pre_deploy.sh +++ b/.dotter/pre_deploy.sh @@ -1 +1,43 @@ -sudo dnf install -y {{# each packages }} {{ this }} {{/each}} +#!/usr/bin/env bash +# shellcheck disable=all +# This is a handlerbars template, so ignore issues + +{{!~ Detect the distribution ~}} +{{~ assign "distro" (trim (command_output "awk -F= '/^ID=/ {print $2}' /etc/os-release | tr -d '\"'")) ~}} + +{{ header "Running pre deploy script for distro" (to_title_case distro) }} + +{{#if (eq distro "fedora") ~}} + +{{! extract the copr repositories variable }} +{{~ assign "copr" (flatten_table copr) ~}} + +{{#if (ne (len copr) 0) ~}} +{{ header "Enabling copr repositories" }} + +{{# each copr }} +sudo -B dnf copr enable -y '{{ this }}' +{{ /each }} + +{{~ /if }} + +{{ header "Installing dnf packages" }} +sudo -B dnf install -y {{~# each (flatten_table packages) }} '{{ this }}' {{~ /each }} + +{{~ /if }} + +{{#if (and dotter.packages.rust (not (is_executable "cargo"))) }} + +{{ header "Installing rust" }} +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path --default-toolchain stable + +{{ /if }} + +{{#if (and dotter.packages.rust (ne (len cargo.packages) 0)) }} + +{{ header "Installing crates" }} +cargo install --locked {{# each cargo.packages }} "{{ this }}" {{ /each }} + +{{ /if }} + +{{ header "Done :3" }} diff --git a/.dotter/work-laptop.toml b/.dotter/work-laptop.toml index 7709e32..8e15648 100644 --- a/.dotter/work-laptop.toml +++ b/.dotter/work-laptop.toml @@ -1,5 +1,5 @@ -includes = [] -packages = ["default", "cli", "dev"] +includes = [".dotter/machines/fedora.toml"] +packages = ["cli", "dev"] [files] diff --git a/config/git/config b/config/git/config index 0c713a8..65fa801 100644 --- a/config/git/config +++ b/config/git/config @@ -8,3 +8,7 @@ [includeIf "gitdir:~/Repos/Work/"] path = ~/.config/git/config-work +[merge] + autoStash = true +[rebase] + autoStash = true From 76e89bf33c5a46bc2d35b74b568cfa38c600126a Mon Sep 17 00:00:00 2001 From: aleidk Date: Tue, 19 Nov 2024 15:48:45 -0300 Subject: [PATCH 2/2] minor_updates --- .../nvim/lua/aleidk/plugins/file-explorer.lua | 2 +- config/nvim/lua/aleidk/plugins/init.lua | 43 ------------------- config/nvim/lua/aleidk/plugins/lsp.lua | 3 ++ config/yazi/keymap.toml | 16 +++---- config/yazi/yazi.toml | 2 +- 5 files changed, 13 insertions(+), 53 deletions(-) diff --git a/config/nvim/lua/aleidk/plugins/file-explorer.lua b/config/nvim/lua/aleidk/plugins/file-explorer.lua index e7b6eaa..ab03cca 100644 --- a/config/nvim/lua/aleidk/plugins/file-explorer.lua +++ b/config/nvim/lua/aleidk/plugins/file-explorer.lua @@ -1,7 +1,7 @@ ---@type LazySpec return { "mikavilpas/yazi.nvim", - event = "VeryLazy", + -- event = "VeryLazy", keys = { -- 👇 in this section, choose your own keymappings! { diff --git a/config/nvim/lua/aleidk/plugins/init.lua b/config/nvim/lua/aleidk/plugins/init.lua index 8dbb557..4c6fcb8 100644 --- a/config/nvim/lua/aleidk/plugins/init.lua +++ b/config/nvim/lua/aleidk/plugins/init.lua @@ -35,41 +35,6 @@ return { { "uC", "CccHighlighterToggle", desc = "Toggle Color highlight" }, }, }, - -- Dotfiles management - { - "xvzc/chezmoi.nvim", - dependencies = { "nvim-lua/plenary.nvim", "alker0/chezmoi.vim" }, - config = function() - require("chezmoi").setup({ - { - edit = { - watch = false, - force = false, - }, - notification = { - on_open = true, - on_apply = true, - on_watch = false, - }, - telescope = { - select = { "" }, - }, - }, - }) - - vim.api.nvim_create_autocmd({ "BufRead", "BufNewFile" }, { - -- INFO: this should be the same as $(chezmoi source-path) - pattern = { os.getenv("HOME") .. "/.local/share/chezmoi/chezmoi/*" }, - callback = function() - vim.schedule(require("chezmoi.commands.__edit").watch) - end, - }) - local telescope = require("telescope") - - telescope.load_extension("chezmoi") - vim.keymap.set("n", "fz", telescope.extensions.chezmoi.find_files, { desc = "Find dotfile" }) - end, - }, { "pmizio/typescript-tools.nvim", dependencies = { "nvim-lua/plenary.nvim", "neovim/nvim-lspconfig" }, @@ -88,12 +53,4 @@ return { }, }, }, - - { - "olexsmir/gopher.nvim", - ft = "go", - build = function() - vim.cmd([[silent! GoInstallDeps]]) - end, - }, } diff --git a/config/nvim/lua/aleidk/plugins/lsp.lua b/config/nvim/lua/aleidk/plugins/lsp.lua index 4a4c40d..ab2f1aa 100644 --- a/config/nvim/lua/aleidk/plugins/lsp.lua +++ b/config/nvim/lua/aleidk/plugins/lsp.lua @@ -175,6 +175,9 @@ return { }), ["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = _border, + max_width = 200, + max_height = 200, + focus = true, }), }, } diff --git a/config/yazi/keymap.toml b/config/yazi/keymap.toml index 6e42a49..4c37eb5 100644 --- a/config/yazi/keymap.toml +++ b/config/yazi/keymap.toml @@ -45,11 +45,11 @@ keymap = [ { on = ["J"], run = "seek 5", desc = "Seek down 5 units in the preview" }, # Selection - { on = [ "" ], run = [ "select --state=none", "arrow 1" ], desc = "Toggle the current selection state" }, + { on = [ "" ], run = [ "toggle", "arrow 1" ], desc = "Toggle the current selection state" }, { on = [ "v" ], run = "visual_mode", desc = "Enter visual mode (selection mode)" }, { on = [ "V" ], run = "visual_mode --unset", desc = "Enter visual mode (unset mode)" }, - { on = [ "" ], run = "select_all --state=true", desc = "Select all files" }, - { on = [ "" ], run = "select_all --state=none", desc = "Inverse selection of all files" }, + { on = [ "" ], run = "toggle_all", desc = "Select all files" }, + { on = [ "" ], run = "toggle_all on", desc = "Inverse selection of all files" }, # Operation { on = [ "o" ], run = "open", desc = "Open the selected files" }, @@ -98,10 +98,10 @@ keymap = [ { on = [ "N" ], run = "find_arrow --previous", desc = "Go to previous found file" }, # Sorting - { on = [ ",", "m" ], run = "sort modified --reverse=no", desc = "Sort by modified time" }, - { on = [ ",", "M" ], run = "sort modified --reverse", desc = "Sort by modified time (reverse)" }, - { on = [ ",", "c" ], run = "sort created --reverse=no", desc = "Sort by created time" }, - { on = [ ",", "C" ], run = "sort created --reverse", desc = "Sort by created time (reverse)" }, + { on = [ ",", "m" ], run = "sort mtime --reverse=no", desc = "Sort by modified time" }, + { on = [ ",", "M" ], run = "sort mtime --reverse", desc = "Sort by modified time (reverse)" }, + { on = [ ",", "c" ], run = "sort btime --reverse=no", desc = "Sort by created time" }, + { on = [ ",", "C" ], run = "sort btime --reverse", desc = "Sort by created time (reverse)" }, { on = [ ",", "e" ], run = "sort extension --reverse=no", desc = "Sort by extension" }, { on = [ ",", "E" ], run = "sort extension --reverse", desc = "Sort by extension (reverse)" }, { on = [ ",", "a" ], run = "sort alphabetical --reverse=no", desc = "Sort alphabetically" }, @@ -162,7 +162,7 @@ keymap = [ { on = [ "~" ], run = "help", desc = "Open help" } ] -[select] +[pick] keymap = [ { on = [ "" ], run = "close", desc = "Cancel selection" }, diff --git a/config/yazi/yazi.toml b/config/yazi/yazi.toml index e59bd36..9c93301 100644 --- a/config/yazi/yazi.toml +++ b/config/yazi/yazi.toml @@ -188,7 +188,7 @@ quit_title = "{n} task{s} running, sure to quit? (y/N)" quit_origin = "center" quit_offset = [ 0, 2, 50, 3 ] -[select] +[pick] open_title = "Open with:" open_origin = "hovered" open_offset = [ 0, 1, 50, 7 ]