Team spirit

alternate text

Marian lubi pracę zespołową i czuje team spirit. Dlatego korzysta z git i nie dzieli się kodem przy użyciu pendrive, ale że lubi kolorki w terminalu dlatego ma używa git-prompt.

Rola: Git

roles/
   git/
     tasks/
         main.yml
     files/
         git-prompt-colors.sh
     templates/
         gitconfig.j2

Templates

[push]
	default = simple

[alias]
    # COMMON SHORTHANDS

    ap = add --patch   # choose which hunks to add - very useful
    au = add --update   # stage only changes in tracked files

    br = branch
    co = checkout

    # see what you're commiting when editing the commit message
    ci = commit --verbose

    d = diff --color=always
    wd = diff --color=always --word-diff=color   # mnemonic: Word-Diff

    g3 = grep --color=always --line-number --context 3

    # unlike plain `pull`, this won't attempt a merge that may result in conflicts
    pl = pull --ff-only

    rb = rebase
    rbo = rebase --onto   # quite useful, see examples in 'git help rebase'
    rbi = rebase --interactive

    rs = reset
    rs1 = reset HEAD~1   # "soft undo" - remove last commit, but keep its changes

    s = status --short   # see also --branch option
    st = status


    # PRETTY LOGS

    # compact log with branch names etc.
    ls = !git log --color=always --decorate --graph --date=relative \
    --format=tformat:'%C(auto)%h%C(reset) -%C(auto)%d%C(reset) %s %C(dim)- %an, %ad%C(reset)'

    # log All local and remote branches
    la = !git ls HEAD --branches --remotes

    # log both HEAD and its Upstream (if present)
    lu = !git ls HEAD `git for-each-ref --format='%(upstream:short)' HEAD $(git symbolic-ref --quiet HEAD)`

    # Long format - full commit message and summary of changes
    ll = !git log --color=always --decorate --graph --stat-graph-width=30 --stat-count=30


[color]
    ui = auto

[color "status"]
    # use different color than untracked and unmerged paths have
    changed = yellow

[color "grep"]
    # similar to standalone grep
    filename = magenta

[core]
    # display non-ASCII characters (e.g. Polish) instead of quoting them
    quotepath = false
    # restore default pager behavior (needed because we manually set $LESS)
    pager = "less -FRX"

[diff]
    # detect renamed files and show only actual differences between them
    renames = copies

[merge]
    # in case of merge conflict also show how common ancestor looked like
    conflictstyle = diff3

[pager]
    # don't wrap lines in log and blame output (needed since git 2.1)
    log = "less -S"
    blame = "less -S"

[push]
    # git < 2.0 pushed all matching branches by default (could be dangerous)
    default = simple

[rebase]
    # automatically process "fixup!" commits when rebasing interactively
    autosquash = true
[user]
	name = {{ git_name }}
	email = {{ git_email }}

Files

# This is the custom theme template for gitprompt.sh

