From e180de3a7bec7a4f0c205c1cb936a34007fc6f40 Mon Sep 17 00:00:00 2001 From: Job79 Date: Thu, 12 Dec 2024 20:42:39 +0100 Subject: [PATCH] refactor: cleanup config --- Containerfile | 5 ++ build.sh | 2 - config/nvim/config/keymaps.lua | 17 ++--- config/nvim/lazyvim.json | 5 +- config/nvim/plugins/autocomplete.lua | 10 --- config/nvim/plugins/colorscheme.lua | 9 +-- config/nvim/plugins/disabled.lua | 21 +++++- config/nvim/plugins/lsp.lua | 7 -- enter.sh | 107 ++++++++++++--------------- 9 files changed, 83 insertions(+), 100 deletions(-) delete mode 100755 build.sh delete mode 100644 config/nvim/plugins/autocomplete.lua delete mode 100644 config/nvim/plugins/lsp.lua diff --git a/Containerfile b/Containerfile index 92cd881..b931b90 100644 --- a/Containerfile +++ b/Containerfile @@ -1,3 +1,8 @@ +# ========================================= # +# Containerfile v1.0; job79 # +# Configure and setup a neovim devcontainer # +# for go and nodejs development. # +# ========================================= # FROM quay.io/fedora/fedora:41 # === setup system === diff --git a/build.sh b/build.sh deleted file mode 100755 index be40679..0000000 --- a/build.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -podman build . $@ -t git.plabble.org/job79/dev diff --git a/config/nvim/config/keymaps.lua b/config/nvim/config/keymaps.lua index 6082ea7..cc3581d 100644 --- a/config/nvim/config/keymaps.lua +++ b/config/nvim/config/keymaps.lua @@ -1,24 +1,21 @@ --- Keymaps are automatically loaded on the VeryLazy event --- Default keymaps that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/keymaps.lua --- Add any additional keymaps here local keymap = vim.keymap.set local delkeymap = vim.keymap.del local opts = { noremap = true, silent = true } --- Better line start/end +-- Improved line start/end keymap("n", "H", "^", opts) keymap("n", "L", "$", opts) keymap("v", "H", "^", opts) keymap("v", "L", "$", opts) --- Better escape +-- Improved escape keymap("n", "", ":noh", opts) keymap("t", "", "", opts) --- Disable alt j/k to move lines -delkeymap({ "i", "v" }, "") -delkeymap({ "i", "v" }, "") - --- Better + movement +-- Improved + movement keymap("n", "", "zz", opts) keymap("n", "", "zz", opts) + +-- Disable alt j/k to move lines (conflict with default vim motions) +delkeymap({ "i", "v" }, "") +delkeymap({ "i", "v" }, "") diff --git a/config/nvim/lazyvim.json b/config/nvim/lazyvim.json index 23d131d..94d1b53 100644 --- a/config/nvim/lazyvim.json +++ b/config/nvim/lazyvim.json @@ -8,8 +8,5 @@ "lazyvim.plugins.extras.lang.typescript", "lazyvim.plugins.extras.test.core" ], - "news": { - "NEWS.md": "6520" - }, - "version": 6 + "version": 7 } diff --git a/config/nvim/plugins/autocomplete.lua b/config/nvim/plugins/autocomplete.lua deleted file mode 100644 index 1842736..0000000 --- a/config/nvim/plugins/autocomplete.lua +++ /dev/null @@ -1,10 +0,0 @@ --- Disable autocomplete on enter. -return { - "hrsh7th/nvim-cmp", - opts = function(_, opts) - local cmp = require("cmp") - opts.mapping = vim.tbl_deep_extend("force", opts.mapping, { - [""] = cmp.config.disable, - }) - end, -} diff --git a/config/nvim/plugins/colorscheme.lua b/config/nvim/plugins/colorscheme.lua index 9d7c53d..28c0feb 100644 --- a/config/nvim/plugins/colorscheme.lua +++ b/config/nvim/plugins/colorscheme.lua @@ -1,12 +1,9 @@ +-- Configure rose-pine and gruvbox-material colorschemes. return { { "rose-pine/neovim" }, + { "sainnhe/gruvbox-material" }, { - "sainnhe/gruvbox-material", - opts = function() - vim.g.gruvbox_material_foreground = "original" - end, - }, - { + -- Set default colorscheme. "LazyVim/LazyVim", opts = { colorscheme = "gruvbox-material", diff --git a/config/nvim/plugins/disabled.lua b/config/nvim/plugins/disabled.lua index d57c39a..be7c8de 100644 --- a/config/nvim/plugins/disabled.lua +++ b/config/nvim/plugins/disabled.lua @@ -1,13 +1,32 @@ --- Disable some unneeded plugins by default. +-- Disable unused plugins and functionality. return { { + -- Disable the dashboard. "folke/snacks.nvim", opts = function(_, opts) opts.dashboard = { enabled = false } end, }, { + -- Disable the bufferline. "bufferline.nvim", enabled = false, }, + { + -- Disable inline hints by default. + "neovim/nvim-lspconfig", + opts = { + inlay_hints = { enabled = false }, + }, + }, + { + "hrsh7th/nvim-cmp", + opts = function(_, opts) + -- Disable autocomplete on enter. + local cmp = require("cmp") + opts.mapping = vim.tbl_deep_extend("force", opts.mapping, { + [""] = cmp.config.disable, + }) + end, + }, } diff --git a/config/nvim/plugins/lsp.lua b/config/nvim/plugins/lsp.lua deleted file mode 100644 index 8b0fe2e..0000000 --- a/config/nvim/plugins/lsp.lua +++ /dev/null @@ -1,7 +0,0 @@ --- Disable inline hints by default. -return { - "neovim/nvim-lspconfig", - opts = { - inlay_hints = { enabled = false }, - }, -} diff --git a/enter.sh b/enter.sh index 2175f80..6ffc350 100755 --- a/enter.sh +++ b/enter.sh @@ -3,93 +3,80 @@ # enter.sh v1.0; job79 # # Enter into an existing or new dev container and # # automatically handle dev container updates. # +# # +# TODO # +# ----------------------------------------------- # +# remove --security-opt label=disable # +# configurable mount directories # # =============================================== # set -e -# podman_run opens a shell into a newly created dev container. -podman_run() { - args="--name $name" - arg() { args="$args $@"; } +# run_args returns the arguments required for the podman run +# command. +run_args() { + arg() { echo -n " $@"; } + arg "--name $name" - # Automatically update the container when a newer - # image is available. - [ "$no_pull" = 1 ] || arg "--pull newer" - - # Disable some security settings to make it possible to mount - # host directories without problems. - arg "--security-opt label=disable" # disable labeling so mounts don't need to be labbeled. + # Disable some security settings to make it possible to + # mount host directories without problems. + arg "--security-opt label=disable" # disable labeling so mounts don't need to be labeled. arg "--userns=keep-id" # required for ~/.ssh which is usually 700. - arg "--net=host" # use host networking + + # Use host networking. + arg "--net=host" # Mount the wayland socket. Required to get the system # clipbard (wl-copy) working. - arg "-v /run/user/$UID/wayland-0:/run/user/1000/wayland-0" + [ -e "/run/user/$UID/wayland-0" ] && arg "-v /run/user/$UID/wayland-0:/run/user/1000/wayland-0" - # Mount the ssh socket, directory and git directory. This - # gets the host ssh and git configuration working inside - # the container. - arg "-v $SSH_AUTH_SOCK:/run/user/1000/ssh-auth-sock" - [ -d ~/.ssh ] && arg "-v $HOME/.ssh:/home/user/.ssh" - [ -d ~/.config/git ] && arg "-v $HOME/.config/git:/home/user/.config/git" + # Mount the ssh socket, directory and the git config + # directory. This gets the host ssh and git configuration + # working inside the container. + [ -e "$SSH_AUTH_SOCK" ] && arg "-v $SSH_AUTH_SOCK:/run/user/1000/ssh-auth-sock" + [ -d "$HOME/.ssh" ] && arg "-v $HOME/.ssh:/home/user/.ssh" + [ -d "$HOME/.config/git" ] && arg "-v $HOME/.config/git:/home/user/.config/git" # Mount host directories with programming projects. - [ -d ~/Documents ] && arg "-v $HOME/Documents:/home/user/Documents" - [ -d ~/.local/share/devcontainer ] && arg "-v $HOME/.local/share/devcontainer:/home/user/.dev" + [ -d "$HOME/Documents" ] && arg "-v $HOME/Documents:/home/user/Documents" + [ -d "$HOME/.local/share/devcontainer" ] && arg "-v $HOME/.local/share/devcontainer:/home/user/.dev" # Add volumes for .local and .cache so these survive # container restarts. arg "-v $name-local:/home/user/.local" arg "-v $name-cache:/home/user/.cache" - podman run -it $args "$image" } -# podman_exec opens a shell into an existing dev container. -podman_exec() { podman exec -it "$name" bash -l; } - -# podman_start starts a stopped existing dev container. -podman_start() { podman start "$name" 1>/dev/null; } - -# podman_delete deletes a dev container. -podman_delete() { podman container rm -f -t 1 "$name" 1>/dev/null; } - ### MAIN ### name="dev" image="git.plabble.org/job79/dev:latest" +recreate=false while test $# -gt 0; do case "$1" in - --recreate | -r) podman_delete ;; - --no-pull | -np) no_pull=1 ;; - -*) echo "unknown option '$1'" ;; - *) name="$1" ;; + --image | -i) + shift + image="$1" + ;; + --name | -n) + shift + name="$1" + ;; + --recreate | -r) + recreate=true + ;; + *) echo "unknown argument '$1'" ;; esac shift done -if ! podman container exists "$name"; then - podman_run - exit -fi - -if [ "$(podman container inspect "$name" -f {{.State.Running}} 2>&1)" = 'true' ]; then - podman_exec - exit -fi - -if [ "$no_pull" = 1 ]; then - podman_start - podman_exec - exit -fi - -iid="$(podman image inspect "$image" -f {{.Id}})" -podman pull "$image" -if [ "$(podman image inspect "$image" -f {{.Id}})" != "$iid" ]; then - # When container is stopped and a newer image is available, - # recreate the container instead of starting the existing one. - podman_delete - podman_run +if + [ "$recreate" = true ] || + { [ "$(podman container inspect "$name" -f {{.State.Running}})" = 'false' ] && + [ "$(podman pull -q "$image")" != "$(podman container inspect "$name" -f {{.Image}})" ]; } +then + podman container rm -f -t 1 "$name" 1>/dev/null + podman run -it $(run_args) "$image" else - podman_start - podman_exec + podman start "$name" 1>/dev/null + podman exec -it "$name" bash -l fi