From: Ismaƫl Bouya Date: Sat, 3 Nov 2018 23:37:08 +0000 (+0100) Subject: Add a temporary bashrc when updating pam_environment X-Git-Tag: v1.0~41 X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FConfig%2FAnsible.git;a=commitdiff_plain;h=c235f9bea368316f1c1a441ebf6877e05e7df21c Add a temporary bashrc when updating pam_environment --- diff --git a/roles/init/tasks/main.yml b/roles/init/tasks/main.yml index d3f0f6b..1baec91 100644 --- a/roles/init/tasks/main.yml +++ b/roles/init/tasks/main.yml @@ -7,6 +7,24 @@ template: src: pam_environment.j2 dest: $XDG_CONFIG_HOME/pam_environment +- name: Remove old lines in bashrc_temp + lineinfile: + line: "{{ ('unset ' ~ item | regex_replace('=.*')) if item != '' and item.0 != '#' else '' }}" + dest: $HOME/.bashrc_temp + insertafter: EOF + create: true + state: present + loop: "{{ pam_environment.diff.0.before.split('\n')|difference(pam_environment.diff.0.after.split('\n')) | regex_replace('[\\\\t]*DEFAULT') }}" + when: pam_environment.changed +- name: Add new lines in bashrc_temp + lineinfile: + line: "{{ ('export ' ~ item) if item != '' and item.0 != '#' else '' }}" + dest: $HOME/.bashrc_temp + insertafter: EOF + create: true + state: present + loop: "{{ pam_environment.diff.0.after.split('\n')|difference(pam_environment.diff.0.before.split('\n')) | regex_replace('[\\\\t]*DEFAULT', '') }}" + when: pam_environment.changed - name: Signal the change when: pam_environment.changed debug: diff --git a/roles/shell/bash/templates/bash_profile.j2 b/roles/shell/bash/templates/bash_profile.j2 index 06210fa..9b9e86c 100644 --- a/roles/shell/bash/templates/bash_profile.j2 +++ b/roles/shell/bash/templates/bash_profile.j2 @@ -4,6 +4,7 @@ {% if "graphical_vt" in features.get(profile, []) %} if [[ ! $DISPLAY && $XDG_VTNR -eq 1 ]]; then + [[ -f "$HOME/.bashrc_temp" ]] && rm -f $HOME/.bashrc_temp exec startx $XDG_CONFIG_HOME/xinitrc > $XDG_STATE_HOME/xsession_errors 2>&1 fi {% endif %} diff --git a/roles/shell/bash/templates/bashrc.j2 b/roles/shell/bash/templates/bashrc.j2 index 2285d2b..99ed55f 100644 --- a/roles/shell/bash/templates/bashrc.j2 +++ b/roles/shell/bash/templates/bashrc.j2 @@ -2,6 +2,8 @@ # ~/.bashrc # +[[ -f "$HOME/.bashrc_temp" ]] && . $HOME/.bashrc_temp + if [ -n "$HOME/.local/bin" ]; then PATH="$HOME/.local/bin:$PATH" fi