From 6cf696e1f603999cd3b7777bec1283bcaf467151 Mon Sep 17 00:00:00 2001 From: Hektor Misplon Date: Sun, 29 Sep 2024 11:36:20 +0200 Subject: [PATCH] Update bash editor configuration --- .bash_aliases/all | 2 +- .bashrc | 10 ++++------ .bashrc.d/editor | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 .bashrc.d/editor diff --git a/.bash_aliases/all b/.bash_aliases/all index c4b8902..deaa29c 100644 --- a/.bash_aliases/all +++ b/.bash_aliases/all @@ -8,7 +8,7 @@ alias al-=unalias # Edit configuration files alias eba="nvim ~/.bashrc" alias eal="nvim ~/.bash_aliasrc" -alias ev="nvim ~/.vimrc" +alias ev="edit_editor_config" # Navigation alias ..="cd .." diff --git a/.bashrc b/.bashrc index 05a6f20..0327751 100644 --- a/.bashrc +++ b/.bashrc @@ -4,6 +4,10 @@ source /etc/os-release +# Functions {{{ +[ -f "$HOME/.bashrc.d/editor" ] && source "$HOME/.bashrc.d/editor" +# }}} + # Aliases {{{ # Load aliases dynamically [ -f "$HOME/.bash_aliases/all" ] && source "$HOME/.bash_aliases/all" @@ -53,12 +57,6 @@ export MANWIDTH=80 export PAGER=nvimpager # }}} -# Editor {{{ -# Set vim as default editor -export EDITOR=nvim -export SUDO_EDITOR=nvim -# }}} - # Nvm export PATH=~/.nvm/versions/node/v14.16.0/bin:$PATH export NVM_DIR="$HOME/.nvm" diff --git a/.bashrc.d/editor b/.bashrc.d/editor new file mode 100644 index 0000000..28b6910 --- /dev/null +++ b/.bashrc.d/editor @@ -0,0 +1,18 @@ +# vim: set ft=bash : + +# Set NeoVim as default editor +export EDITOR=nvim +export SUDO_EDITOR="$EDITOR" + +declare -A -r EDITOR_CONFIGS=( + ["nvim"]="$HOME/.config/nvim/init.lua" + ["vim"]="$HOME/.vimrc" +) + +edit_editor_config() { + for editor in "${!EDITOR_CONFIGS[@]}"; do + if [ "$EDITOR" = "$editor" ]; then + $EDITOR "${EDITOR_CONFIGS[$editor]}" + fi + done +}