tbeseda

Home
All Posts

gitclean zsh command

gitclean() {
  git clean -Xdn
  if read -q REPLY\?"Clean these? (Y/y)"; then
    git clean -Xdf
  else
    echo "Still dirty."
  fi
}

For more fancy, use "gum":

gitclean() {
  DIRTY=$(git clean -Xdn | sed 's/Would remove //g')

  gum style \
    --foreground 196 --border thick --border-foreground 88 \
    --margin "1 2" --padding "1 3" "$DIRTY"

  gum confirm "🧹 Delete these?" \
    && git clean -Xdf \
    || echo "Still dirty."
}

gum docs
gist version with preview image

---

All Posts