Module: Githelp

Defined in:
lib/githelp/tags.rb,
lib/githelp.rb,
lib/githelp/args.rb,
lib/githelp/params.rb,
lib/githelp/changes.rb,
lib/githelp/numbers.rb,
lib/githelp/version.rb,
lib/githelp/branches.rb,
lib/githelp/glossary.rb,
lib/githelp/patterns.rb,
lib/githelp/git_check.rb

Overview

存在するタグのリストを作る

Constant Summary collapse

VERSION =
"0.1.2"

Instance Method Summary collapse

Instance Method Details

#args(argv = ARGV) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/githelp/args.rb', line 5

def args(argv=ARGV)
  a = []
  argv.each { |arg|
    if arg =~ /^(\d+)([^\d]+)?$/ then
      a << $1
      a << $2 if $2.to_s != ''
    else
      a << arg.sub(/^['"]/,'').sub(/['"]$/,'').sub('「','').sub('」','')
    end
  }
  a.length > 0 ? a : ['']
end

#branchObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/githelp/branches.rb', line 24

def branch
  b = git_branch
  if b
    b.split(/\n/).map { |line|
      line.chomp!
      if line =~ /^\* (.*)$/ then
        return $1
      end
    }
    ''
  else
    ''
  end
end

#branchesObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/githelp/branches.rb', line 12

def branches
  b = git_branch
  if b
    b.split(/\n/).map { |line|
      line.chomp!
      line.sub(/^../,'')
    }
  else
    [ '##BRANCH##' ]
  end
end

#changed(since) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/githelp/changes.rb', line 12

def changed(since)
  files(true).find_all { |file|
    wc = git_log_wc(since,file)
    if wc
      wc !~ /  0  /
    else
      false
    end
  }
end

#git_branchObject



4
5
6
7
8
9
10
# File 'lib/githelp/branches.rb', line 4

def git_branch
  begin
    `git branch`
  rescue
    nil
  end
end

#git_checkObject



4
5
6
7
8
9
10
11
# File 'lib/githelp/git_check.rb', line 4

def git_check
  res = nil
  begin
    res = `git log`
  rescue
  end
  res != ''
end

#git_log_wc(since, file) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/githelp/changes.rb', line 4

def git_log_wc(since,file)
  begin
    `git log --oneline --since='#{since}' #{file} | wc`
  rescue
    nil
  end
end

#githelp(pat) ⇒ Object

パタンを指定してコマンド候補リストを得る



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/githelp.rb', line 21

def githelp(pat)

  datadir = File.expand_path('../../data', __FILE__)
  # $LOAD_PATH.unshift File.expand_path('../data', __FILE__)

  entries = []
  Dir.open(datadir).each { |file|
    next unless File.file?("#{datadir}/#{file}")
    next if file !~ /\.rb$/
    # require file
    a = eval File.read("#{datadir}/#{file}")
    entries += a if a
  }

  g = ExpandRuby::Generator.new # re_expandのジェネレータ
  entries.each { |entry|
    g.add entry[0], entry[1] if entry
  }
  res = g.generate pat
  listed = {}
  res[0].find_all { |a| # 0 ambig
    if listed[a[1]]
      false
    else
      listed[a[1]] = true
    end
  }
end

#numbers(argv = ARGV) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/githelp/numbers.rb', line 5

def numbers(argv=ARGV)
  a = []
  argv.each { |arg|
    if arg =~ /^(\d+)[^\d]*$/ then
      a << $1
    end
  }
  a.length > 0 ? a : ['1']
end

#params(argv = ARGV) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/githelp/params.rb', line 5

def params(argv=ARGV)
  a = []
  argv.each { |arg|
    if arg =~ /^(\d+)[^\d]*$/ then
    # a << $1
    elsif arg =~ /^'.*'$/ || arg =~ /^".*"$/ || arg =~ /^「.*」$/
      a << arg.sub(/^['"]/,'').sub(/['"]$/,'').sub('「','').sub('」','')
    end
  }
  a.length > 0 ? a : ['##DUMMYNAME##']
end

#patterns(argv = ARGV) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/githelp/patterns.rb', line 5

def patterns(argv=ARGV)
  a = []
  argv.each { |arg|
    if arg =~ /^(\d+)[^\d]*$/ then
    # a << $1
    elsif arg =~ /^'.*'$/ || arg =~ /^".*"$/ || arg =~ /^「.*」$/
    # a << arg.sub(/^['"]/,'').sub(/['"]$/,'').sub('「','').sub('」','')
    else
      a << arg
    end
  }
  a.length > 0 ? a : ['##PATTERN##']
end

#tags(force = false, argv = ARGV) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/githelp/tags.rb', line 7

def tags(force=false,argv=ARGV)
  #
  # 引数の中にタグ名とマッチするものがあればタグリストを取得
  #
  list = begin
           `git tag`.split(/\n/)
         rescue
           []
         end
  matched = false
  list.each { |tag|
    args.each { |arg|
      matched = true if tag.match arg
    }
  }
  if (argv.length > 0 && matched) || force
    list
  else
    ['##DUMMYTAG##']
  end
end

#unchanged(since) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/githelp/changes.rb', line 23

def unchanged(since)
  files(true).find_all { |file|
    wc = git_log_wc(since,file)
    if wc
      wc =~ /  0  /
    else
      false
    end
  }
end