require "colorize" require "tallboy" require "./conf.cr" require "./argv.cr" if File.exists?(CONFIG_PATH) repository_dirs = File.read_lines(CONFIG_PATH) repositoryes = Array({name: String, path: String, ahead: Int32}).new repository_dirs.each { |repo_path| if Dir.exists?("#{repo_path}/.git".sub("$HOME", ENV["HOME"])) repo_name = repo_path.split("/")[-1] ahead_count = `git -C #{repo_path} status | grep -i "Your branch" | grep -Eo "[0-9]"`.chomp if !ahead_count.empty? repositoryes << {name: repo_name, path: repo_path, ahead: ahead_count.to_i} end end } if ARGV_VARS.daemon puts "Daemon mode" sleep(600) `notify-send --app-name=git-ahead-check --icon=flag-red --urgency=normal GIT-AHEAD "Unpushed repos: #{repositoryes.size}"` else repositoryes.each { |repo| print "* #{repo[:ahead]}\t".colorize(:red).mode(:bold) print repo[:name].colorize(:yellow) if !ARGV_VARS.short print " [" print repo[:path].colorize(:light_magenta) print "]" end } puts end else Dir.mkdir_p(File.dirname(CONFIG_PATH)) File.new(CONFIG_PATH, "w") print File.dirname(CONFIG_PATH) puts " directory created.\n" end