Compare commits

..

No commits in common. "716d5634c359d7829782837902ab254c79a92a18" and "b3f6b2b80811c3cd5d469c230e7eaefa9cc37ff4" have entirely different histories.

4 changed files with 55 additions and 122 deletions

View File

@ -1,5 +1,5 @@
name: git-ahead-check
version: 0.3.0
version: 0.1.0
authors:
- Alexander Popov <iiiypuk@fastmail.fm>
@ -13,6 +13,3 @@ targets:
git-ahead-check:
main: src/git-ahead-check.cr
dependencies:
tallboy:
github: epoch/tallboy

View File

@ -1,31 +0,0 @@
require "option_parser"
begin
OptionParser.parse do |parser|
parser.banner = "The very simple password manager for humans\n"
parser.on "-h", "--help", "Show help" do
puts parser
exit(0)
end
parser.on "-s", "Short output" do
ARGV_VARS.short = true
end
parser.on "-r RENDER", "Table render (unicode, ascii, markdown)" do |render|
ARGV_VARS.render = render
end
parser.on "-d", "Daemon" do
ARGV_VARS.daemon = true
end
parser.on "-v", "Show version" do
puts VERSION
exit(0)
end
end
rescue ex
puts ex.message, ""
end

View File

@ -1,40 +0,0 @@
VERSION = {{ `shards version "#{__DIR__}"`.chomp.stringify }}
class CONFIG
property daemon : Bool
property short : Bool
def initialize(daemon : Bool, short : Bool)
@daemon = daemon
@short = short
@render = "unicode"
end
def daemon=(daemon : Bool)
@daemon = daemon
end
def short=(short : Bool)
@short = short
end
def render=(render : String)
@render = render
end
def daemon
return @daemon
end
def short
return @short
end
def render
return @render
end
end
ARGV_VARS = CONFIG.new(false, false)
CONFIG_PATH = "#{ENV["HOME"]}/.config/emilecok/git-ahead-check"

View File

@ -1,58 +1,39 @@
require "colorize"
require "tallboy"
require "option_parser"
require "./conf.cr"
require "./argv.cr"
VERSION = {{ `shards version "#{__DIR__}"`.chomp.stringify }}
short_output = false
if File.exists?(CONFIG_PATH)
repository_dirs = File.read_lines(CONFIG_PATH)
begin
OptionParser.parse do |parser|
parser.banner = "The very simple password manager for humans\n"
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
repos_table = Tallboy.table do
header [
"Ahead".colorize.mode(:bold),
"Repo name".colorize.mode(:bold),
if !ARGV_VARS.short
"Repo path".colorize.mode(:bold)
end,
]
repositoryes.each { |repo|
row [
repo[:ahead].colorize(:red).mode(:bold),
repo[:name].colorize(:yellow),
if !ARGV_VARS.short
repo[:path].sub("$HOME", ENV["HOME"]).colorize(:light_magenta)
end,
]
}
parser.on "-h", "--help", "Show help" do
puts parser
exit(0)
end
if ARGV_VARS.render == "ascii"
puts repos_table.render(:ascii)
elsif ARGV_VARS.render == "markdown"
puts repos_table.render(:markdown)
else
puts repos_table.render(:unicode)
parser.on "-s", "Short output" do
short_output = true
end
parser.on "-v", "Show version" do
puts VERSION
exit(0)
end
end
rescue ex
puts ex.message, ""
end
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, short_output) }
else
Dir.mkdir_p(File.dirname(CONFIG_PATH))
File.new(CONFIG_PATH, "w")
@ -60,3 +41,29 @@ else
print File.dirname(CONFIG_PATH)
puts " directory created.\n"
end
def check_repo(repo_path : String, show_path)
if !Dir.exists?(repo_path.sub("$HOME", ENV["HOME"]))
return 0
end
if !Dir.exists?("#{repo_path}/.git")
return 0
end
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?
print "* #{ahead_count}\t".colorize(:red).mode(:bold)
print repo_name.colorize(:yellow)
if !show_path
print " ["
print repo_path.colorize(:light_magenta)
puts "]"
else
puts
end
end
end