Update shell configuration to consider macOS and Linux

This commit is contained in:
Jens Luedicke
2025-09-22 13:36:07 +02:00
parent c7bbc68a92
commit 806fb003be
6 changed files with 205 additions and 47 deletions

5
bash/bash_profile Normal file
View File

@@ -0,0 +1,5 @@
#!/bin/bash
# Bash profile - loaded for login shells
# Source bashrc if it exists
[ -f "$HOME/.bashrc" ] && source "$HOME/.bashrc"

95
bash/bashrc Normal file
View File

@@ -0,0 +1,95 @@
#!/bin/bash
# Bash configuration file
# Source common profile
[ -f "$HOME/.shell-common/profile.common" ] && source "$HOME/.shell-common/profile.common"
# Bash-specific configurations
# Enable bash completion if available
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
elif [ -f "$HOMEBREW_PREFIX/etc/bash_completion" ]; then
. "$HOMEBREW_PREFIX/etc/bash_completion"
fi
# Source fzf files for bash
if [ -f /usr/share/doc/fzf/examples/key-bindings.bash ]; then
source /usr/share/doc/fzf/examples/key-bindings.bash
fi
if [ -f /usr/share/doc/fzf/examples/completion.bash ]; then
source /usr/share/doc/fzf/examples/completion.bash
fi
# History configuration
export HISTCONTROL=ignoreboth:erasedups
export HISTSIZE=10000
export HISTFILESIZE=20000
shopt -s histappend
# Check window size after each command
shopt -s checkwinsize
# Enable globstar (** pattern)
shopt -s globstar 2> /dev/null
# Aliases (same as zsh)
alias fzp='fzf --preview "bat --color=always --style=numbers --line-range=:500 {}"'
alias fzd='cd $(fd --type d --hidden --follow --exclude .git | fzf --preview "tree -C {} | head -200")'
alias fzv='vim $(fzf --preview "bat --color=always --style=numbers --line-range=:500 {}")'
alias fgb='git branch | fzf | xargs git checkout'
alias fgl='git log --oneline | fzf --preview "git show --color=always {1}" | awk "{print \$1}" | xargs git show'
# Tmux session switcher function
fts() {
local session
session=$(tmux list-sessions -F "#{session_name}" 2>/dev/null | fzf --preview "tmux list-windows -t {} | column -t" --preview-window=down:20%) && tmux switch-client -t "$session"
}
# Bash Prompt Configuration
# Colors
RED='\[\033[0;31m\]'
GREEN='\[\033[0;32m\]'
YELLOW='\[\033[0;33m\]'
BLUE='\[\033[0;34m\]'
MAGENTA='\[\033[0;35m\]'
CYAN='\[\033[0;36m\]'
GRAY='\[\033[0;90m\]'
RESET='\[\033[0m\]'
# Git prompt function
git_prompt_info() {
local ref
ref=$(git symbolic-ref HEAD 2> /dev/null) || \
ref=$(git rev-parse --short HEAD 2> /dev/null) || return
# Get git status
local git_status=""
local STATUS=$(git status --porcelain 2> /dev/null | tail -1)
if [[ -n $STATUS ]]; then
git_status=" ${YELLOW}${RESET}"
else
git_status=" ${GREEN}${RESET}"
fi
echo " ${CYAN}(${ref#refs/heads/}${git_status}${CYAN})${RESET}"
}
# Virtual environment indicator
virtualenv_prompt_info() {
if [[ -n "$VIRTUAL_ENV" ]]; then
echo "${MAGENTA}($(basename $VIRTUAL_ENV))${RESET} "
fi
}
# Username and hostname for SSH sessions
user_host_prompt() {
if [[ -n "$SSH_CONNECTION" ]]; then
echo "${YELLOW}\u@\h${RESET} "
fi
}
# Set prompt
PROMPT_COMMAND='PS1="$(user_host_prompt)$(virtualenv_prompt_info)${BLUE}\W${RESET}$(git_prompt_info) ${GREEN}➜${RESET} "'

6
profile Normal file
View File

@@ -0,0 +1,6 @@
#!/bin/sh
# POSIX-compliant profile for login shells
# This file is sourced by sh-compatible shells (including bash when invoked as sh)
# Source the common profile configuration
[ -f "$HOME/.shell-common/profile.common" ] && . "$HOME/.shell-common/profile.common"

2
rcrc
View File

@@ -1,3 +1,3 @@
EXCLUDES="README.md LICENSE .git .gitignore" EXCLUDES="README.md LICENSE .git .gitignore"
DOTFILES_DIRS="$HOME/.dotfiles" DOTFILES_DIRS="$HOME/.dotfiles"
SYMLINK_DIRS="" SYMLINK_DIRS="zsh bash shell-common"

View File

