Skip to content

Instantly share code, notes, and snippets.

@havenwood
Created April 24, 2018 06:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save havenwood/339039f9266c401050d830b030b258b5 to your computer and use it in GitHub Desktop.
Save havenwood/339039f9266c401050d830b030b258b5 to your computer and use it in GitHub Desktop.
Sort your directly-installed homebrew packages by most recently run executable.
# frozen_string_literal: true
require 'date'
leaves = `brew leaves`.lines chomp: true
recent_bins = leaves.map do |leaf|
bins = Dir[File.join `brew --cellar #{leaf}`.chomp, '*', 'bin', '*']
recently_used = bins.max_by { |bin| File.atime bin }
next unless recently_used
[leaf, File.basename(recently_used), File.atime(recently_used)]
end.compact
recent_bins_sorted = recent_bins.sort_by { |_, _, time| time }.reverse
recent_bins_sorted.each do |leaf, bin, time|
puts "#{leaf}: `#{bin}` last run #{time.to_date}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment