Last active
April 27, 2026 17:41
-
-
Save hanneshapke/ab4b25c1405163a688b3cde34110e600 to your computer and use it in GitHub Desktop.
Provisioning remote machines
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 | |
| # | |
| # install.sh - Hannes's dev shortcuts installer | |
| # | |
| # Usage: | |
| # curl -fsSL https://hanneshapke.com/install.sh | bash | |
| # curl -fsSL https://gist.githubusercontent.com/hanneshapke/ab4b25c1405163a688b3cde34110e600/raw/install.sh | bash | |
| # | |
| # Installs: | |
| # - Yaak (https://getyaak.ai) via its official installer | |
| # - Git aliases and shell shortcuts in ~/.hh_shortcuts.sh | |
| # - Sources that file from your ~/.bashrc and/or ~/.zshrc | |
| # | |
| # Safe to re-run: it will not duplicate entries. | |
| set -euo pipefail | |
| # ---------- pretty output ---------- | |
| if [ -t 1 ]; then | |
| BOLD=$(printf '\033[1m'); GREEN=$(printf '\033[32m') | |
| YELLOW=$(printf '\033[33m'); RED=$(printf '\033[31m'); RESET=$(printf '\033[0m') | |
| else | |
| BOLD=""; GREEN=""; YELLOW=""; RED=""; RESET="" | |
| fi | |
| info() { printf "%s==>%s %s\n" "$GREEN" "$RESET" "$*"; } | |
| warn() { printf "%s!!%s %s\n" "$YELLOW" "$RESET" "$*" >&2; } | |
| error() { printf "%sxx%s %s\n" "$RED" "$RESET" "$*" >&2; } | |
| # ---------- sanity checks ---------- | |
| if [ "${EUID:-$(id -u)}" -eq 0 ]; then | |
| warn "Running as root. Shortcuts will be installed for the root user only." | |
| fi | |
| for cmd in curl uname; do | |
| if ! command -v "$cmd" >/dev/null 2>&1; then | |
| error "Required command not found: $cmd" | |
| exit 1 | |
| fi | |
| done | |
| OS="$(uname -s)" | |
| info "Detected OS: ${BOLD}${OS}${RESET}" | |
| # ---------- 1. install Yaak ---------- | |
| install_yaak() { | |
| info "Installing Yaak from https://getyaak.ai/install.sh" | |
| if curl -fsSL https://getyaak.ai/install.sh | bash; then | |
| info "Yaak installer finished." | |
| else | |
| warn "Yaak install failed (exit $?). Continuing with shortcut setup." | |
| fi | |
| } | |
| # ---------- 2. write the shortcuts file ---------- | |
| SHORTCUTS_FILE="$HOME/.hh_shortcuts.sh" | |
| write_shortcuts() { | |
| info "Writing shortcuts to ${BOLD}${SHORTCUTS_FILE}${RESET}" | |
| cat > "$SHORTCUTS_FILE" <<'SHORTCUTS_EOF' | |
| # ~/.hh_shortcuts.sh - managed by install.sh | |
| # Re-running the installer overwrites this file. Local edits will be lost. | |
| # --- git --- | |
| alias gst='git status' | |
| alias ga='git add' | |
| alias gaa='git add --all' | |
| alias gc='git commit' | |
| alias gcm='git commit -m' | |
| alias gca='git commit --amend' | |
| alias gp='git push' | |
| alias gpf='git push --force-with-lease' | |
| alias gpl='git pull' | |
| alias gco='git checkout' | |
| alias gcb='git checkout -b' | |
| alias gb='git branch' | |
| alias gd='git diff' | |
| alias gds='git diff --staged' | |
| alias gl='git log --oneline --graph --decorate -20' | |
| alias gll='git log --oneline --graph --decorate --all' | |
| alias gf='git fetch --all --prune' | |
| alias gsw='git switch' | |
| alias grh='git reset HEAD' | |
| alias gss='git stash' | |
| alias gsp='git stash pop' | |
| # --- navigation / files --- | |
| alias ..='cd ..' | |
| alias ...='cd ../..' | |
| alias ....='cd ../../..' | |
| alias ll='ls -lah' | |
| alias la='ls -A' | |
| alias l='ls -CF' | |
| # --- safety --- | |
| alias rm='rm -i' | |
| alias cp='cp -i' | |
| alias mv='mv -i' | |
| # --- misc --- | |
| alias h='history' | |
| alias c='clear' | |
| alias reload='exec "$SHELL" -l' | |
| # --- functions --- | |
| # mkcd: make a directory and cd into it | |
| mkcd() { mkdir -p -- "$1" && cd -- "$1"; } | |
| # gcp: git add all + commit with message in one shot | |
| gcp() { | |
| if [ "$#" -eq 0 ]; then | |
| echo "usage: gcp <commit message>" >&2 | |
| return 1 | |
| fi | |
| git add --all && git commit -m "$*" | |
| } | |
| SHORTCUTS_EOF | |
| } | |
| # ---------- 3. wire it into shell rc files ---------- | |
| SOURCE_LINE='[ -f "$HOME/.hh_shortcuts.sh" ] && . "$HOME/.hh_shortcuts.sh"' | |
| SOURCE_MARKER='# >>> hh_shortcuts >>>' | |
| SOURCE_END='# <<< hh_shortcuts <<<' | |
| wire_into_rc() { | |
| local rc="$1" | |
| if [ ! -f "$rc" ]; then | |
| info "Creating $rc" | |
| touch "$rc" | |
| fi | |
| if grep -Fq "$SOURCE_MARKER" "$rc"; then | |
| info "Already wired into ${BOLD}${rc}${RESET}, skipping." | |
| return | |
| fi | |
| info "Adding source line to ${BOLD}${rc}${RESET}" | |
| { | |
| printf '\n%s\n' "$SOURCE_MARKER" | |
| printf '%s\n' "$SOURCE_LINE" | |
| printf '%s\n' "$SOURCE_END" | |
| } >> "$rc" | |
| } | |
| # ---------- run ---------- | |
| install_yaak | |
| write_shortcuts | |
| wire_into_rc "$HOME/.bashrc" | |
| # also do zsh if the user has it | |
| if [ -f "$HOME/.zshrc" ] || command -v zsh >/dev/null 2>&1; then | |
| wire_into_rc "$HOME/.zshrc" | |
| fi | |
| info "${BOLD}Done.${RESET}" | |
| echo | |
| echo "Open a new shell, or run: source ~/.hh_shortcuts.sh" | |
| echo "Try it: gst" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment