From d82b98593f536db244f0a0b62fdb3b0d9c6d0725 Mon Sep 17 00:00:00 2001 From: Ludovic Cartier Date: Tue, 17 Dec 2024 17:30:08 +0100 Subject: [PATCH] initial commit --- tasks/main.yml | 56 +++++++++++++++++++++++++++++++++++ templates/powerline.custom.j2 | 21 +++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 tasks/main.yml create mode 100644 templates/powerline.custom.j2 diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..9093519 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,56 @@ +--- +- name: powerline.bash | verify vars + assert: + that: + - powerline_bash_user is defined + +- name: powerline.bash | get user info + getent: + database: passwd + +#- debug: +# msg: "{{ item }}: homedir is {{ getent_passwd[item][4] }} & group is {{ getent_passwd[item][2] }}" +# with_items: +# - "{{ powerline_bash_user }}" + +- name: powerline.bash | create config directory + file: + path: "{{ getent_passwd[item][4] }}/.config" + state: directory + owner: "{{ item }}" + group: "{{ getent_passwd[item][2] }}" + mode: '0755' + loop: "{{ powerline_bash_user }}" + +- name: powerline.bash | get powerline.bash + get_url: + url: https://gitlab.com/bersace/powerline.bash/raw/master/powerline.bash + dest: "{{ getent_passwd[item][4] }}/.config/powerline.bash" + owner: "{{ item }}" + group: "{{ getent_passwd[item][2] }}" + force: yes + loop: "{{ powerline_bash_user }}" + +- name: powerline.bash | create configuration file + template: + src: powerline.custom.j2 + dest: "{{ getent_passwd[item][4] }}/.config/powerline.custom" + owner: "{{ item }}" + group: "{{ getent_passwd[item][2] }}" + mode: 0644 + loop: "{{ powerline_bash_user }}" + +- name: powerline.bash | append .bashrc + blockinfile: + path: "{{ getent_passwd[item][4] }}/.bashrc" + block: | + + # enable powerline.bash + # https://gitlab.com/bersace/powerline.bash + if [ -f ~/.config/powerline.custom ]; then + . ~/.config/powerline.custom + fi + insertafter: EOF + backup: yes + validate: /bin/bash -n %s + loop: "{{ powerline_bash_user }}" diff --git a/templates/powerline.custom.j2 b/templates/powerline.custom.j2 new file mode 100644 index 0000000..348c9af --- /dev/null +++ b/templates/powerline.custom.j2 @@ -0,0 +1,21 @@ +# {{ ansible_managed }} + +if [ "$EUID" -eq 0 ]; then + POWERLINE_HOSTNAME_BG="rouge" + POWERLINE_HOSTNAME_FG="blanc" +else + POWERLINE_HOSTNAME_BG="{{ powerline_hostname_bg | default('blanc') }}" + POWERLINE_HOSTNAME_FG="{{ powerline_hostname_fg | default('noir-fedora') }}" +fi + +#{% if powerline_hostname_bg is defined %} +#POWERLINE_HOSTNAME_BG="{{ powerline_hostname_bg }}" +#{% endif %} +#{% if powerline_hostname_fg is defined %} +#POWERLINE_HOSTNAME_FG="{{ powerline_hostname_fg }}" +#{% endif %} + +. ${HOME}/.config/powerline.bash +PROMPT_COMMAND='__update_ps1 $?' + +POWERLINE_SEGMENTS="logo heure hostname pwd python git git_sync docker status jobs"