From e4dbe394f43f47ed8794ecb3853b40458bf26dbd Mon Sep 17 00:00:00 2001 From: Wryn Wagner Date: Wed, 4 Nov 2020 14:13:41 -0700 Subject: [PATCH] programmatically load os-specific plugin and set preferred EDITOR/VISUAL --- zsh/rc | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/zsh/rc b/zsh/rc index 100e99e..8c5404d 100644 --- a/zsh/rc +++ b/zsh/rc @@ -4,30 +4,36 @@ source "$HOME/.wryn/env/env.zsh" RC_DIR="$DOTWRYN/zsh" -# zsh plugins +# --- load custom plugins ------------------------------------------ + for file in $(find $RC_DIR -maxdepth 1 -type f ! -name 'rc'); do source $file; done; -# linux-specific plugins -if [[ "$OSTYPE" == "linux-gnu" ]]; then - for file in $(find $RC_DIR/linux -type f); do source $file; done; -fi - -# osx-specific plugins -if [[ "$OSTYPE" == "darwin"* ]]; then - for file in $(find $RC_DIR/osx -type f); do source $file; done; -fi +# operating system specific plugins +case "$OSTYPE" in + linux-gnu ) + for file in $(find $RC_DIR/linux -type f); do source $file; done; + ;; + darwin* ) + for file in $(find $RC_DIR/osx -type f); do source $file; done; + ;; +esac -# --- vi / vim as default editor (vim preferred) ------------------- -which vi >/dev/null 2>&1 && { - export EDITOR='vi'; - export VISUAL='vi'; -} - -which vim >/dev/null 2>&1 && { - export EDITOR='vim'; - export VISUAL='vim'; +# --- set default editor ------------------------------------------- +SET_PREFERRED_EDITOR() { + local PREFERENCE="$PREFERRED_EDITOR"; # load preference from environment (vi vim) by default + [ -z $PREFERENCE ] && { echo 'unable to find $PREFERRED_EDITOR environment variable'; return 1; } + + [[ $EDITOR == "${PREFERENCE[-1]}" ]] && [[ $VISUAL == "${PREFERENCE[-1]}" ]] && return 0; + + local AVAILABLE_EDITOR="$EDITOR"; + + for program in $PREFERENCE; do which $program >/dev/null 2>&1 && AVAILABLE_EDITOR="$program"; done + + export EDITOR="$AVAILABLE_EDITOR"; + export VISUAL="$AVAILABLE_EDITOR"; } +SET_PREFERRED_EDITOR # --- welcome message ----------------------------------------------