gitflash 0.8.0.beta2 → 0.9.0.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 23ba7339e9f7379f584f077360187ad644c37fdd5072e3543884158b005b4959
4
- data.tar.gz: 4acf7c6abced1e55db26363423526578044c261ddb7ff159da4f30fd7cde512c
3
+ metadata.gz: ad145aeb23d517bd2bd1effa7b4e973e8c401e0702fb9d5ead180625f5f383f2
4
+ data.tar.gz: 42a90e6328cd4bbeb47f37326c03edc1c29bfaf7b66e176284c6640a773fd53f
5
5
  SHA512:
6
- metadata.gz: be4b287957681955938a05122449bf7a47446882ba1fbe07a785f55d15c938331c95f457fe8819ee3b5b4f252fa47e3ecdbe639a43754abc0ab18e160790f5cd
7
- data.tar.gz: ebd1ea09af65e869af1c50944c90389a323528edeb5c541b69c8d9f7476abe8d6de6995743abd6dc419a5e06029a3a19e75c57c064655b8438e0a57a47bcdf10
6
+ metadata.gz: 0ca23e4a816bca82cf28d87fbd2014327da12ff8c9f1907d8e8ceb8bd1d1bd0201dcab576e823bddd2522f3ddd88c27e70619c691fba3310b06c173e00f80a0e
7
+ data.tar.gz: e4639651d40e3bca4cc30f99fdb75f1951fa718e9a3b54f8168354d41d05c7da6b01eb8133ccf663336f09d83bfc4d728d67966421ee17bf8685506b7e1da916
data/CHANGELOG.md CHANGED
@@ -195,3 +195,24 @@ Second beta of the agent integrations release. gitflash itself has not changed s
195
195
  - Tested with `mcp` 1.9.0; the requirement stays `~> 1.8`
196
196
  - Development and CI only: `rubocop` 1.92.2, `pry` 0.16.1, `simplecov` 1.3.2 and `ruby/setup-ruby` 1.338.0, and Dependabot proposes gem updates as well as Action updates
197
197
  - Contributors: rules for pull requests and reviews (`docs/pull-requests.md`, `REVIEW.md`)
