Skip to content

Commit b1f7252

Browse files
authored
Merge pull request #12 from Zuehlke/feature/configure-git-ps1-prompt
Setup git PS1 shell prompt via ~/.bashrc.d mechanism
2 parents e6ddf7d + 41dabcf commit b1f7252

4 files changed

Lines changed: 34 additions & 0 deletions

File tree

roles/git/files/git-ps1.bash

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
export PS1='`if [ $? = 0 ]; then echo "\[\e[32m\] ✔ "; else echo "\[\e[31m\] ✘ "; fi`\[\e[00;37m\]\u\[\e[01;37m\]@\[\e[00;37m\]\h\[\e[01;37m\]:\[\e[01;34m\]\w\[\e[00;34m\] `[[ $(git status 2> /dev/null | head -n4 | tail -n1) != "Changes to be committed:" ]] && echo "\[\e[01;31m\]" || echo "\[\e[01;33m\]"``[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit, working tree clean" ]] || echo "\[\e[01;32m\]"`$(__git_ps1 "(%s)")`echo "\[\e[00m\]"`\$ '

roles/git/tasks/main.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
3+
- name: Make sure Git is installed
4+
apt:
5+
name: git
6+
state: present
7+
8+
- name: Set up the PS1 shell prompt for Git
9+
copy:
10+
src: git-ps1.bash
11+
dest: ~/.bashrc.d/git-ps1.bash
12+
become: yes
13+
become_user: "{{ ansible_env.SUDO_USER }}"

site.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313
- { role: ansible-lint, tags: "ansible-lint" }
1414
- { role: testinfra, tags: "testinfra" }
1515
- { role: bashrc_d, tags: "bashrc_d" }
16+
- { role: git, tags: "git" }

spec/test_git.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import os
2+
3+
def test_git_package_is_installed_(host):
4+
assert host.package('git').is_installed
5+
6+
def test_git_command_is_found_(host):
7+
assert host.run('which git').rc is 0
8+
9+
def test_git_version_command_reports_version_2_x_(host):
10+
assert 'git version 2.' in host.run('git --version').stdout
11+
12+
def test_git_shell_prompt_is_configured_in_bashrc_d_(host):
13+
git_ps1 = host.file(f"{os.environ['HOME']}/.bashrc.d/git-ps1.bash")
14+
assert git_ps1.exists
15+
assert git_ps1.contains('export PS1=')
16+
17+
def test_git_shell_prompt_is_set_in_the_environment_(host):
18+
assert '__git_ps1' in host.run('bash -i -c "env | grep ^PS1=; exit \\$?"').stdout

0 commit comments

Comments
 (0)