@@ -0,0 +1,77 @@
#!/bin/sh
# Common profile settings for all shells
# This file is sourced by both bash and zsh
# Detect operating system
case "$(uname -s)" in
Darwin)
OS="macos"
# Homebrew on macOS (Apple Silicon and Intel)
if [ -d "/opt/homebrew" ]; then
export HOMEBREW_PREFIX="/opt/homebrew"
elif [ -d "/usr/local/Homebrew" ]; then
export HOMEBREW_PREFIX="/usr/local"
fi
if [ -n "$HOMEBREW_PREFIX" ]; then
export PATH="$HOMEBREW_PREFIX/bin:$PATH"
export PATH="$HOMEBREW_PREFIX/opt/gnu-sed/libexec/gnubin:$PATH"
export PATH="$HOMEBREW_PREFIX/opt/ruby/bin:$HOMEBREW_PREFIX/lib/ruby/gems/3.4.0/bin:$PATH"
fi
;;
Linux)
OS="linux"
# Homebrew on Linux
if [ -d "/home/linuxbrew/.linuxbrew" ]; then
export HOMEBREW_PREFIX="/home/linuxbrew/.linuxbrew"
export PATH="$HOMEBREW_PREFIX/bin:$PATH"
fi
;;
*)
OS="unknown"
;;
esac
# Export OS for use in other scripts
export OS
# Go path
export GOPATH=$HOME/go
export PATH="$GOPATH/bin:$PATH"
# User local paths (common for all systems)
export PATH="$HOME/.local/bin:$PATH"
export PATH="$HOME/.emacs.d/bin:$PATH"
export PATH="$HOME/.cargo/bin:$PATH"
# API keys (consider moving to a separate, untracked file)
export PERPLEXITY_API_KEY="your-api-key"
# FZF configuration (common for all shells that support it)
export FZF_DEFAULT_COMMAND='fd --type f --hidden --follow --exclude .git'
export FZF_DEFAULT_OPTS='
--height 40%
--layout=reverse
--border
--preview "bat --color=always --style=numbers --line-range=:500 {}"
--preview-window=right:60%:wrap
--bind "ctrl-/:toggle-preview"
--bind "ctrl-y:execute-silent(echo {} | pbcopy)"
'
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
export FZF_CTRL_T_OPTS="
--preview 'bat --color=always --style=numbers --line-range=:500 {}'
--preview-window=right:60%:wrap
"
export FZF_ALT_C_COMMAND='fd --type d --hidden --follow --exclude .git'
export FZF_ALT_C_OPTS="--preview 'tree -C {} | head -200'"
export FZF_CTRL_R_OPTS="
--preview 'echo {}'
--preview-window=down:3:wrap
--bind 'ctrl-y:execute-silent(echo {} | pbcopy)'
"
export FZF_TMUX_OPTS='-p80%,60%'

View File

@@ -1,51 +1,26 @@
export GOPATH=$HOME/go #!/bin/zsh
export PATH="$HOME/.cargo/bin:/opt/homebrew/opt/gnu-sed/libexec/gnubin:$PATH" # Zsh configuration file
# The following lines have been added by Docker Desktop to enable Docker CLI completions.
fpath=(/Users/jens/.docker/completions $fpath) # Source common profile
[ -f "$HOME/.shell-common/profile.common" ] && source "$HOME/.shell-common/profile.common"
# Zsh-specific configurations
# Docker CLI completions (macOS specific path)
if [ "$OS" = "macos" ] && [ -d "/Users/jens/.docker/completions" ]; then
fpath=(/Users/jens/.docker/completions $fpath)
fi
# Enable completions
autoload -Uz compinit autoload -Uz compinit
compinit compinit
# End of Docker CLI completions
export PATH="/opt/homebrew/opt/ruby/bin:/opt/homebrew/lib/ruby/gems/3.4.0/bin:$PATH"
export PATH="$HOME/.local/bin:$PATH"
export PATH="$HOME/.emacs.d/bin:$PATH"
export PERPLEXITY_API_KEY="your-api-key"
# FZF configuration # Source fzf files for Ubuntu/Debian systems
# Enable fzf key bindings and fuzzy completion if [[ -f /usr/share/doc/fzf/examples/key-bindings.zsh ]]; then
eval "$(fzf --zsh)" source /usr/share/doc/fzf/examples/key-bindings.zsh
fi
# FZF environment variables if [[ -f /usr/share/doc/fzf/examples/completion.zsh ]]; then
export FZF_DEFAULT_COMMAND='fd --type f --hidden --follow --exclude .git' source /usr/share/doc/fzf/examples/completion.zsh
export FZF_DEFAULT_OPTS=' fi
--height 40%
--layout=reverse
--border
--preview "bat --color=always --style=numbers --line-range=:500 {}"
--preview-window=right:60%:wrap
--bind "ctrl-/:toggle-preview"
--bind "ctrl-y:execute-silent(echo {} | pbcopy)"
'
# Use fd for CTRL-T
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
export FZF_CTRL_T_OPTS="
--preview 'bat --color=always --style=numbers --line-range=:500 {}'
--preview-window=right:60%:wrap
"
# Use fd for ALT-C
export FZF_ALT_C_COMMAND='fd --type d --hidden --follow --exclude .git'
export FZF_ALT_C_OPTS="--preview 'tree -C {} | head -200'"
# Better history search with fzf
export FZF_CTRL_R_OPTS="
--preview 'echo {}'
--preview-window=down:3:wrap
--bind 'ctrl-y:execute-silent(echo {} | pbcopy)'
"
# FZF-tmux integration
export FZF_TMUX_OPTS='-p80%,60%'
# Useful aliases with fzf # Useful aliases with fzf
alias fzp='fzf --preview "bat --color=always --style=numbers --line-range=:500 {}"' alias fzp='fzf --preview "bat --color=always --style=numbers --line-range=:500 {}"'
@@ -136,4 +111,4 @@ function precmd() {
fi fi
unset timer unset timer
fi fi
} }