Created
April 24, 2018 06:14
-
-
Save havenwood/339039f9266c401050d830b030b258b5 to your computer and use it in GitHub Desktop.
Sort your directly-installed homebrew packages by most recently run executable.
This file contains 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
# 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