From 4b45c89a9052b089506ef35bd11a0508ffbdfc1c Mon Sep 17 00:00:00 2001 From: Ismo Vuorinen Date: Fri, 29 Sep 2023 15:52:16 +0300 Subject: [PATCH] fix(shell): change how shell detection works --- base/bashrc | 1 - base/zshrc | 1 - config/exports-apps | 2 +- config/exports-shell | 36 +++++++++++++++++++----------------- local/bin/x-load-configs | 19 ++++++++++--------- scripts/shared.sh | 4 ++++ 6 files changed, 34 insertions(+), 29 deletions(-) diff --git a/base/bashrc b/base/bashrc index d40e063..177ef86 100755 --- a/base/bashrc +++ b/base/bashrc @@ -4,7 +4,6 @@ # Defaults export DOTFILES="$HOME/.dotfiles" export DOTFILES_SHARED_LOADED="" -export DOTFILES_CURRENT_SHELL="bash" # shellcheck source=scripts/shared.sh source "$DOTFILES/scripts/shared.sh" path_prepend "$DOTFILES/local/bin" diff --git a/base/zshrc b/base/zshrc index 538d15c..fc8c282 100755 --- a/base/zshrc +++ b/base/zshrc @@ -3,7 +3,6 @@ # Defaults export DOTFILES="$HOME/.dotfiles" -export DOTFILES_CURRENT_SHELL="zsh" # shellcheck source=scripts/shared.sh source "$DOTFILES/scripts/shared.sh" path_prepend "$DOTFILES/local/bin" diff --git a/config/exports-apps b/config/exports-apps index 449c12b..3abee89 100755 --- a/config/exports-apps +++ b/config/exports-apps @@ -4,7 +4,7 @@ # shellcheck disable=1091,2139 # vim: filetype=bash -export DOTFILES="$HOME/.dotfiles" +: "${DOTFILES:=$HOME/.dotfiles}" source "$DOTFILES/scripts/shared.sh" # Antigen configuration diff --git a/config/exports-shell b/config/exports-shell index 88d90cc..0349d1d 100755 --- a/config/exports-shell +++ b/config/exports-shell @@ -1,7 +1,7 @@ #!/usr/bin/env bash # shellcheck shell=bash # shellcheck disable=1091,2046 -# vim: filetype=zsh +# vim: filetype=bash export DOTFILES="$HOME/.dotfiles" source "$DOTFILES/scripts/shared.sh" @@ -48,25 +48,27 @@ hash shopt 2> /dev/null && shopt -s checkwinsize have dircolors && eval $(dircolors "$XDG_CONFIG_HOME/dircolors") # If we are using zsh, color our dir lists and such -if [ "$DOTFILES_CURRENT_SHELL" = "zsh" ]; then - autoload -U colors zsh/terminfo compinit - colors - compinit -d "$XDG_CACHE_HOME"/zsh/zcompdump-"$ZSH_VERSION" +if [ "$DOTFILES_CURRENT_SHELL" = "-zsh" ]; then + [[ $ZSH_VERSION != "" ]] && { + autoload -U colors zsh/terminfo compinit + colors + compinit -d "$XDG_CACHE_HOME"/zsh/zcompdump-"$ZSH_VERSION" - x-dc "$XDG_CACHE_HOME/zsh" - x-dc "$XDG_STATE_HOME/zsh" - export HISTFILE="$XDG_STATE_HOME/zsh/history" - zstyle ':completion:*' cache-path "$XDG_CACHE_HOME/zsh/zcompcache" - zstyle ':completion:*' list-colors "$LS_COLORS" + x-dc "$XDG_CACHE_HOME/zsh" + x-dc "$XDG_STATE_HOME/zsh" + export HISTFILE="$XDG_STATE_HOME/zsh/history" + zstyle ':completion:*' cache-path "$XDG_CACHE_HOME/zsh/zcompcache" + zstyle ':completion:*' list-colors "$LS_COLORS" - # fzf - [ -f "${XDG_CONFIG_HOME:-$HOME/.config}"/fzf/fzf.zsh ] \ - && source "${XDG_CONFIG_HOME:-$HOME/.config}"/fzf/fzf.zsh + # fzf + [ -f "${XDG_CONFIG_HOME:-$HOME/.config}"/fzf/fzf.zsh ] \ + && source "${XDG_CONFIG_HOME:-$HOME/.config}"/fzf/fzf.zsh - # Load iterm2 shell integration - # https://iterm2.com/documentation-shell-integration.html - [[ -f "$XDG_BIN_HOME/iterm2_shell_integration.zsh" ]] \ - && source "$XDG_BIN_HOME/iterm2_shell_integration.zsh" + # Load iterm2 shell integration + # https://iterm2.com/documentation-shell-integration.html + [[ -f "$XDG_BIN_HOME/iterm2_shell_integration.zsh" ]] \ + && source "$XDG_BIN_HOME/iterm2_shell_integration.zsh" + } fi # If we are using bash diff --git a/local/bin/x-load-configs b/local/bin/x-load-configs index 1ce5f1e..8c74a7c 100755 --- a/local/bin/x-load-configs +++ b/local/bin/x-load-configs @@ -3,20 +3,21 @@ # Copyright (c) 2023 Ismo Vuorinen. All Rights Reserved. : "${DOTFILES:=$HOME/.dotfiles}" +source "$DOTFILES/scripts/shared.sh" # Load the shell dotfiles, and then some: -for file in $DOTFILES/config/{exports,alias,functions}; do +for FILENAME in $DOTFILES/config/{exports,alias,functions}; do HOST="$(hostname -s)" - # global (exports|alias|functions) file for all hosts + # global (exports|alias|functions) FILENAME for all hosts # shellcheck source=../config/exports - [ -r "$file" ] && source "$file" - # global secret file, git ignored + [ -r "$FILENAME" ] && source "$FILENAME" + # global secret FILENAME, git ignored # shellcheck source=../config/exports-secret - [ -r "$file-secret" ] && source "$file-secret" - # host specific (exports|alias|functions) file + [ -r "$FILENAME-secret" ] && source "$FILENAME-secret" + # host specific (exports|alias|functions) FILENAME # shellcheck source=../config/exports - [ -r "$file-$HOST" ] && source "$file-$HOST" - # host specific (exports|alias|functions) file, git ignored + [ -r "$FILENAME-$HOST" ] && source "$FILENAME-$HOST" + # host specific (exports|alias|functions) FILENAME, git ignored # shellcheck source=../config/exports - [ -r "$file-$HOST-secret" ] && source "$file-$HOST-secret" + [ -r "$FILENAME-$HOST-secret" ] && source "$FILENAME-$HOST-secret" done diff --git a/scripts/shared.sh b/scripts/shared.sh index 46142e4..f9ce3be 100755 --- a/scripts/shared.sh +++ b/scripts/shared.sh @@ -5,6 +5,10 @@ # Helper env variables. Use like this: VERBOSE=1 ./script.sh : "${VERBOSE:=0}" +: "${DOTFILES:=$HOME/.dotfiles}" + +DOTFILES_CURRENT_SHELL=$(ps -p $$ -oargs=) +export DOTFILES_CURRENT_SHELL source "$DOTFILES/local/bin/msgr"