#!/bin/bash # ============================================================================= # Oh My Posh + Catppuccin Mocha Setup # FINAL: 100% FIXED | No loop | No fail | Just type i or u # ============================================================================= set -euo pipefail # === Icons === INFO="i" SUCCESS="Checkmark" WARN="Warning" ERROR="Cross" PROMPT="Question" ROCKET="Arrow Right" # === Colors === RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' PURPLE='\033[0;35m' CYAN='\033[0;36m' NC='\033[0m' log() { echo -e "${CYAN}[${INFO}]${NC} $1"; } success(){ echo -e "${GREEN}[${SUCCESS}]${NC} $1"; } warn() { echo -e "${YELLOW}[${WARN}]${NC} $1"; } error() { echo -e "${RED}[${ERROR}]${NC} $1" >&2; } prompt() { echo -ne "${PURPLE}[${PROMPT}]${NC} $1 "; } # === Paths & URLs === ARCH=$(uname -m) case $ARCH in x86_64) OHMY_POSH_BIN="posh-linux-amd64" ;; aarch64) OHMY_POSH_BIN="posh-linux-arm64" ;; *) error "Unsupported arch: $ARCH"; exit 1 ;; esac OHMY_POSH_PATH="/usr/local/bin/oh-my-posh" THEME_URL="https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/catppuccin_mocha.omp.json" THEME_PATH="$HOME/.poshthemes/catppuccin_mocha.omp.json" FONT_ZIP="JetBrainsMono.zip" FONT_URL="https://github.com/ryanoasis/nerd-fonts/releases/latest/download/$FONT_ZIP" FONT_DIR="$HOME/.local/share/fonts" # === Install === install_oh_my_posh() { log "Installing Oh My Posh..." sudo curl -sSL "https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/$OHMY_POSH_BIN" -o "$OHMY_POSH_PATH" sudo chmod +x "$OHMY_POSH_PATH" success "Oh My Posh installed" log "Setting up theme..." mkdir -p ~/.poshthemes curl -sSL "$THEME_URL" -o "$THEME_PATH.tmp" sed 's/{{ .UserName }}@{{ .HostName }}/subeditor/g' "$THEME_PATH.tmp" | \ sed 's/"type": "session"/"type": "text"/g' > "$THEME_PATH" rm -f "$THEME_PATH.tmp" success "Theme ready" if ! grep -q "oh-my-posh" "$HOME/.bashrc" 2>/dev/null; then echo -e "\n# === Oh My Posh (Catppuccin Mocha) ===\neval \"\$(oh-my-posh init bash --config '$THEME_PATH')\"" >> "$HOME/.bashrc" success ".bashrc updated" fi if [[ ! -d "$FONT_DIR" ]] || [[ -z "$(ls -A "$FONT_DIR"/*.ttf 2>/dev/null)" ]]; then log "Installing Nerd Font..." mkdir -p "$FONT_DIR" cd "$FONT_DIR" curl -sSL "$FONT_URL" -o "$FONT_ZIP" unzip -o -j "$FONT_ZIP" "*.ttf" -x "*Windows*" >/dev/null 2>&1 rm -f "$FONT_ZIP" fc-cache -fv >/dev/null cd ~ success "Font installed" fi success "Installation complete!" if [[ -t 1 ]] && [[ -z "${OMP_RELOADED:-}" ]]; then echo -e "${CYAN}Reloading shell...${NC}" export OMP_RELOADED=1 source "$HOME/.bashrc" 2>/dev/null || true exec bash -l else echo -e "${BLUE}${ROCKET} Run: ${YELLOW}source ~/.bashrc${NC}" fi } # === Uninstall === uninstall_oh_my_posh() { log "Uninstalling..." sed -i '/# === Oh My Posh (Catppuccin Mocha) ===/,+2d' "$HOME/.bashrc" 2>/dev/null || true sed -i '/oh-my-posh init bash/d' "$HOME/.bashrc" 2>/dev/null || true [[ -f "$OHMY_POSH_PATH" ]] && sudo rm -f "$OHMY_POSH_PATH" && success "Binary removed" [[ -f "$THEME_PATH" ]] && rm -f "$THEME_PATH" && success "Theme removed" [[ -d ~/.poshthemes ]] && rmdir ~/.poshthemes 2>/dev/null || true [[ -d "$FONT_DIR" ]] && rm -rf "$FONT_DIR" && fc-cache -fv >/dev/null && success "Font removed" success "Uninstalled!" if [[ -t 1 ]]; then exec bash -l; fi } # ============================================================================= # === MAIN === # ============================================================================= clear echo -e "${PURPLE} Oh My Posh – Catppuccin Mocha${NC}" echo -e "${CYAN} Prompt: subeditor ~ Arrow Right${NC}" echo # === AUTO MODE IF ARGS === if [[ $# -eq 1 ]]; then choice="${1,,}" case "$choice" in i|install) install_oh_my_posh ;; u|uninstall) uninstall_oh_my_posh ;; *) error "Use -s -- i or -s -- u"; exit 1 ;; esac exit 0 fi # === INTERACTIVE MODE (ONLY IF TTY) === if [[ ! -t 0 ]] || [[ ! -t 1 ]]; then echo -e "${YELLOW}[${WARN}]${NC} Interactive mode requires a terminal." echo -e " Use: ${GREEN}curl -sSL https://oh-myposh.subeditor.works | bash -s -- i${NC}" exit 1 fi while :; do prompt "Install or Uninstall? [i/u]: " IFS= read -r input || { echo; break; } choice="${input,,}" choice="${choice// /}" [[ -z "$choice" ]] && continue case "$choice" in i|install) install_oh_my_posh; break ;; u|uninstall) uninstall_oh_my_posh; break ;; *) echo -e "${RED}[${ERROR}]${NC} Type 'i' or 'u' only." ;; esac done