# These are the defaults from the "Default" theme
# You just need to override what you want to have changed
override_git_prompt_colors() {
  GIT_PROMPT_THEME_NAME="Custom"

  # Time12a="\$(date +%H:%M)"
  # PathShort="\w";

  ## These are the color definitions used by gitprompt.sh
   GIT_PROMPT_PREFIX="${DimWhite}["                # start of the git info string
   GIT_PROMPT_SUFFIX="${DimWhite}]"                 # the end of the git info string
   GIT_PROMPT_SEPARATOR="${DimWhite}|"              # separates each item

   GIT_PROMPT_BRANCH="${Cyan}"        # the git branch that is active in the current directory
   GIT_PROMPT_STAGED="${Red}:"           # the number of staged files/directories
   GIT_PROMPT_CONFLICTS="${Red}✖ "       # the number of files in conflict
   GIT_PROMPT_CHANGED="${Blue}✚ "        # the number of changed files

   GIT_PROMPT_REMOTE=" "                 # the remote branch name (if any) and the symbols for ahead and behind
   GIT_PROMPT_UNTRACKED="${Cyan}…"       # the number of untracked files/dirs
   GIT_PROMPT_STASHED="${BoldBlue}⚑ "    # the number of stashed files/dir
   GIT_PROMPT_CLEAN="${BoldGreen}✔"      # a colored flag indicating a "clean" repo

  ## For the command indicator, the placeholder _LAST_COMMAND_STATE_
  ## will be replaced with the exit code of the last command
  ## e.g.
  # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ "    # indicator if the last command returned with an exit code of 0
  # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ "    # indicator if the last command returned with an exit code of other than 0

   GIT_PROMPT_COMMAND_OK="${Green}✔"    # indicator if the last command returned with an exit code of 0
   GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_"    # indicator if the last command returned with an exit code of other than 0

  ## template for displaying the current virtual environment
  ## use the placeholder _VIRTUALENV_ will be replaced with
  ## the name of the current virtual environment (currently CONDA and VIRTUAL_ENV)
   GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) "

  # template for displaying the current remote tracking branch
  # use the placeholder _UPSTREAM_ will be replaced with
  # the name of the current remote tracking branch
  # GIT_PROMPT_UPSTREAM=" {${Blue}_UPSTREAM_${ResetColor}}"

  ## _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL
  # GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}"
  # GIT_PROMPT_START_ROOT="_LAST_COMMAND_INDICATOR_ ${GIT_PROMPT_START_USER}"
  # GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ "
  # GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # "

  ## Please do not add colors to these symbols
   GIT_PROMPT_SYMBOLS_AHEAD="{Green}↑·"             # The symbol for "n versions ahead of origin"
   GIT_PROMPT_SYMBOLS_BEHIND="{DimRed}↓·"            # The symbol for "n versions behind of origin"
   GIT_PROMPT_SYMBOLS_PREHASH=":"            # Written before hash of commit, if no name could be found
   GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="L" # This symbol is written after the branch, if the branch is not tracked
}

reload_git_prompt_colors "Custom"

Tasks

- name: apt git
  apt:
    name: "git"
    state: present

- name: install bash-git-prompt
  git:
    repo: https://github.com/magicmonty/bash-git-prompt.git
    version: master
    dest: '{{ home_path }}/.bash-git-prompt'

- name: copy git-prompt config
  copy:
    src: git-prompt-colors.sh
    dest: '{{ home_path }}/.git-prompt-colors.sh'

- name: add alias pycharm
  lineinfile:
    path: "{{ user_config }}/aliases.sh"
    line: "{{ item }}"
    state: present
  with_items:
    - 'GIT_PROMPT_ONLY_IN_REPO=1'
    - 'source {{ home_path }}/.bash-git-prompt/gitprompt.sh'
    - 'GIT_PROMPT_THEME_FILE={{ home_path }}/.git-prompt-colors.sh'
    - 'GIT_PROMPT_THEME=Custom'

Output

$ ansible-playbook playbooks/git.yml

PLAY [install and configure git] *********************************************************************************************************************

TASK [Gathering Facts] *******************************************************************************************************************************
ok: [localhost]

TASK [git : apt git] *********************************************************************************************************************************
ok: [localhost]

TASK [git : install bash-git-prompt] *****************************************************************************************************************
ok: [localhost]

TASK [git : copy git-prompt config] ******************************************************************************************************************
changed: [localhost]

TASK [git : add alias pycharm] ***********************************************************************************************************************
changed: [localhost] => (item=GIT_PROMPT_ONLY_IN_REPO=1)
changed: [localhost] => (item=source /home/kepok/.bash-git-prompt/gitprompt.sh)
changed: [localhost] => (item=GIT_PROMPT_THEME_FILE=/home/kepok/.git-prompt-colors.sh)
changed: [localhost] => (item=GIT_PROMPT_THEME=Custom)

PLAY RECAP *******************************************************************************************************************************************
localhost                  : ok=5    changed=2    unreachable=0    failed=0

Note

Template pozwala generowanie plików, configów na podstawie zmienny. template