mirror of
https://github.com/danbee/dotfiles-local
synced 2025-03-04 08:49:07 +00:00
Add tools command
This commit is contained in:
parent
1889fb432c
commit
53d0bce1cf
6
bin/tools
Executable file
6
bin/tools
Executable file
@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
require_relative "tools_lib/tools"
|
||||
|
||||
tools = Tools.new
|
||||
tools.list_tools
|
||||
5
bin/tools_lib/empty_file.rb
Normal file
5
bin/tools_lib/empty_file.rb
Normal file
@ -0,0 +1,5 @@
|
||||
class EmptyFile
|
||||
def lines
|
||||
[]
|
||||
end
|
||||
end
|
||||
15
bin/tools_lib/tool_icons.rb
Normal file
15
bin/tools_lib/tool_icons.rb
Normal file
@ -0,0 +1,15 @@
|
||||
module ToolIcons
|
||||
TOOL_ICONS = {
|
||||
"ruby" => "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAGFBMVEVHcEy/Qzm8QDW+Qje8QDW9QTa9QDa8QTZmAPnqAAAAB3RSTlMAJvFL33C/T+QPRAAAAF1JREFUeNrN0DkKwDAQBEHd/v+PDcIwhgLFmrQ62S03rbbnt1bPblFHzGI7GxWnwC10i7hru1hCtvgAt1LgKfRevvUU+KGIp9BTHJwCp8Apppoi7iZOgVPgFPgFewH6bQsqZElHlwAAAABJRU5ErkJggg==",
|
||||
|
||||
"elixir" => "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAGFBMVEVHcEx/Z916Ytl6Ydl6Ytp8ZNp7Ytp6Ytmj2hGuAAAAB3RSTlMAGeHBoT54bVkLIwAAAH1JREFUeNrNk0sOAzEMQuMv979x5V0njFGXfVsscIxybiqPwhKh9HJAOSSgBiwwxKo7MLjUh1L6vsTkK4vGF24cgAdhfIAnXtJgiNo24BxO4F0dr7QYuI6Ohd8dAq+EeuaQ66G4tNYGvAV3asG6LjSN/0RcXTLW4YBn2/kvPr/BC1y3ed4EAAAAAElFTkSuQmCC",
|
||||
|
||||
"python" => "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAMFBMVEVHcEyQo5pGjM5GispFisxEisxEiszWpirWpirYpyvWpirbqSzOpTNmkavXqCvYqitbyuh6AAAAEHRSTlMACEXg//f84f9c9B7Aw1Mxvf5QxwAAAIZJREFUeNq909EKhDAMRNG2aZvYrfr/f7srioNhloKg59ULGUTDy+IhcEnyQRINJJ8KDWoGeqXcDLCfncB+R81MJ78fqtpPi9jvqW0+mOfUUSCNB3VXpBsCbJi1GZCgG9BA/wd5FAgP8KKSbNt90JZwpQYr+/DUXX8g6G6/F1c9n0+jH+ddX6eCCwZdgedvAAAAAElFTkSuQmCC",
|
||||
|
||||
"nodejs" => "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAgMAAAAOFJJnAAAADFBMVEVHcExvuztvuDlvuTijLMEbAAAAA3RSTlMAQMCRa0lrAAAANklEQVR4AWMgErBNgDLyf0IF/v+HCOX///8TKgAUgghAhP6DAR0YcEvhzoA7DOFUhOMR3iEMAH4wa5VMF4BbAAAAAElFTkSuQmCC",
|
||||
}.freeze
|
||||
|
||||
def tool_icon(tool)
|
||||
"\e]1337;File=inline=1;height=1:#{TOOL_ICONS[tool]}\a"
|
||||
end
|
||||
end
|
||||
34
bin/tools_lib/tools.rb
Normal file
34
bin/tools_lib/tools.rb
Normal file
@ -0,0 +1,34 @@
|
||||
require_relative "tools_file"
|
||||
require_relative "tool_icons"
|
||||
|
||||
class Tools
|
||||
include ToolIcons
|
||||
|
||||
attr_reader :tools
|
||||
|
||||
def initialize
|
||||
@tools = ToolsFile.new.tools
|
||||
end
|
||||
|
||||
def list_tools
|
||||
tools.each do |tool, version|
|
||||
if available_tools.include? tool
|
||||
puts "#{tool_icon(tool)}#{tool.ljust(max_length)} #{version}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def max_length
|
||||
@max_length ||= installed_tools.max do |a, b|
|
||||
a.length <=> b.length
|
||||
end.length
|
||||
end
|
||||
|
||||
def installed_tools
|
||||
tools.keys & available_tools
|
||||
end
|
||||
|
||||
def available_tools
|
||||
TOOL_ICONS.keys
|
||||
end
|
||||
end
|
||||
24
bin/tools_lib/tools_file.rb
Normal file
24
bin/tools_lib/tools_file.rb
Normal file
@ -0,0 +1,24 @@
|
||||
require_relative "empty_file"
|
||||
|
||||
class ToolsFile
|
||||
def initialize
|
||||
end
|
||||
|
||||
def tools
|
||||
@tools ||= format_tools
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def format_tools
|
||||
Hash[tools_file.lines.map do |tool|
|
||||
tool.split
|
||||
end]
|
||||
end
|
||||
|
||||
def tools_file
|
||||
File.read(".tool-versions")
|
||||
rescue
|
||||
EmptyFile.new
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue
Block a user