Last active
January 22, 2026 21:21
-
-
Save saikrn112/049639928da70cb1c6492ac2af77408f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| VIMRC_RAW_URL="https://gist.githubusercontent.com/saikrn112/b55bf8a8bad6f6538a40561bdafe45bc/raw/.vimrc" | |
| ZIMRC_COMPONENTS_URL="https://gist.githubusercontent.com/saikrn112/1e353283a091824bb0074c7aafe203fe/raw/zimrc-components" | |
| ALIAS_URL="https://gist.githubusercontent.com/saikrn112/b9d16ad838fc240fe7370697039eb56c/raw/alias.sh" | |
| need(){ command -v "$1" >/dev/null 2>&1; } | |
| fetch(){ curl -fsSL "$1"; } | |
| die() { echo "error: $*" >&2; exit 1; } | |
| ensure_block() { | |
| local file="$1" begin="$2" end="$3" content="$4" | |
| touch "$file" | |
| if grep -qF "$begin" "$file"; then | |
| awk -v b="$begin" -v e="$end" ' | |
| $0==b{in=1; next} | |
| $0==e{in=0; next} | |
| !in{print} | |
| ' "$file" > "$file.tmp" && mv "$file.tmp" "$file" | |
| fi | |
| { echo "$begin"; printf "%s\n" "$content"; echo "$end"; } >> "$file" | |
| } | |
| setup_aliases_rc() { | |
| local rc="$1" content="$2" | |
| ensure_block "$rc" \ | |
| "# >>> setup-shell aliases >>>" \ | |
| "# <<< setup-shell aliases <<<" \ | |
| "$content" | |
| } | |
| setup_aliases() { | |
| need curl || die "curl missing" | |
| local aliases | |
| aliases="$(fetch "$ALIAS_URL")" | |
| setup_aliases_rc "$HOME/.bashrc" "$aliases" | |
| setup_aliases_rc "$HOME/.zshrc" "$aliases" | |
| } | |
| setup_vim() { | |
| need curl || die "curl missing" | |
| curl -fsSLo "$HOME/.vimrc" "$VIMRC_RAW_URL" | |
| if need vim; then | |
| TERM=xterm vim +'silent! PlugInstall --sync' +qa || true | |
| else | |
| echo "warn: vim missing; wrote ~/.vimrc but skipped PlugInstall" | |
| fi | |
| } | |
| install_zim() { | |
| need zsh || { echo "warn: zsh missing; skipping zim"; return 0; } | |
| need curl || die "curl missing" | |
| if [[ ! -d "$HOME/.zim" ]]; then | |
| curl -fsSL https://raw.githubusercontent.com/zimfw/install/master/install.zsh | zsh | |
| fi | |
| local zim_modules | |
| zim_modules="$(fetch "$ZIMRC_COMPONENTS_URL")" | |
| ensure_block "$HOME/.zimrc" \ | |
| "# >>> setup-shell zim modules >>>" \ | |
| "# <<< setup-shell zim modules <<<" \ | |
| "$zim_modules" | |
| export ZIM_HOME="${ZIM_HOME:-$HOME/.zim}" | |
| zsh "$ZIM_HOME/zimfw.zsh" install | |
| } | |
| want_zsh_setup() { | |
| case "${1:-auto}" in | |
| zsh|both) return 0 ;; | |
| bash) return 1 ;; | |
| auto) | |
| [[ "${SHELL:-}" == *zsh ]] && return 0 | |
| [[ -f "$HOME/.zshrc" && -s "$HOME/.zshrc" ]] && return 0 | |
| return 1 | |
| ;; | |
| esac | |
| } | |
| usage() { | |
| cat <<'EOF' | |
| usage: setup-shell.sh [auto|bash|zsh|both] | |
| auto (default): zim only if you likely use zsh | |
| bash: no zim; vim+aliases | |
| zsh: zim+vim+aliases | |
| both: zim+vim+aliases | |
| notes: | |
| - no sudo / no apt/apk/brew calls | |
| - requires curl; vim and zsh are optional (features degrade gracefully) | |
| EOF | |
| } | |
| main() { | |
| local mode="${1:-auto}" | |
| [[ "$mode" == "-h" || "$mode" == "--help" ]] && { usage; exit 0; } | |
| setup_aliases | |
| setup_vim | |
| want_zsh_setup "$mode" && install_zim | |
| echo "done" | |
| } | |
| main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment