@@ -0,0 +1,27 @@
1+#!/usr/bin/env bash
2+# Link shared shell config and source it from existing shell rc files.
3+set -euo pipefail
4+
5+repo_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/shell"
7+shared_target="$config_dir/shared.sh"
8+
9+mkdir -p "$config_dir"
10+
11+if [ ! -e "$shared_target" ] && [ ! -L "$shared_target" ]; then
12+ ln -s "$repo_dir/shared.sh" "$shared_target"
13+fi
14+
15+# Use POSIX-compatible '.' instead of 'source'; bash/zsh are not strictly POSIX by default.
16+source_line='[ -f "${XDG_CONFIG_HOME:-$HOME/.config}/shell/shared.sh" ] && . "${XDG_CONFIG_HOME:-$HOME/.config}/shell/shared.sh"'
17+
18+for rc_file in "$HOME/.zshrc" "$HOME/.bashrc"; do
19+ if [ -f "$rc_file" ]; then
20+ if ! grep -q "shell/shared.sh" "$rc_file"; then
21+ printf '\n# Load shared shell config\n%s\n' "$source_line" >> "$rc_file"
22+ fi
23+ fi
24+done
25+
26+echo "Installed shared shell config to $shared_target"
27+echo "Note: install dependencies (fortune, cowsay, lolcat) if you haven't yet."