Last active
November 2, 2025 01:50
-
-
Save apainintheneck/bc954a82323242afe56c19381f3659ec to your computer and use it in GitHub Desktop.
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 ruby | |
| # frozen_string_literal: true | |
| # Usage: | |
| # $ git-last-modified | |
| # $ git-last-modified '*.rb' | |
| require "bundler/inline" | |
| require "open3" | |
| require "shellwords" | |
| gemfile do | |
| source "https://rubygems.org" | |
| gem "async", "~> 2.34" | |
| end | |
| PATHSPEC = ARGV.first.freeze | |
| def current_files | |
| command = %w[git ls-files -z --exclude-standard] | |
| command << "--" << PATHSPEC if PATHSPEC | |
| last_stdout, _wait_threads = Open3.pipeline_r(command) | |
| last_stdout.each_line("\0", chomp: true).lazy.each do |file| | |
| yield file | |
| end | |
| ensure | |
| last_stdout&.close | |
| end | |
| def last_modified(file) | |
| command = ["git", "log", "-1", "--format=%as", "--", file] | |
| `#{Shellwords.join(command)}`.strip | |
| end | |
| Barrier do |barrier| | |
| current_files do |file| | |
| barrier.async do | |
| date = last_modified(file) | |
| puts "#{date} #{file}" | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment