From 97b8a1a8023dbe2f0a88b4f903600e742918262c Mon Sep 17 00:00:00 2001 From: Maciej Lebiest Date: Tue, 17 Dec 2024 20:37:16 +0100 Subject: [PATCH] more formatters, some cleaning --- Containerfile | 14 +-- README.md | 215 ++++++++++++++++++++-------------------- bashrc_nvim.sh | 77 -------------- lua/plugins/conform.lua | 6 +- 4 files changed, 120 insertions(+), 192 deletions(-) delete mode 100644 bashrc_nvim.sh diff --git a/Containerfile b/Containerfile index 7123e4c..5604d5e 100644 --- a/Containerfile +++ b/Containerfile @@ -8,8 +8,8 @@ ENV LC_ALL="C.UTF-8" ENV NEOVIM_PKGS="\ wget \ unzip \ - git \ - neovim \ + git \ + neovim \ ripgrep \ fd-find \ npm \ @@ -44,17 +44,19 @@ ENV MASON_PKGS=" \ markdownlint \ ansible-language-server \ ansible-lint \ - yamlfmt" + yamlfmt \ + mdformat \ + shfmt" ENV MASON_PKGS_NO_ARM="lemminx helm-ls lua-language-server" COPY . /root/.config/nvim # install system dependencies -RUN dnf5 install -y \ +RUN dnf install -y \ ${GENERAL_PKGS} ${NEOVIM_PKGS} ${PYTHON_DEVEL_PKGS} ${BUILD_ONLY_PKGS} && \ - dnf5 -y autoremove && \ - dnf5 clean all && \ + dnf -y autoremove && \ + dnf clean all && \ nvim --headless +"MasonInstall ${MASON_PKGS}" +qa || exit 1 ; \ nvim --headless +"MasonInstall ${MASON_PKGS_NO_ARM}" +qa || true diff --git a/README.md b/README.md index 918ebc1..34d3660 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # My personal **neovim as container** configuration -I made this public so I can easily clone without authentication, -but since I treat this as a personal use only stuff, +I made this public so I can easily clone without authentication,\ +but since I treat this as a personal use only stuff,\ there can be some(read "a lot of") messy stuff. Much of this might have been selectively copy pasted from plugin repos. @@ -29,6 +29,7 @@ sudo dnf install -y \ ```bash podman pull ghcr.io/szwendacz99/neovim:latest ``` + #### or build ```bash @@ -50,7 +51,7 @@ import file back to local registry: podman load -i ./neovim.tar.xz ``` -### Image usage examples +### Image usage examples basic startup for editing current folder: @@ -75,10 +76,10 @@ function nvim() { # Also pass all parameters to neovim as its arguments. for arg in "$@"; do - if [ -f "$arg" ] || [ -d "$arg" ] ; then + if [ -f "$arg" ] || [ -d "$arg" ]; then local MOUNT_FILE=("${MOUNT_FILE[@]}" -v "$arg:$arg:rw") echo "Mounting $arg" - fi + fi done if [ -z "$MOUNT_FILE" ]; then # mount current workdir if no arguments with path @@ -86,7 +87,7 @@ function nvim() { local base_path="$(pwd)" # use list as a trick to allow paths with spaces - local MOUNT_FOLDER=(--workdir "/data$base_path" -v "$base_path:/data$base_path:rw") + local MOUNT_FILE=(--workdir "/data$base_path" -v "$base_path:/data$base_path:rw") fi if [ -f "$HOME/.gitconfig" ]; then @@ -97,27 +98,31 @@ function nvim() { local MOUNT_FILE=("${MOUNT_FILE[@]}" -v "$HOME/.ssh/known_hosts:/root/.ssh/known_hosts:ro") fi - if [ -S "$XDG_RUNTIME_DIR/ssh-agent.socket" ]; then - local MOUNT_FILE=("${MOUNT_FILE[@]}" -v "$XDG_RUNTIME_DIR/ssh-agent.socket:/runtime_dir/ssh-agent.socket:rw") + if [ -d "$XDG_RUNTIME_DIR" ]; then + local MOUNT_FILE=("${MOUNT_FILE[@]}" -v "$XDG_RUNTIME_DIR:/runtime_dir:rw") + else + local MOUNT_FILE=("${MOUNT_FILE[@]}" --tmpfs "/runtime_dir") + fi + + if [ -S "$SSH_AUTH_SOCK" ]; then + local MOUNT_FILE=("${MOUNT_FILE[@]}" -v "$SSH_AUTH_SOCK:/runtime_dir/ssh-agent.socket:rw") fi # make sure there is a folder for sessions on default path mkdir -p ~/.local/share/nvim/sessions ~/.local/state/nvim/shada echo "Files mount options: ${MOUNT_FILE[*]}" - echo "Folder mount options: ${MOUNT_FOLDER[*]}" podman run --privileged -it --rm \ - --network host \ - --tz Europe/Warsaw \ - -e XDG_RUNTIME_DIR=/runtime_dir \ - -e SSH_AUTH_SOCK=/runtime_dir/ssh-agent.socket \ - -e WAYLAND_DISPLAY="$WAYLAND_DISPLAY" \ - -v "$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY:/runtime_dir/$WAYLAND_DISPLAY:rw" \ - -v ~/.local/share/nvim/sessions:/root/.local/share/nvim/sessions:rw \ - -v ~/.local/state/nvim/shada/:/root/.local/state/nvim/shada/:rw \ - "${MOUNT_FILE[@]}" \ - "${MOUNT_FOLDER[@]}" \ - neovim:latest "$@" + --shm-size=0 \ + --init \ + --network host \ + -e XDG_RUNTIME_DIR=/runtime_dir \ + -e SSH_AUTH_SOCK=/runtime_dir/ssh-agent.socket \ + -e WAYLAND_DISPLAY="$WAYLAND_DISPLAY" \ + -v ~/.local/share/nvim/sessions:/root/.local/share/nvim/sessions:rw \ + -v ~/.local/state/nvim/shada/:/root/.local/state/nvim/shada/:rw \ + "${MOUNT_FILE[@]}" \ + neovim:latest "$@" } ``` @@ -128,31 +133,23 @@ then use function below. ```bash function nvim_project() { # Mount current folder to a container that will not be removed on exit. - # Requires first argument to be a name for the container so it can be - # easily reentered later. # If you specify some paths as latter parameters, then these paths will # be mounted instead of current folder. # Also mounts wayland for clipboard sync. - if [ -z "$1" ]; then - echo "give project/container name as first parameter" - return 1 - fi - local container_name="$1" - shift # skip first parameter as it can be name of a folder/file in - # current dir so it could try mounting it later + read -p "Enter container name: " container_name for arg in "$@"; do - if [ -f "$arg" ] || [ -d "$arg" ] ; then + if [ -f "$arg" ] || [ -d "$arg" ]; then local MOUNT_FILE=("${MOUNT_FILE[@]}" -v "$arg:$arg:rw") echo "Mounting $arg" - fi + fi done if [ -z "$MOUNT_FILE" ]; then # mount current workdir if no arguments with path # mount on base_path to make sessions saving work local base_path base_path="$(pwd)" - local MOUNT_FOLDER=(--workdir "/data$base_path" -v "$base_path:/data$base_path:rw") + local MOUNT_FILE=(--workdir "/data$base_path" -v "$base_path:/data$base_path:rw") fi if [ -f "$HOME/.gitconfig" ]; then @@ -163,29 +160,35 @@ function nvim_project() { local MOUNT_FILE=("${MOUNT_FILE[@]}" -v "$HOME/.ssh/known_hosts:/root/.ssh/known_hosts:ro") fi - if [ -S "$XDG_RUNTIME_DIR/ssh-agent.socket" ]; then - local MOUNT_FILE=("${MOUNT_FILE[@]}" -v "$XDG_RUNTIME_DIR/ssh-agent.socket:/runtime_dir/ssh-agent.socket:rw") + if [ -d "$XDG_RUNTIME_DIR" ]; then + local MOUNT_FILE=("${MOUNT_FILE[@]}" -v "$XDG_RUNTIME_DIR:/runtime_dir:rw") + else + local MOUNT_FILE=("${MOUNT_FILE[@]}" --tmpfs "/runtime_dir") + fi + + if [ -S "$SSH_AUTH_SOCK" ]; then + local MOUNT_FILE=("${MOUNT_FILE[@]}" -v "$SSH_AUTH_SOCK:/runtime_dir/ssh-agent.socket:rw") fi # make sure there is a folder for sessions on default path mkdir -p ~/.local/share/nvim/sessions ~/.local/state/nvim/shada echo "Files mount options: ${MOUNT_FILE[*]}" - echo "Folder mount options: ${MOUNT_FOLDER[*]}" podman run --privileged -it \ - --network host \ - --tz Europe/Warsaw \ - -e XDG_RUNTIME_DIR=/runtime_dir \ - -e SSH_AUTH_SOCK=/runtime_dir/ssh-agent.socket \ - -e WAYLAND_DISPLAY="$WAYLAND_DISPLAY" \ - -v "$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY:/runtime_dir/$WAYLAND_DISPLAY:rw" \ - -v ~/.local/share/nvim/sessions:/root/.local/share/nvim/sessions:rw \ - -v ~/.local/state/nvim/shada/:/root/.local/state/nvim/shada/:rw \ - "${MOUNT_FILE[@]}" \ - "${MOUNT_FOLDER[@]}" \ - --entrypoint bash \ - --name "nvim-$container_name" \ - neovim:latest + --shm-size=0 \ + --init \ + --network host \ + -e XDG_RUNTIME_DIR=/runtime_dir \ + -e SSH_AUTH_SOCK=/runtime_dir/ssh-agent.socket \ + -e WAYLAND_DISPLAY="$WAYLAND_DISPLAY" \ + -v "$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY:/runtime_dir/$WAYLAND_DISPLAY:rw" \ + -v ~/.local/share/nvim/sessions:/root/.local/share/nvim/sessions:rw \ + -v ~/.local/state/nvim/shada/:/root/.local/state/nvim/shada/:rw \ + "${MOUNT_FILE[@]}" \ + --entrypoint bash \ + "$@" \ + --name "nvim-$container_name" \ + neovim:latest } ``` @@ -242,7 +245,7 @@ There is need to make sure your system can display (almost) any unicode character. Hacked fonts may be needed for filetype icons but there is also need for a dedicated package with unicode fonts (like unifont-fonts.noarch) that will have every character missing from default font used in Neovim editor. -Link to hacked fonts: +Link to hacked fonts:\ [https://www.nerdfonts.com/font-downloads](https://www.nerdfonts.com/font-downloads) ### General info @@ -259,57 +262,57 @@ All that is saved in image, so that is why image is so heavy. |keys|action| |----|----| -|\l|disable (search) highlighting| -|\cb|Close all buffers (:bufdo bd)| +|\l|disable (search) highlighting| +|\cb|Close all buffers (:bufdo bd)| #### Opened files navigation |keys|action| |----|----| -|Ctrl w w| Move to next splitted frame| -|Ctrl w \ | moving throught splitted frame| -|Ctrl w c | close split| -|Ctrl w v | split vertically| -|Ctrl w s| split horizontally| -|Ctrl w x| swap places of two splits| -|gt |next tab| -|gT| previous tab| -|:tabnew |Create new tab| -|Ctrl+g Ctrl+t |(when in file tree) open selected file in new tab| -|:bd | close buffer| -|:bnext | next buffer| -|:b3 |switch to buffer 3| -|:buffers | list buffers and their numbers | +|Ctrl w w| Move to next splitted frame| +|Ctrl w \ | moving throught splitted frame| +|Ctrl w c | close split| +|Ctrl w v | split vertically| +|Ctrl w s| split horizontally| +|Ctrl w x| swap places of two splits| +|gt |next tab| +|gT| previous tab| +|:tabnew |Create new tab| +|Ctrl+g Ctrl+t |(when in file tree) open selected file in new tab| +|:bd | close buffer| +|:bnext | next buffer| +|:b3 |switch to buffer 3| +|:buffers | list buffers and their numbers | #### File explorer |keys|action| |----|----| -|Ctrl+t | Toggle file explorer when not focused on it| -|f | Toggle filtering when focused on explorer| -|\ n | Move focus to explorer| -|d |Delete selected file| -|rn |Rename file| -|c |add file to clipboard| -|p | paste (file) from clipboard | +|Ctrl+t | Toggle file explorer when not focused on it| +|f | Toggle filtering when focused on explorer| +|\ n | Move focus to explorer| +|d |Delete selected file| +|rn |Rename file| +|c |add file to clipboard| +|p | paste (file) from clipboard | #### File searching / Telescope |keys|action| |----|----| -|\ff |Find files| -|\fg| Live grep| -|\fb| Buffers| -|\fh |Help tags| +|\ff |Find files| +|\fg| Live grep| +|\fb| Buffers| +|\fh |Help tags| |Ctrl+/|Show mappings for picker actions (insert mode)| -|Ctrl+q| Open search result list as a dedicated split (quickfix list) (will overwrite previous one created this way in current tab)| -|Ctrl+u | Scroll preview up| -|Ctrl+d | Scroll preview down| +|Ctrl+q| Open search result list as a dedicated split (quickfix list) (will overwrite previous one created this way in current tab)| +|Ctrl+u | Scroll preview up| +|Ctrl+d | Scroll preview down| |Ctrl+f|Scroll left in preview window| |Ctrl+k|Scroll right in preview window| -|Ctrl+x |Open selection as a split| -|Ctrl+v | Open selection as a vsplit| -|Ctrl+t | Open selection in new tab | +|Ctrl+x |Open selection as a split| +|Ctrl+v | Open selection as a vsplit| +|Ctrl+t | Open selection in new tab | ##### Usefull Telescope commands @@ -359,7 +362,6 @@ Bindings: |gc|git_commits| |gb|git_branches| - GitSings provides some commands for displaying git stuff: ```bash @@ -385,33 +387,32 @@ GitSings provides some commands for displaying git stuff: ||| |----|----| -|\q | open list with diagnostics postions| -|\e |open diagnostics floating window| -|\[d | next diagnostic| -|\] | previous diagnostic| -|\k| open hoover box and enter it| -|\rn |rename element (function name, etc)| -|\f| format file| -|gd |go to definition| -|gD| go to declaration| -|\D| go to type definition| -|gi| go to implementation| -|gr| go to references| -|Ctrl+f |scroll down popup with docstring| -|Ctrl+b |scroll up popup with docstring| -|\wa |add workspace folder| -|\wr |remove workspace folder| -|\wl | list workspace folders | - +|\q | open list with diagnostics postions| +|\e |open diagnostics floating window| +|\[d | next diagnostic| +|\] | previous diagnostic| +|\k| open hoover box and enter it| +|\rn |rename element (function name, etc)| +|\f| format file| +|gd |go to definition| +|gD| go to declaration| +|\D| go to type definition| +|gi| go to implementation| +|gr| go to references| +|Ctrl+f |scroll down popup with docstring| +|Ctrl+b |scroll up popup with docstring| +|\wa |add workspace folder| +|\wr |remove workspace folder| +|\wl | list workspace folders | #### LSP diagnostics (custom and trouble.nvim) ||| |----|----| -|\vt| switch display of virtual text| -|\xx| Open diagnostics window| -|gR | lsp references | -|\ca | code action menu | +|\vt| switch display of virtual text| +|\xx| Open diagnostics window| +|gR | lsp references | +|\ca | code action menu | #### Sessions @@ -421,5 +422,5 @@ To save new session on specific path, just use :SaveSession, then when opening n ||| |----|----| -|:Notifications |show recent notifications| -|:Telescope notify | show recent notifications in telescope gui| +|:Notifications |show recent notifications| +|:Telescope notify | show recent notifications in telescope gui| diff --git a/bashrc_nvim.sh b/bashrc_nvim.sh deleted file mode 100644 index d76abc1..0000000 --- a/bashrc_nvim.sh +++ /dev/null @@ -1,77 +0,0 @@ -#!/bin/bash - -function nvim() { - # Mount current folder OR folders/files given as parameters, then - # open neovim. Container will be removed on neovim exit. - # Mount wayland for clipboard sync. - # Also pass all parameters to neovim as its arguments. - - for arg in "$@"; do - if [ -f "$arg" ] || [ -d "$arg" ] ; then - local MOUNT_FILE="$MOUNT_FILE -v "$arg:$arg:rw"" - echo "Mounting $arg" - fi - done - if [ -z "$MOUNT_FILE" ]; then - # mount current workdir if no arguments with path - # mount on base_path to make sessions saving work - local base_path - base_path="$(pwd)" - local MOUNT_FOLDER="--workdir /data$base_path -v "$base_path:/data$base_path:rw"" - fi - # make sure there is a folder for sessions on default path - mkdir -p ~/.local/share/nvim/sessions - - podman run --privileged -it --rm \ - -e XDG_RUNTIME_DIR=/runtime_dir \ - -e WAYLAND_DISPLAY="$WAYLAND_DISPLAY" \ - -v "$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY:/runtime_dir/$WAYLAND_DISPLAY:rw" \ - -v ~/.local/share/nvim/sessions:/root/.local/share/nvim/sessions:rw \ - $MOUNT_FILE \ - $MOUNT_FOLDER \ - neovim:latest "$@" -} - -function nvim_project() { - # Mount current folder to a container that will not be removed on exit. - # Requires first argument to be a name for the container so it can be - # easily reentered later. - # If you specify some paths as latter parameters, then these paths will - # be mounted instead of current folder. - # Also mounts wayland for clipboard sync. - - if [ -z "$1" ]; then - echo "give project/container name as first parameter" - return 1 - fi - local container_name - container_name="$1" - shift # skip first parameter as it can be name of a folder/file in - # current dir so it could try mounting it later - for arg in "$@"; do - if [ -f "$arg" ] || [ -d "$arg" ] ; then - local MOUNT_FILE="$MOUNT_FILE -v "$arg:$arg:rw"" - echo "Mounting $arg" - fi - done - if [ -z "$MOUNT_FILE" ]; then - # mount current workdir if no arguments with path - # mount on base_path to make sessions saving work - local base_path - base_path="$(pwd)" - local MOUNT_FOLDER="--workdir /data$base_path -v "$base_path:/data$base_path:rw"" - fi - # make sure there is a folder for sessions on default path - mkdir -p ~/.local/share/nvim/sessions - - podman run --privileged -it \ - -e XDG_RUNTIME_DIR=/runtime_dir \ - -e WAYLAND_DISPLAY="$WAYLAND_DISPLAY" \ - -v "$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY:/runtime_dir/$WAYLAND_DISPLAY:rw" \ - -v ~/.local/share/nvim/sessions:/root/.local/share/nvim/sessions:rw \ - $MOUNT_FILE \ - $MOUNT_FOLDER \ - --entrypoint bash \ - --name $container_name \ - neovim:latest -} diff --git a/lua/plugins/conform.lua b/lua/plugins/conform.lua index 20f005c..45e171a 100644 --- a/lua/plugins/conform.lua +++ b/lua/plugins/conform.lua @@ -6,6 +6,8 @@ return { -- Define your formatters formatters_by_ft = { yaml = { "yamlfmt" }, + markdown = { "mdformat" }, + bash = { "shfmt" }, --lua = { "stylua" }, --python = { "isort", "black" }, --javascript = { "prettierd", "prettier", stop_after_first = true }, @@ -18,8 +20,8 @@ return { --format_on_save = { timeout_ms = 500 }, -- Customize formatters formatters = { - shfmt = { - prepend_args = { "-i", "2" }, + yamlfmt = { + prepend_args = { "-formatter", "retain_line_breaks=true,indentless_arrays=true" }, }, }, }