From a19180dfda49b96ff27911a71255ea3a504c4bb1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Isma=C3=ABl=20Bouya?= Date: Tue, 13 Nov 2018 01:01:36 +0100 Subject: [PATCH] Move bashrc temporary file to state dir --- roles/init/tasks/main.yml | 27 +++++++++++----------- roles/shell/bash/templates/bash_profile.j2 | 2 +- roles/shell/bash/templates/bashrc.j2 | 4 +++- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/roles/init/tasks/main.yml b/roles/init/tasks/main.yml index ce56ec4..a52f3cd 100644 --- a/roles/init/tasks/main.yml +++ b/roles/init/tasks/main.yml @@ -1,4 +1,16 @@ --- +- name: Create XDG dirs + file: + path: "{{ item }}" + state: directory + loop: + - "$XDG_CONFIG_HOME" + - "$XDG_STATE_HOME" + - "$XDG_STATE_HOME/bash" + - "$XDG_DATA_HOME" + - "$XDG_CACHE_HOME" + - "$HOME/Desktop" + - "$HOME/Downloads" - name: Get gnupg runtime folder name shell: 'GNUPGHOME=$XDG_CONFIG_HOME/gnupg gpgconf --list-dirs socketdir | sed -e "s@$XDG_RUNTIME_DIR/gnupg/@@"' changed_when: false @@ -12,7 +24,7 @@ - name: Remove old lines in bashrc_temp lineinfile: line: "{{ ('unset ' ~ item | regex_replace('=.*')) if item != '' and item.0 != '#' else '' }}" - dest: $HOME/.bashrc_temp + dest: $XDG_STATE_HOME/bash/bashrc_temp insertafter: EOF create: true state: present @@ -21,7 +33,7 @@ - name: Add new lines in bashrc_temp lineinfile: line: "{{ ('export ' ~ item) if item != '' and item.0 != '#' else '' }}" - dest: $HOME/.bashrc_temp + dest: $XDG_STATE_HOME/bash/bashrc_temp insertafter: EOF create: true state: present @@ -31,14 +43,3 @@ when: pam_environment.changed debug: msg: "\u26A0\uFE0F \u26A0\uFE0F You need to log out and back in to update your environment \u26A0\uFE0F \u26A0\uFE0F" -- name: Create XDG dirs - file: - path: "{{ item }}" - state: directory - loop: - - "$XDG_CONFIG_HOME" - - "$XDG_STATE_HOME" - - "$XDG_DATA_HOME" - - "$XDG_CACHE_HOME" - - "$HOME/Desktop" - - "$HOME/Downloads" diff --git a/roles/shell/bash/templates/bash_profile.j2 b/roles/shell/bash/templates/bash_profile.j2 index 9b9e86c..8ffd818 100644 --- a/roles/shell/bash/templates/bash_profile.j2 +++ b/roles/shell/bash/templates/bash_profile.j2 @@ -4,7 +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 + [[ -f "$XDG_STATE_HOME/bash/bashrc_temp" ]] && rm -f $XDG_STATE_HOME/bash/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 fff19f7..91334b7 100644 --- a/roles/shell/bash/templates/bashrc.j2 +++ b/roles/shell/bash/templates/bashrc.j2 @@ -2,7 +2,7 @@ # ~/.bashrc # -[[ -f "$HOME/.bashrc_temp" ]] && . $HOME/.bashrc_temp +[[ -f "$XDG_STATE_HOME/bash/bashrc_temp" ]] && . $XDG_STATE_HOME/bash/bashrc_temp if [ -n "$HOME/.local/bin" ]; then PATH="$HOME/.local/bin:$PATH" @@ -137,6 +137,8 @@ PS1='\[\033[01;31m\]$(error_code)\[\033[00;00m\]$(running_jobs)\[\033[01;32m\]$( PS1='\[\033[01;31m\]$(error_code)\[\033[00;00m\]$(running_jobs)\[$(git_prompt_color)\]$(git_prompt)\[\033[00;32m\]\u@\h\[\033[94m\] \w \$\[\033[00m\] ' {% endif %} +PROMPT_COMMAND="[[ -f "$XDG_STATE_HOME/bash/bashrc_temp" ]] && . $XDG_STATE_HOME/bash/bashrc_temp" + {% if "nodejs" in features.get(profile, []) %} source /usr/share/nvm/init-nvm.sh {% endif %} -- 2.41.0