git-ahead-check/src/git-ahead-check.cr

39 lines
888 B
Crystal
Raw Normal View History

2022-08-11 01:37:24 +03:00
require "colorize"
2022-08-13 12:24:27 +03:00
CONFIG_PATH = "#{ENV["HOME"]}/.config/emilecok/git-ahead-check"
if File.exists?(CONFIG_PATH)
a = File.read_lines(CONFIG_PATH)
repos_dirs = File.read_lines(CONFIG_PATH)
repos_dirs.each { |x| check_repo(x) }
else
Dir.mkdir_p(File.dirname(CONFIG_PATH))
File.new(CONFIG_PATH, "w")
print File.dirname(CONFIG_PATH)
puts " directory created.\n"
end
2022-08-11 01:37:24 +03:00
def check_repo(repo_path : String)
2022-08-13 12:24:27 +03:00
if !Dir.exists?(repo_path.sub("$HOME", ENV["HOME"]))
return 0
end
2022-08-13 12:37:44 +03:00
if !Dir.exists?("#{repo_path}/.git")
return 0
end
2022-08-11 01:37:24 +03:00
repo_name = repo_path.split("/")[-1]
2022-08-13 11:39:51 +03:00
ahead_count = `git -C #{repo_path} status | grep -i "Your branch" | grep -Eo "[0-9]"`.chomp
2022-08-11 01:37:24 +03:00
if !ahead_count.empty?
2022-08-13 11:39:51 +03:00
print "* #{ahead_count}\t".colorize(:red).mode(:bold)
2022-08-11 01:37:24 +03:00
print repo_name.colorize(:yellow)
2022-08-13 11:39:51 +03:00
print " ["
print repo_path.colorize(:light_magenta)
puts "]"
2022-08-11 01:37:24 +03:00
end
end