Skip to content

Commit e6ddf7d

Browse files
authored
Merge pull request #11 from Zuehlke/feature/add-bashrc-d
Add ~/.bashrc.d directory and load the .bash files therein
2 parents 474520f + 100a52f commit e6ddf7d

4 files changed

Lines changed: 36 additions & 1 deletion

File tree

roles/bashrc_d/tasks/main.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
- name: create ~/.bashrc.d directory
3+
file:
4+
path: ~/.bashrc.d
5+
state: directory
6+
mode: 0755
7+
become: yes
8+
become_user: "{{ ansible_env.SUDO_USER }}"
9+
10+
- name: Setup ~/.bashrc to load .bash files from ~/.bashrc.d
11+
blockinfile:
12+
dest: ~/.bashrc
13+
block: |
14+
# Load *.bash files from ~/.bashrc.d
15+
for config in "$HOME"/.bashrc.d/*.bash ; do
16+
. "$config"
17+
done
18+
unset -v config
19+
become: yes
20+
become_user: "{{ ansible_env.SUDO_USER }}"

roles/readme/tasks/main.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
path: ~/Desktop
1212
state: directory
1313
mode: 0755
14-
1514
become: yes
1615
become_user: "{{ ansible_env.SUDO_USER }}"
1716

site.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212
- { role: readme, tags: "readme" }
1313
- { role: ansible-lint, tags: "ansible-lint" }
1414
- { role: testinfra, tags: "testinfra" }
15+
- { role: bashrc_d, tags: "bashrc_d" }

spec/test_bashrc_d.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import textwrap
2+
import os
3+
4+
def test_bashrc_loads_files_from_bashrc_d_(host):
5+
bashrc = host.file(f"{os.environ['HOME']}/.bashrc")
6+
snippet = textwrap.dedent(
7+
'''
8+
# Load *.bash files from ~/.bashrc.d
9+
for config in "$HOME"/.bashrc.d/*.bash ; do
10+
. "$config"
11+
done
12+
unset -v config
13+
'''
14+
)
15+
assert snippet in bashrc.content_string

0 commit comments

Comments
 (0)