1
0
mirror of https://github.com/danbee/dotfiles-local synced 2025-03-04 08:49:07 +00:00

Use asdf current to get tools

This commit is contained in:
Daniel Barber 2021-12-22 12:44:53 -06:00
parent 72742bd18d
commit 752ed91f74
3 changed files with 22 additions and 14 deletions

View File

@ -1,5 +0,0 @@
class EmptyFile
def lines
[]
end
end

View File

@ -11,13 +11,25 @@ class Tools
end
def list_tools
tools.sort.each do |tool, version|
if available_tools.include? tool
puts "#{tool_icon(tool)}#{tool.ljust(max_length)} #{version}"
tools.sort.each do |tool, meta|
if available_tools.include?(tool)
puts "#{tool_icon(tool)}" \
"#{tool.ljust(max_length)} " \
"#{version(meta)}"
end
end
end
private
def version(meta)
if installed?(meta)
"\e[37m#{meta[:version]}"
else
"\e[31m#{meta[:version]}* (not installed)"
end
end
def max_length
@max_length ||= installed_tools.max_by(&:length).length
end
@ -29,4 +41,8 @@ class Tools
def available_tools
TOOL_ICONS.keys
end
def installed?(meta)
meta[:source].start_with?("/")
end
end

View File

@ -1,5 +1,3 @@
require_relative "empty_file"
class ToolsFile
def initialize
end
@ -12,13 +10,12 @@ class ToolsFile
def format_tools
Hash[tools_file.lines.map do |tool|
tool.split
name, version, source = tool.split
[name, { version: version, source: source }]
end]
end
def tools_file
File.read(".tool-versions")
rescue
EmptyFile.new
`asdf current 2>&1`
end
end