Sha256: bdde1f9702a5dc868d66661ee4e2a4ec0914112d58d6d78a720a699fb8379b12

Contents?: true

Size: 1.08 KB

Versions: 7

Compression:

Stored size: 1.08 KB

Contents

#!/usr/bin/env ruby
# -*- coding: utf-8 -*-

# The methods that get called more than once are memoized.

def git_repo_path
  @git_repo_path ||= `git rev-parse --git-dir 2>/dev/null`.strip
end

def in_git_repo
  !git_repo_path.empty? &&
  git_repo_path != '~' &&
  git_repo_path != "#{ENV['HOME']}/.git"
end

def git_parse_branch
  @git_parse_branch ||= File.read("#{git_repo_path}/HEAD").strip.scan(/(?<=refs\/heads\/).*$/).first
end

def git_head_commit_id
  `git rev-parse --short HEAD 2>/dev/null`.strip
end

def git_cwd_dirty
  " %{\e[90m%}✗%{\e[0m%}" unless git_repo_path == '.' || `git ls-files -m`.strip.empty?
end

def rebasing_etc
  if File.exists?(File.join(git_repo_path, 'BISECT_LOG'))
    "+bisect"
  elsif File.exists?(File.join(git_repo_path, 'MERGE_HEAD'))
    "+merge"
  elsif %w[rebase rebase-apply rebase-merge ../.dotest].any? {|d| File.exists?(File.join(git_repo_path, d)) }
    "+rebase"
  end
end

if in_git_repo
  print " %{$fg[cyan]%}#{git_parse_branch}%{$reset_color_with_bg%}@%{$fg[violet]%}#{git_head_commit_id}%{$reset_color_with_bg%}#{rebasing_etc}#{git_cwd_dirty}"
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
zsh_dots-0.5.7 bin/git_cwd_info
zsh_dots-0.5.6 bin/git_cwd_info
zsh_dots-0.5.5 bin/git_cwd_info
zsh_dots-0.5.4 bin/git_cwd_info
zsh_dots-0.5.3 bin/git_cwd_info
zsh_dots-0.5.1 bin/git_cwd_info
zsh_dots-0.5.0 bin/git_cwd_info