|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Read current version from VERSION file |
| 4 | +current_version=$(cat VERSION) |
| 5 | + |
| 6 | +# Function to increment version |
| 7 | +bump_version() { |
| 8 | + local version="$1" |
| 9 | + local type="$2" |
| 10 | + local IFS="." |
| 11 | + local -a parts=(${version}) |
| 12 | + |
| 13 | + case "$type" in |
| 14 | + "major") |
| 15 | + parts[0]=$((parts[0] + 1)) |
| 16 | + parts[1]=0 |
| 17 | + parts[2]=0 |
| 18 | + ;; |
| 19 | + "minor") |
| 20 | + parts[1]=$((parts[1] + 1)) |
| 21 | + parts[2]=0 |
| 22 | + ;; |
| 23 | + "patch") |
| 24 | + parts[2]=$((parts[2] + 1)) |
| 25 | + ;; |
| 26 | + *) |
| 27 | + echo "Invalid bump type: $type" |
| 28 | + return 1 |
| 29 | + ;; |
| 30 | + esac |
| 31 | + |
| 32 | + echo "${parts[0]}.${parts[1]}.${parts[2]}" |
| 33 | +} |
| 34 | + |
| 35 | +# Calculate new versions |
| 36 | +new_patch_version=$(bump_version "$current_version" "patch") |
| 37 | +new_minor_version=$(bump_version "$current_version" "minor") |
| 38 | +new_major_version=$(bump_version "$current_version" "major") |
| 39 | + |
| 40 | +# Menu items |
| 41 | +menu_items=( |
| 42 | + "patch (${current_version} → ${new_patch_version})" |
| 43 | + "minor (${current_version} → ${new_minor_version})" |
| 44 | + "major (${current_version} → ${new_major_version})" |
| 45 | + "exit" |
| 46 | +) |
| 47 | + |
| 48 | +# Function to draw menu |
| 49 | +draw_menu() { |
| 50 | + local selected=$1 |
| 51 | + clear |
| 52 | + echo "Current version: $current_version" |
| 53 | + echo "Use ↑/↓ arrows to navigate, Enter to select" |
| 54 | + echo |
| 55 | + |
| 56 | + for i in "${!menu_items[@]}"; do |
| 57 | + if [ $i -eq $selected ]; then |
| 58 | + echo "→ ${menu_items[$i]} ←" |
| 59 | + else |
| 60 | + echo " ${menu_items[$i]}" |
| 61 | + fi |
| 62 | + done |
| 63 | +} |
| 64 | + |
| 65 | +# Initialize selection |
| 66 | +selected=0 |
| 67 | + |
| 68 | +# Hide cursor and configure terminal |
| 69 | +tput civis |
| 70 | +stty -echo |
| 71 | + |
| 72 | +# Cleanup function |
| 73 | +cleanup() { |
| 74 | + tput cnorm |
| 75 | + stty echo |
| 76 | +} |
| 77 | +trap cleanup EXIT |
| 78 | + |
| 79 | +# Main menu loop |
| 80 | +while true; do |
| 81 | + draw_menu $selected |
| 82 | + |
| 83 | + # Read a key |
| 84 | + IFS= read -r -n1 key |
| 85 | + |
| 86 | + case "$key" in |
| 87 | + $'\x1b') # ESC sequence |
| 88 | + read -r -n2 rest |
| 89 | + case "$rest" in |
| 90 | + '[A') # Up arrow |
| 91 | + if [ $selected -gt 0 ]; then |
| 92 | + selected=$((selected - 1)) |
| 93 | + fi |
| 94 | + ;; |
| 95 | + '[B') # Down arrow |
| 96 | + if [ $selected -lt $((${#menu_items[@]} - 1)) ]; then |
| 97 | + selected=$((selected + 1)) |
| 98 | + fi |
| 99 | + ;; |
| 100 | + esac |
| 101 | + ;; |
| 102 | + "") # Enter key |
| 103 | + clear |
| 104 | + stty echo |
| 105 | + tput cnorm |
| 106 | + |
| 107 | + case $selected in |
| 108 | + 0) new_version="$new_patch_version" ;; |
| 109 | + 1) new_version="$new_minor_version" ;; |
| 110 | + 2) new_version="$new_major_version" ;; |
| 111 | + 3) echo "Exiting..."; exit 0 ;; |
| 112 | + esac |
| 113 | + |
| 114 | + read -p "Confirm version bump to $new_version? [y/N] " confirm |
| 115 | + if [[ ! "$confirm" =~ ^[Yy] ]]; then |
| 116 | + echo "Cancelled" |
| 117 | + exit 0 |
| 118 | + fi |
| 119 | + |
| 120 | + # Update VERSION file |
| 121 | + echo "$new_version" > VERSION |
| 122 | + |
| 123 | + # Update the cask file with the new version |
| 124 | + sed -i "" "s/version \".*\"/version \"$new_version\"/g" Casks/chilikeys.rb |
| 125 | + |
| 126 | + # Commit the changes |
| 127 | + git add Casks/chilikeys.rb VERSION |
| 128 | + git commit -m "Update cask version to $new_version" |
| 129 | + |
| 130 | + # Add the new tag |
| 131 | + git tag "v$new_version" |
| 132 | + |
| 133 | + # Push the tags |
| 134 | + git push origin --tags |
| 135 | + |
| 136 | + echo "Version bumped to $new_version and tag v$new_version added and pushed successfully." |
| 137 | + exit 0 |
| 138 | + ;; |
| 139 | + esac |
| 140 | +done |
0 commit comments