From 392628e7339d54ccf5dfffa31cd118c1eeb46415 Mon Sep 17 00:00:00 2001 From: Ismo Vuorinen Date: Sat, 16 Nov 2024 16:30:57 +0200 Subject: [PATCH] fix(shell): fixes to zsh and bash configs --- base/bashrc | 43 ++++++++++++++++++++++++++++++++++++++---- base/{zshrc => zshenv} | 32 +++++++++++++++++++------------ config/exports | 17 ++++++++--------- 3 files changed, 67 insertions(+), 25 deletions(-) rename base/{zshrc => zshenv} (84%) mode change 100755 => 100644 diff --git a/base/bashrc b/base/bashrc index 65d0205..b482195 100644 --- a/base/bashrc +++ b/base/bashrc @@ -14,10 +14,45 @@ source "$DOTFILES/config/shared.sh" # Import ssh keys in keychain ssh-add -A 2>/dev/null -x-have oh-my-posh && { - eval "$(oh-my-posh init bash --config "$DOTFILES/config/omp/own.toml")" -} - x-have antidot && { eval "$(antidot init)" } + +# If not running interactively, don't do anything +case $- in +*i*) ;; +*) return ;; +esac + +# set variable identifying the chroot you work in (used in the prompt below) +if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then + debian_chroot=$(cat /etc/debian_chroot) +fi + +if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then + # We have color support; assume it's compliant with Ecma-48 + # (ISO/IEC-6429). (Lack of such support is extremely rare, and such + # a case would tend to support setf rather than setaf.) + color_prompt=yes +else + color_prompt= +fi + +if [ "$color_prompt" = yes ]; then + PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\u\[\033[01;33m\]@\[\033[01;36m\]\h \[\033[01;33m\]\w \[\033[01;35m\]\$ \[\033[00m\]' +else + PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' +fi +unset color_prompt + +# If this is an xterm set the title to user@host:dir +case "$TERM" in +xterm* | rxvt*) + PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1" + ;; +*) ;; +esac + +x-have oh-my-posh && { + eval "$(oh-my-posh init bash --config "$DOTFILES/config/omp/own.toml")" +} diff --git a/base/zshrc b/base/zshenv old mode 100755 new mode 100644 similarity index 84% rename from base/zshrc rename to base/zshenv index 3925b1b..abd472a --- a/base/zshrc +++ b/base/zshenv @@ -1,4 +1,5 @@ # this is my zsh config. there are many like it, but this one is mine. +# https://zsh.sourceforge.io/Intro/intro_3.html # shellcheck shell=bash # export VERBOSE=1 @@ -10,6 +11,16 @@ export PATH="$HOME/.local/bin:$DOTFILES/local/bin:$LOCAL_SHARE/nvim/mason/bin:$L export SHARED_SCRIPTS_SOURCED=0 source "$DOTFILES/config/shared.sh" +source "${XDG_CONFIG_HOME:-$HOME/.config}/asdf-direnv/zshrc" + +export ZDOTDIR="$DOTFILES/zsh" +ZSH_COMPDUMP="$XDG_CACHE_HOME/zsh/zcompdump-${SHORT_HOST}-${ZSH_VERSION}" + +# If not running interactively, don't do anything +case $- in + *i*) ;; + *) return;; +esac eval "$(oh-my-posh init zsh --config "$DOTFILES/config/omp/own.toml")" @@ -88,19 +99,16 @@ setup_tmux_window_name_plugin() fi } -main() -{ - load_antigen - source_fzf_config - setup_tmux_window_name_plugin - if x-have antidot; then - eval "$(antidot init)" - fi - source "${XDG_CONFIG_HOME:-$HOME/.config}/asdf-direnv/zshrc" -} - -main "$@" +load_antigen +source_fzf_config +setup_tmux_window_name_plugin +if x-have antidot; then + eval "$(antidot init)" +fi # Lando export PATH="$HOME/.lando/bin${PATH+:$PATH}"; #landopath +autoload -Uz compinit bashcompinit +compinit -d $ZSH_COMPDUMP +bashcompinit diff --git a/config/exports b/config/exports index db3188d..b5efd53 100755 --- a/config/exports +++ b/config/exports @@ -14,22 +14,21 @@ # if DOTFILES is not set, set it to the default location [ -z "$DOTFILES" ] && export DOTFILES="$HOME/.dotfiles" +# zsh completions directory +[ -z "$ZSH_COMPLETIONS" ] && export ZSH_COMPLETIONS="$XDG_CONFIG_HOME/zsh/completion" + export PATH="$XDG_BIN_HOME:$DOTFILES/local/bin:$XDG_DATA_HOME/bob/nvim-bin:$XDG_DATA_HOME/cargo/bin:/opt/homebrew/bin:/usr/local/bin:$PATH" -# Load bash completions if available for zsh -if [[ -n "$ZSH_VERSION" ]]; then - autoload bashcompinit - bashcompinit -fi +# Add zsh completions to FPATH, compinit will be called later +FPATH="$ZSH_COMPLETIONS:$FPATH" # Load asdf export ASDF_DIR="$XDG_BIN_HOME/asdf" if [[ -d $ASDF_DIR ]]; then - [[ -d $ASDF_DIR/completions ]] && fpath=("$ASDF_DIR/completions" $fpath) - [[ -d $ASDF_DIR/plugins ]] && fpath=("$ASDF_DIR/plugins" $fpath) + [[ -d $ASDF_DIR/completions ]] && FPATH="$ASDF_DIR/completions:$FPATH" + [[ -d $ASDF_DIR/plugins ]] && FPATH="$ASDF_DIR/plugins:$FPATH" source "$ASDF_DIR/asdf.sh" fi -export PATH="$ASDF_DIR/bin:$ASDF_DIR/shims:$PATH" if ! command -v msg &> /dev/null; then # Function to print messages if VERBOSE is enabled @@ -124,7 +123,7 @@ preexec() dfu() { ( - cd "$DOTFILES" && git pull --ff-only && ./install + cd "$DOTFILES" && git rebase --ff --autostash && ./install ) }