198
+
199
+ ## [0.8.0] - 2026-11-21
200
+
201
+ The agent integrations release: an Agent Skill, an MCP server that asks the user to approve destructive changes, and a Claude Code plugin that installs the hook, the server and the skill together, with every change from 0.8.0.beta1 and beta2 above. gitflash itself has not changed since 0.8.0.beta2. Needs git 2.36 or newer.
202
+
203
+ Upgrading from 0.7.0:
204
+
205
+ - Check scripts and agent instructions against the behaviour changes listed under 0.8.0.beta1: `clean` and `wt clean` keep a branch nobody has committed to since it was created, `--stale` counts the latest move of a branch, and `undo` can name an earlier snapshot marked `"reused": true`
206
+ - New runtime dependency: `mcp` (~> 1.8), tested with 1.10.0
207
+ - To use the Claude Code plugin, install the gem first, then `/plugin marketplace add Kleanthismits/git_flash` and `/plugin install gitflash@gitflash`. Do not keep a hook from `gitflash hook install` next to the plugin, or the hook runs twice
208
+ - Development and CI only: `rubocop` 1.92.3 and `ruby/setup-ruby` 1.341.0
209
+
210
+ ## [0.9.0.beta1] - 2026-11-22
211
+
212
+ First beta of the distribution release: shell completion for bash, zsh and fish, and releases published from GitHub Actions through RubyGems trusted publishing. No behaviour changes in existing commands or in the JSON contract. Install with `gem install gitflash --pre`. Needs git 2.36 or newer.
213
+
214
+ The changes:
215
+
216
+ - Add `completion SHELL`: prints a completion script for `bash`, `zsh` or `fish`. It completes commands, the `worktree` (`wt`), `hook` and `skill` subcommands, options and their values, and local branch names for arguments that take a branch or worktree, and file names for paths. The script is built from the commands of the installed version, so run it again after upgrading. Completing runs `git`, never gitflash
217
+ - Releases are published from GitHub Actions when a version tag is pushed, through RubyGems trusted publishing: no RubyGems key is stored. The workflow refuses a tag that does not match the gem version
218
+ - Development and CI only: help texts load into frozen `Data` records instead of nested Structs; CI also runs Ruby 4.0
data/README.md CHANGED
@@ -79,13 +79,23 @@ Requires Ruby 3.3+ and git 2.36+ (the worktree commands read `git worktree list
79
79
 
80
80
  Prerelease versions (named like `0.7.0.beta3`) are only installed when you ask for them: `gem install gitflash --pre`, or the exact version in a Gemfile.
81
81
 
82
+ Shell completion for commands, options, branch names and paths:
83
+
84
+ ```bash
85
+ echo 'source <(gitflash completion zsh)' >> ~/.zshrc # after compinit
86
+ echo 'source <(gitflash completion bash)' >> ~/.bashrc
87
+ mkdir -p ~/.config/fish/completions && gitflash completion fish > ~/.config/fish/completions/gitflash.fish
88
+ ```
89
+
90
+ Run it again after upgrading gitflash; `gitflash help completion` has the details.
91
+
82
92
  ## Quick start for agents
83
93
 
84
94
  Pick one. Details for each are in [Agent integrations](https://github.com/Kleanthismits/git_flash/blob/main/docs/agent-integrations.md).
85
95
 
86
96
  | Way | Command | You get |
87
97
  | --- | --- | --- |
88
- | Claude Code plugin | `/plugin marketplace add Kleanthismits/git_flash`, then `/plugin install gitflash@gitflash` | Hook, MCP server and skill in one install (gem 0.8.0 or newer; for now the 0.8.0.beta2 prerelease: `gem install gitflash --pre`) |
98
+ | Claude Code plugin | `/plugin marketplace add Kleanthismits/git_flash`, then `/plugin install gitflash@gitflash` | Hook, MCP server and skill in one install (gem 0.8.0 or newer) |
89
99
  | Hook and skill | `gitflash hook install` and `gitflash skill install` | Snapshots before destructive plain git commands; the agent learns to prefer gitflash |
90
100
  | MCP server | `claude mcp add gitflash -- gitflash mcp` | gitflash as MCP tools, with your approval before destructive changes |
91
101
 
@@ -113,6 +123,7 @@ Run `gitflash` inside a git repository for the list, and `gitflash help <command
113
123
  | `gitflash skill install`, `skill show` | Install or print the gitflash Agent Skill |
114
124
  | `gitflash mcp` | Run an MCP server for the current repository on stdio |
115
125
  | `gitflash schema` | Print the JSON Schema of the `--json` output |
126
+ | `gitflash completion SHELL` | Print the completion script for `bash`, `zsh` or `fish` |
116
127
  | `gitflash version` | Print the installed version (also `--version`, `-v`) |
117
128
 
118
129
  ## Undo
@@ -177,7 +188,9 @@ After checking out the repository, run `bin/setup` to install dependencies. Then
177
188
 
178
189
  To install the gem from your checkout, run `bundle exec rake install`.
179
190
 
180
- To release, bump the version in `lib/gitflash/version.rb` and `.claude-plugin/plugin.json` (a spec checks they match), move the `[Unreleased]` notes in `CHANGELOG.md` under the new version, and run `bundle exec rake release`. It tags the version, pushes the tag and publishes the gem to [rubygems.org](https://rubygems.org/gems/gitflash).
191
+ The first release needs two settings made once by the maintainer: a GitHub environment named `release`, and a trusted publisher on rubygems.org for this repository, the workflow `release.yml` and the environment `release`. Without them the Release workflow cannot publish.
192
+
193
+ To release, bump the version in `lib/gitflash/version.rb` and `.claude-plugin/plugin.json` (a spec checks they match), move the `[Unreleased]` notes in `CHANGELOG.md` under the new version, and merge it into `main`. Then tag that commit and push the tag: `git tag v0.9.0 && git push origin v0.9.0`. The Release workflow checks the tag against the version, runs the specs and publishes the gem to [rubygems.org](https://rubygems.org/gems/gitflash) through trusted publishing; no RubyGems key is stored anywhere.
181
194
 
182
195
  ## Contributing
183
196
 
data/lib/gitflash/cli.rb CHANGED
@@ -35,8 +35,8 @@ module Gitflash
35
35
  class_option :dry_run, type: :boolean, default: false,
36
36
  desc: 'Show what would happen without changing anything'
37
37
 
38
- desc 'branches', descriptions.branches.short
39
- long_desc descriptions.branches.long
38
+ desc 'branches', description(:branches).short
39
+ long_desc description(:branches).long
40
40
  option :merged, type: :boolean, desc: 'Branches merged into the default branch'
41
41
  option :gone, type: :boolean, desc: 'Branches whose upstream branch was deleted'
42
42
  option :stale, type: :numeric, banner: 'DAYS', desc: 'Branches without commits for DAYS days'
@@ -44,22 +44,22 @@ module Gitflash
44
44
  run_command('branches', Commands::Branches)
45
45
  end
46
46
 
47
- desc 'checkout [BRANCH]', descriptions.checkout.short
48
- long_desc descriptions.checkout.long
47
+ desc 'checkout [BRANCH]', description(:checkout).short
48
+ long_desc description(:checkout).long
49
49
  def checkout(branch = nil)
50
50
  run_command('checkout', Commands::Checkout, *[branch].compact)
51
51
  end
52
52
 
53
- desc 'delete [BRANCH...]', descriptions.delete.short
54
- long_desc descriptions.delete.long
53
+ desc 'delete [BRANCH...]', description(:delete).short
54
+ long_desc description(:delete).long
55
55
  option :force, type: :boolean, default: false,
56
56
  desc: 'Delete branches even if they have unmerged changes'
57
57
  def delete(*branches)
58
58
  run_command('delete', Commands::Delete, *branches)
59
59
  end
60
60
 
61
- desc 'mark [BRANCH...]', descriptions.mark.short
62
- long_desc descriptions.mark.long
61
+ desc 'mark [BRANCH...]', description(:mark).short
62
+ long_desc description(:mark).long
63
63
  option :owner, type: :string, enum: Ownership::OWNERS,
64
64
  desc: 'agent or human (default: human in a terminal, agent otherwise)'
65
65
  option :clear, type: :boolean, default: false, desc: 'Remove the mark'
@@ -67,8 +67,8 @@ module Gitflash
67
67
  run_command('mark', Commands::Mark, *branches)
68
68
  end
69
69
 
70
- desc 'clean', descriptions.clean.short
71
- long_desc descriptions.clean.long
70
+ desc 'clean', description(:clean).short
71
+ long_desc description(:clean).long
72
72
  option :merged, type: :boolean, desc: 'Branches merged into the default branch'
73
73
  option :gone, type: :boolean, desc: 'Branches whose upstream branch was deleted'
74
74
  option :stale, type: :string, banner: 'DAYS', lazy_default: '',
@@ -80,16 +80,16 @@ module Gitflash
80
80
  run_command('clean', Commands::Clean)
81
81
  end
82
82
 
83
- desc 'reset [COMMIT]', descriptions.reset.short
84
- long_desc descriptions.reset.long
83
+ desc 'reset [COMMIT]', description(:reset).short
84
+ long_desc description(:reset).long
85
85
  option :hard, type: :boolean, default: false, desc: 'Discard all current changes'
86
86
  option :soft, type: :boolean, default: false, desc: 'Keep changes staged'
87
87
  def reset(commit = nil)
88
88
  run_command('reset', Commands::Reset, *[commit].compact)
89
89
  end
90
90
 
91
- desc 'undo [SNAPSHOT]', descriptions.undo.short
92
- long_desc descriptions.undo.long
91
+ desc 'undo [SNAPSHOT]', description(:undo).short
92
+ long_desc description(:undo).long
93
93
  def undo(snapshot = nil)
94
94
  run_command('undo', Commands::Undo, *[snapshot].compact)
95
95
  end
@@ -99,8 +99,8 @@ module Gitflash
99
99
  run_command('snapshots', Commands::SnapshotList)
100
100
  end
101
101
 
102
- desc 'snapshot', descriptions.snapshot.short
103
- long_desc descriptions.snapshot.long
102
+ desc 'snapshot', description(:snapshot).short
103
+ long_desc description(:snapshot).long
104
104
  option :message, type: :string, desc: 'Why the snapshot was taken'
105
105
  option :scope, type: :array, banner: 'PARTS',
106
106
  desc: 'Parts to save: branches head worktree stashes (default: all)'
@@ -128,8 +128,8 @@ module Gitflash
128
128
  desc 'skill SUBCOMMAND', 'The Agent Skill that teaches agents to use gitflash'
129
129
  subcommand 'skill', SkillCli
130
130
 
131
- desc 'pick [SOURCE] [SHA...]', descriptions.pick.short
132
- long_desc descriptions.pick.long
131
+ desc 'pick [SOURCE] [SHA...]', description(:pick).short
132
+ long_desc description(:pick).long
133
133
  option :list, type: :boolean, desc: 'List the commits of SOURCE that are not on this branch yet'
134
134
  option :commit, type: :boolean, default: true,
135
135
  desc: 'Create a commit per pick; --no-commit only stages the changes'
@@ -178,6 +178,25 @@ module Gitflash
178
178
  puts File.read(SCHEMA_PATH)
179
179
  end
180
180
 
181
+ desc 'completion SHELL', 'Print the shell completion script for bash, zsh or fish'
182
+ long_desc <<~TEXT
183
+ Prints a completion script for SHELL (bash, zsh or fish) on stdout. It completes commands,
184
+ worktree, hook and skill subcommands, options and their values, local branch names for
185
+ arguments that take a branch or worktree, and file names for paths. Completing runs git,
186
+ never gitflash.
187
+
188
+ bash: add `source <(gitflash completion bash)` to ~/.bashrc
189
+ zsh: add `source <(gitflash completion zsh)` to ~/.zshrc after compinit, or save the
190
+ output as _gitflash in a directory of $fpath
191
+ fish: mkdir -p ~/.config/fish/completions
192
+ gitflash completion fish > ~/.config/fish/completions/gitflash.fish
193
+
194
+ Run it again after upgrading gitflash to complete new commands and options.
195
+ TEXT
196
+ def completion(shell)
197
+ puts Completion.new.script(shell)
198
+ end
199
+
181
200
  desc 'version', 'Print the gitflash version'
182
201
  map %w[--version -v] => :version
183
202
 
@@ -0,0 +1,81 @@
1
+ # gitflash completion for bash. Load it with: source <(gitflash completion bash)
2
+
3
+ # Adds the local branches that start with $1 (its backslashes removed), quoted for the command
4
+ # line. Branch names never go through compgen -W, which would expand them: a branch named
5
+ # $(...) would run.
6
+ _gitflash_branches() {
7
+ local b q prefix=${1//\\/}
8
+ while IFS= read -r b; do
9
+ [[ $b == "$prefix"* ]] || continue
10
+ printf -v q '%q' "$b"
11
+ COMPREPLY+=("$q")
12
+ done < <(<%= View::BRANCHES %>)
13
+ }
14
+
15
+ # True when $1 is a switch whose value follows it
16
+ _gitflash_takes_value() {
17
+ case $1 in <%= tree.value_switches.join('|') %>) return 0 ;; esac
18
+ return 1
19
+ }
20
+
21
+ _gitflash() {
22
+ local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
23
+ # --switch=value: bash 4 and later split it into --switch, = and value (= is in
24
+ # COMP_WORDBREAKS). bash 3.2 keeps one word, but readline still replaces only the value.
25
+ # Only an = after a switch that takes a value joins the two: = is a valid branch name.
26
+ if [[ $cur == = ]] && _gitflash_takes_value "$prev"; then
27
+ cur=''
28
+ elif [[ $prev == = ]] && _gitflash_takes_value "${COMP_WORDS[COMP_CWORD-2]}"; then
29
+ prev=${COMP_WORDS[COMP_CWORD-2]}
30
+ elif [[ $cur == --*=* ]] && _gitflash_takes_value "${cur%%=*}"; then
31
+ prev=${cur%%=*} cur=${cur#*=}
32
+ fi
33
+ COMPREPLY=()
34
+ _gitflash_complete
35
+ }
36
+
37
+ # Reads cur and prev from _gitflash and fills COMPREPLY
38
+ _gitflash_complete() {
39
+ local -a found=()
40
+ local i w skip=0
41
+ for ((i = 1; i < COMP_CWORD; i++)); do
42
+ w=${COMP_WORDS[i]}
43
+ # = after a switch that takes a value: the next word is that value, never an argument
44
+ if [[ $w == = ]] && _gitflash_takes_value "${COMP_WORDS[i-1]}"; then skip=1; continue; fi
45
+ if ((skip)); then skip=0; continue; fi
46
+ if _gitflash_takes_value "$w"; then skip=1; continue; fi
47
+ case $w in -*) continue ;; esac
48
+ found+=("$w")
49
+ done
50
+ local cmd=${found[0]-} n=$(( ${#found[@]} - 1 ))
51
+ <% tree.aliases.each do |from, to| -%>
52
+ [[ $cmd == <%= from %> ]] && cmd=<%= to %>
53
+ <% end -%>
54
+ case $cmd in <%= tree.groups.join('|') %>) if ((n > 0)); then cmd="$cmd ${found[1]}"; n=$((n - 1)); fi ;; esac
55
+ case "$cmd $prev" in
56
+ <% value_cases.each do |pattern, value| -%>
57
+ <%= pattern %>) <%= bash_action(value) %>; return ;;
58
+ <% end -%>
59
+ esac
60
+ if [[ $cur == -* ]]; then
61
+ local words='<%= switches(tree.global_options) %>'
62
+ case $cmd in
63
+ <% commands_with_options.each do |command| -%>
64
+ '<%= command.path %>') words+=' <%= switches(command.options) %>' ;;
65
+ <% end -%>
66
+ esac
67
+ COMPREPLY=($(compgen -W "$words" -- "$cur"))
68
+ return
69
+ fi
70
+ case "$cmd $n" in
71
+ ' -1') COMPREPLY=($(compgen -W '<%= names(tree.children) %>' -- "$cur")) ;;
72
+ <% tree.groups.each do |group| -%>
73
+ '<%= group %> 0') COMPREPLY=($(compgen -W '<%= names(tree.children(group)) %>' -- "$cur")) ;;
74
+ <% end -%>
75
+ <% argument_cases.each do |pattern, value| -%>
76
+ <%= pattern %>) <%= bash_action(value) %> ;;
77
+ <% end -%>
78
+ esac
79
+ }
80
+ # -o default: bash completes file names when the function offers nothing (PATH and DIR values)
81
+ complete -o default -F _gitflash gitflash
@@ -0,0 +1,74 @@
1
+ # gitflash completion for fish. Load it with: gitflash completion fish | source
2
+ # or save it as ~/.config/fish/completions/gitflash.fish
3
+
4
+ # Prints the command being completed, then how many of its arguments come before this word
5
+ function __gitflash_cmd
6
+ set -l tokens (commandline -opc)
7
+ set -e tokens[1]
8
+ set -l found
9
+ set -l skip 0
10
+ for w in $tokens
11
+ if test $skip -eq 1
12
+ set skip 0
13
+ continue
14
+ end
15
+ switch $w
16
+ case <%= tree.value_switches.join(' ') %>
17
+ set skip 1
18
+ continue
19
+ case '-*'
20
+ continue
21
+ end
22
+ set -a found $w
23
+ end
24
+ set -l cmd $found[1]
25
+ set -l n (math (count $found) - 1)
26
+ <% tree.aliases.each do |from, to| -%>
27
+ test "$cmd" = <%= from %>; and set cmd <%= to %>
28
+ <% end -%>
29
+ if contains -- "$cmd" <%= tree.groups.join(' ') %>; and test $n -gt 0
30
+ set cmd "$cmd $found[2]"
31
+ set n (math $n - 1)
32
+ end
33
+ echo $cmd
34
+ echo $n
35
+ end
36
+
37
+ # True when completing command path $argv[1]; with $argv[2], only at argument n ("1") or at
38
+ # argument n and later ("1+")
39
+ function __gitflash_at
40
+ set -l state (__gitflash_cmd)
41
+ test "$state[1]" = "$argv[1]"; or return 1
42
+ set -q argv[2]; or return 0
43
+ set -l n (string trim -r -c + -- $argv[2])
44
+ if string match -q -- '*+' $argv[2]
45
+ test $state[2] -ge $n
46
+ else
47
+ test $state[2] -eq $n
48
+ end
49
+ end
50
+
51
+ function __gitflash_branches
52
+ <%= View::BRANCHES %>
53
+ end
54
+
55
+ complete -c gitflash -f
56
+ <% tree.children.each do |name, text| -%>
57
+ complete -c gitflash -n '__gitflash_at ""' -a <%= name %> -d <%= fish_quote(text) %>
58
+ <% end -%>
59
+ <% tree.groups.each do |group| -%>
60
+ <% tree.children(group).each do |name, text| -%>
61
+ complete -c gitflash <%= fish_at(group, '0') %> -a <%= name %> -d <%= fish_quote(text) %>
62
+ <% end -%>
63
+ <% end -%>
64
+ <% tree.global_options.each do |option| -%>
65
+ complete -c gitflash <%= fish_option(option) %>
66
+ <% end -%>
67
+ <% tree.commands.each do |command| -%>
68
+ <% command.options.each do |option| -%>
69
+ complete -c gitflash <%= fish_at(command.path) %> <%= fish_option(option) %>
70
+ <% end -%>
71
+ <% end -%>
72
+ <% fish_arguments.each do |path, argument, value| -%>
73
+ complete -c gitflash <%= fish_at(path, argument) %> <%= fish_values(value) %>
74
+ <% end -%>
@@ -0,0 +1,152 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'erb'
4
+
5
+ module Gitflash
6
+ class Completion
7
+ # Renders the templates in this directory: `tree` is the Completion they read, and the
8
+ # helpers put it in the shapes the scripts need, quoted for each shell. Every script works
9
+ # out the command being completed the same way: the first word that is not an option (or an
10
+ # option's value), plus the second one when the first names a group (`hook`, `skill`,
11
+ # `worktree`/`wt`). The words after it are its positional arguments, counted from 0.
12
+ class View
13
+ BRANCHES = "git for-each-ref --format='%(refname:lstrip=2)' refs/heads 2>/dev/null"
14
+ # What each shell runs to offer a value that is not fixed words. bash offers nothing but
15
+ # branches: it completes file names itself (`complete -o default`).
16
+ BASH = { branch: '_gitflash_branches "$cur"' }.freeze
17
+ ZSH = { branch: "compadd -- ${(f)\"$(#{BRANCHES})\"}", path: '_files',
18
+ directory: '_files -/' }.freeze
19
+ FISH = { branch: "-a '(__gitflash_branches)'", path: '-F',
20
+ directory: "-a '(__fish_complete_directories)'" }.freeze
21
+
22
+ attr_reader :tree
23
+
24
+ def initialize(tree)
25
+ @tree = tree
26
+ end
27
+
28
+ def render(template)
29
+ ERB.new(File.read(template), trim_mode: '-').result(binding)
30
+ end
31
+
32
+ # Commands that have options of their own
33
+ def commands_with_options
34
+ tree.commands.reject { |command| command.options.empty? }
35
+ end
36
+
37
+ # [case pattern on "$cmd $prev", value] for every option whose value must follow it: the
38
+ # command's own options first, then the global ones under any command. An option whose
39
+ # value may be left out is not listed, so the word after it completes as an argument.
40
+ def value_cases
41
+ own = tree.commands.flat_map do |command|
42
+ required(command.options).map do |switch, value|
43
+ [sh_quote("#{command.path} #{switch}"), value]
44
+ end
45
+ end
46
+ own + required(tree.global_options).map do |switch, value|
47
+ ["*#{sh_quote(" #{switch}")}", value]
48
+ end
49
+ end
50
+
51
+ # [case pattern on "$cmd $n", value] for every positional argument, where n counts the
52
+ # arguments before the one being completed. A repeated last argument is a pattern that
53
+ # matches any n: the patterns of the arguments before it come first, and the first match
54
+ # wins.
55
+ def argument_cases
56
+ tree.commands.flat_map do |command|
57
+ last = command.repeats ? command.arguments.size - 1 : nil
58
+ command.arguments.each_with_index.map do |value, index|
59
+ if index == last then ["#{sh_quote("#{command.path} ")}*", value]
60
+ else [sh_quote("#{command.path} #{index}"), value]
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ # [command path, n or "n+", value] for every positional argument that completes something
67
+ def fish_arguments
68
+ tree.commands.flat_map do |command|
69
+ last = command.repeats ? command.arguments.size - 1 : nil
70
+ command.arguments.each_with_index.filter_map do |value, index|
71
+ next unless value
72
+
73
+ [command.path, index == last ? "#{index}+" : index.to_s, value]
74
+ end
75
+ end
76
+ end
77
+
78
+ # Fixed words are static, from the code, so they may go through compgen -W
79
+ def bash_action(value)
80
+ if value.is_a?(Array)
81
+ "COMPREPLY=($(compgen -W '#{value.join(' ')}' -- \"$cur\"))"
82
+ else
83
+ BASH.fetch(value, ':')
84
+ end
85
+ end
86
+
87
+ def zsh_action(value)
88
+ value.is_a?(Array) ? "compadd -- #{value.join(' ')}" : ZSH.fetch(value, ':')
89
+ end
90
+
91
+ def fish_values(value)
92
+ value.is_a?(Array) ? "-a #{fish_quote(value.join(' '))}" : FISH[value]
93
+ end
94
+
95
+ def switches(options)
96
+ options.flat_map(&:switches).join(' ')
97
+ end
98
+
99
+ def names(entries)
100
+ entries.map(&:first).join(' ')
101
+ end
102
+
103
+ # zsh `_describe` entries: 'name:description'
104
+ def described_options(options)
105
+ options.flat_map { |option| option.switches.map { |switch| [switch, option.description] } }
106
+ .then { |entries| described(entries) }
107
+ end
108
+
109
+ def described(entries)
110
+ entries.map { |name, text| sh_quote("#{name}:#{text}") }.join(' ')
111
+ end
112
+
113
+ def sh_quote(text)
114
+ "'#{text.gsub("'") { "'\\''" }}'"
115
+ end
116
+
117
+ def fish_quote(text)
118
+ "'#{text.gsub(/[\\']/) { |char| "\\#{char}" }}'"
119
+ end
120
+
121
+ # The condition that limits a fish completion to one command path, and to its argument
122
+ # number n ("1", or "1+" for the first and later ones) when given
123
+ def fish_at(path, argument = nil)
124
+ "-n '__gitflash_at \"#{path}\"#{" #{argument}" if argument}'"
125
+ end
126
+
127
+ # `-l json -s y -x -a 'a b' -d '...'` for one option
128
+ def fish_option(option)
129
+ flags = option.switches.map { |switch| fish_flag(switch) }
130
+ flags << fish_value(option) if option.takes_value && !option.optional
131
+ flags << "-d #{fish_quote(option.description)}" unless option.description.empty?
132
+ flags.join(' ')
133
+ end
134
+
135
+ private
136
+
137
+ def required(options)
138
+ options.select { |option| option.takes_value && !option.optional }
139
+ .flat_map { |option| option.switches.map { |switch| [switch, option.value] } }
140
+ end
141
+
142
+ def fish_flag(switch)
143
+ switch.start_with?('--') ? "-l #{switch.delete_prefix('--')}" : "-s #{switch[1..]}"
144
+ end
145
+
146
+ # `-x` takes a value and no file names, `-r` a value that may be a file name
147
+ def fish_value(option)
148
+ option.value == :path ? '-r -F' : ['-x', fish_values(option.value)].compact.join(' ')
149
+ end
150
+ end
151
+ end
152
+ end
@@ -0,0 +1,51 @@
1
+ #compdef gitflash
2
+ # gitflash completion for zsh. Load it with: source <(gitflash completion zsh)
3
+ # or save it as _gitflash in a directory of $fpath.
4
+ _gitflash() {
5
+ local -a found items
6
+ local i w skip=0
7
+ for ((i = 2; i < CURRENT; i++)); do
8
+ w=${words[i]}
9
+ if ((skip)); then skip=0; continue; fi
10
+ case $w in
11
+ (<%= tree.value_switches.join('|') %>) skip=1; continue ;;
12
+ (-*) continue ;;
13
+ esac
14
+ found+=("$w")
15
+ done
16
+ local cmd=${found[1]-} prev=${words[CURRENT-1]}
17
+ local n=$(( ${#found} - 1 ))
18
+ <% tree.aliases.each do |from, to| -%>
19
+ [[ $cmd == <%= from %> ]] && cmd=<%= to %>
20
+ <% end -%>
21
+ case $cmd in (<%= tree.groups.join('|') %>) if ((n > 0)); then cmd="$cmd ${found[2]}"; n=$((n - 1)); fi ;; esac
22
+ case "$cmd $prev" in
23
+ <% value_cases.each do |pattern, value| -%>
24
+ (<%= pattern %>) <%= zsh_action(value) %>; return ;;
25
+ <% end -%>
26
+ esac
27
+ if [[ $PREFIX == -* ]]; then
28
+ items=(<%= described_options(tree.global_options) %>)
29
+ case $cmd in
30
+ <% commands_with_options.each do |command| -%>
31
+ ('<%= command.path %>') items+=(<%= described_options(command.options) %>) ;;
32
+ <% end -%>
33
+ esac
34
+ _describe -t options option items
35
+ return
36
+ fi
37
+ case "$cmd $n" in
38
+ (' -1') items=(<%= described(tree.children) %>); _describe -t commands command items ;;
39
+ <% tree.groups.each do |group| -%>
40
+ ('<%= group %> 0') items=(<%= described(tree.children(group)) %>); _describe -t commands command items ;;
41
+ <% end -%>
42
+ <% argument_cases.each do |pattern, value| -%>
43
+ (<%= pattern %>) <%= zsh_action(value) %> ;;
44
+ <% end -%>
45
+ esac
46
+ }
47
+ if [[ $funcstack[1] == _gitflash ]]; then
48
+ _gitflash "$@"
49
+ else
50
+ compdef _gitflash gitflash
51
+ fi
@@ -0,0 +1,103 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gitflash
4
+ # Shell completion scripts for `gitflash completion SHELL`, built from the Thor command tree so
5
+ # a new command or option is completed without editing a script. What an argument or an option
6
+ # value completes comes from its name in the usage (`checkout [BRANCH]`) or its banner (`REF`);
7
+ # branch names are read with plain git, so completing never starts Ruby.
8
+ class Completion
9
+ SHELLS = %w[bash zsh fish].freeze
10
+ HIDDEN = %w[tree].freeze
11
+ TEMPLATES = File.expand_path('completion', __dir__)
12
+
13
+ # What a value completes: local branch names, any path, directories, or fixed words (an
14
+ # Array). A name that is not listed completes nothing.
15
+ ARGUMENTS = { 'BRANCH' => :branch, 'SOURCE' => :branch, 'COMMIT' => :branch,
16
+ 'WORKTREE' => :branch, 'PATH' => :path, 'SHELL' => SHELLS }.freeze
17
+ BANNERS = { 'REF' => :branch, 'DIR' => :directory }.freeze
18
+
19
+ # `value` is what the option's value completes; `optional` when it may be left out
20
+ # (`clean --stale`), so the next word may be an argument instead
21
+ Option = Data.define(:switches, :description, :takes_value, :optional, :value)
22
+ # `arguments` are what each positional argument completes, in order; `repeats` when the last
23
+ # one may be given more than once (`delete [BRANCH...]`)
24
+ Command = Data.define(:path, :description, :options, :arguments, :repeats)
25
+
26
+ def initialize(cli = Cli)
27
+ @cli = cli
28
+ end
29
+
30
+ def script(shell)
31
+ unless SHELLS.include?(shell)
32
+ raise Thor::Error, "Unknown shell '#{shell}'. Choose one of: #{SHELLS.join(', ')}"
33
+ end
34
+
35
+ View.new(self).render(File.join(TEMPLATES, "#{shell}.erb"))
36
+ end
37
+
38
+ # Words that name a command at the top level or inside a group, with the group aliases
39
+ def groups
40
+ @cli.subcommand_classes.keys
41
+ end
42
+
43
+ def aliases
44
+ @cli.map.filter_map { |from, to|
45
+ [from, to.to_s] if !from.start_with?('-') && groups.include?(to.to_s)
46
+ }.to_h
47
+ end
48
+
49
+ # Commands at the top level ('') and inside each group ('worktree'), as [name, description]
50
+ def children(group = '')
51
+ klass = group.empty? ? @cli : @cli.subcommand_classes.fetch(group)
52
+ visible(klass).map { |name, command| [name, command.description.to_s] }
53
+ end
54
+
55
+ # Every command that runs something, top level and in groups, by its path ('worktree add')
56
+ def commands
57
+ top = visible(@cli).except(*groups).map { |name, cmd| build(name, cmd) }
58
+ top + groups.flat_map do |group|
59
+ visible(@cli.subcommand_classes.fetch(group)).map do |name, cmd|
60
+ build("#{group} #{name}", cmd)
61
+ end
62
+ end
63
+ end
64
+
65
+ def global_options
66
+ @cli.class_options.values.map { |option| option_record(option) }
67
+ end
68
+
69
+ # Switches whose next word is their value, so it is not read as a command or an argument
70
+ def value_switches
71
+ options = global_options + commands.flat_map(&:options)
72
+ options.select(&:takes_value).flat_map(&:switches).uniq
73
+ end
74
+
75
+ private
76
+
77
+ def visible(klass)
78
+ klass.all_commands.reject { |name, command| HIDDEN.include?(name) || command.hidden? }
79
+ end
80
+
81
+ def build(path, command)
82
+ words = command.usage.split.drop(1)
83
+ Command.new(path:, description: command.description.to_s,
84
+ options: command.options.values.map { |option| option_record(option) },
85
+ arguments: words.map { |word| ARGUMENTS[word.delete('[].')] },
86
+ repeats: words.last.to_s.end_with?('...', '...]'))
87
+ end
88
+
89
+ def option_record(option)
90
+ Option.new(switches: switches(option), description: option.description.to_s,
91
+ takes_value: !option.boolean?, optional: !option.lazy_default.nil?,
92
+ value: option.enum || BANNERS[option.banner])
93
+ end
94
+
95
+ # A boolean option that defaults to true is also turned off with --no-<name>
96
+ def switches(option)
97
+ if option.boolean? && option.default == true
98
+ negated = "--no-#{option.switch_name.delete_prefix('--')}"
99
+ end
100
+ [option.switch_name, *option.aliases, negated].compact
101
+ end
102
+ end
103
+ end
@@ -4,27 +4,23 @@ require 'yaml'
4
4
 
5
5
  module Gitflash
6
6
  module Configuration
7
+ # Help texts from command_descriptions.yml, read once and frozen.
8
+ # Thor classes extend it and call `description(:branches).short` in their `desc` lines.
7
9
  module Descriptions
8
- def descriptions
9
- @descriptions ||= load_descriptions
10
- end
10
+ FILE = File.expand_path('../../command_descriptions.yml', __dir__)
11
11
 
12
- private
12
+ # `short` is nil for an entry that only overrides the long help
13
+ Description = Data.define(:short, :long)
13
14
 
14
- def load_descriptions
15
- file = File.expand_path('../../command_descriptions.yml', __dir__)
16
- transform_to_struct(YAML.load_file(file))
15
+ def self.all
16
+ @all ||= YAML.load_file(FILE).to_h { |name, texts|
17
+ [name.to_sym, Description.new(short: texts['short']&.freeze, long: texts['long']&.freeze)]
18
+ }.freeze
17
19
  end
18
20
 
19
- def transform_to_struct(data)
20
- return data unless data.is_a? Hash
21
-
22
- keys = data.keys.map(&:to_sym)
23
- Struct.new(*keys).new(*data.values).tap do |st|
24
- keys.each do |method|
25
- st.public_send("#{method}=", transform_to_struct(st.public_send(method)))
26
- end
27
- end
21
+ # Raises KeyError naming the entry when command_descriptions.yml has none
22
+ def description(name)
23
+ Descriptions.all.fetch(name)
28
24
  end
29
25
  end
30
26
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gitflash
4
- VERSION = '0.8.0.beta2'
4
+ VERSION = '0.9.0.beta1'
5
5
  end
@@ -105,7 +105,7 @@ module Gitflash
105
105
  end
106
106
 
107
107
  desc 'remove [WORKTREE...]', 'Remove worktrees (paths or branch names), saving a snapshot first'
108
- long_desc descriptions.worktree_remove.long
108
+ long_desc description(:worktree_remove).long
109
109
  option :force, type: :boolean, default: false,
110
110
  desc: 'Remove locked worktrees and worktrees with uncommitted changes'
111
111
  def remove(*worktrees)
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitflash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0.beta2
4
+ version: 0.9.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kleanthis Mitsioulis
8
+ autorequire:
8
9
  bindir: bin
9
10
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
11
+ date: 2026-11-22 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: mcp
@@ -124,6 +125,11 @@ files:
124
125
  - lib/gitflash/commands/worktree_remove.rb
125
126
  - lib/gitflash/commands/worktree_unlock.rb
126
127
  - lib/gitflash/commit.rb
128
+ - lib/gitflash/completion.rb
129
+ - lib/gitflash/completion/bash.erb
130
+ - lib/gitflash/completion/fish.erb
131
+ - lib/gitflash/completion/view.rb
132
+ - lib/gitflash/completion/zsh.erb
127
133
  - lib/gitflash/config.rb
128
134
  - lib/gitflash/config_keys.rb
129
135
  - lib/gitflash/configuration.rb
@@ -189,6 +195,7 @@ metadata:
189
195
  documentation_uri: https://github.com/Kleanthismits/git_flash#readme
190
196
  bug_tracker_uri: https://github.com/Kleanthismits/git_flash/issues
191
197
  rubygems_mfa_required: 'true'
198
+ post_install_message:
192
199
  rdoc_options: []
193
200
  require_paths:
194
201
  - lib
@@ -203,7 +210,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
203
210
  - !ruby/object:Gem::Version
204
211
  version: '0'
205
212
  requirements: []
206
- rubygems_version: 4.0.23
213
+ rubygems_version: 3.5.22
214
+ signing_key:
207
215
  specification_version: 4
208
216
  summary: Safety net and cleanup for git repos that AI coding agents work in
209
217
  test_files: []