From 853c14457ef51fbca58f9c4fb5c1a255e68d7c87 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Isma=C3=ABl=20Bouya?= Date: Sun, 18 Nov 2018 13:14:33 +0100 Subject: [PATCH] Make bash xdg-compliant --- roles/init/tasks/main.yml | 1 - roles/init/templates/pam_environment.j2 | 3 +++ roles/shell/bash/files/inputrc | 7 +++++++ roles/shell/bash/tasks/main.yml | 12 ++++++++++-- roles/shell/bash/templates/bash_profile.j2 | 4 +++- roles/shell/bash/templates/bashrc.j2 | 20 +++++++++++++------- 6 files changed, 36 insertions(+), 11 deletions(-) create mode 100644 roles/shell/bash/files/inputrc diff --git a/roles/init/tasks/main.yml b/roles/init/tasks/main.yml index a52f3cd..e60bb2a 100644 --- a/roles/init/tasks/main.yml +++ b/roles/init/tasks/main.yml @@ -9,7 +9,6 @@ - "$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/@@"' diff --git a/roles/init/templates/pam_environment.j2 b/roles/init/templates/pam_environment.j2 index 5bb8895..c257045 100644 --- a/roles/init/templates/pam_environment.j2 +++ b/roles/init/templates/pam_environment.j2 @@ -19,6 +19,9 @@ BROWSER DEFAULT="firefox" # replace GIO with xdg-open, see tools/files/gio_unwrapper.sh GIO_LAUNCH_DESKTOP DEFAULT=gio_unwrapper +# Readline +INPUTRC DEFAULT="${XDG_CONFIG_HOME}/inputrc" + # Ansible ANSIBLE_CONFIG DEFAULT="${XDG_CONFIG_HOME}/ansible/ansible.cfg" diff --git a/roles/shell/bash/files/inputrc b/roles/shell/bash/files/inputrc new file mode 100644 index 0000000..111f8dd --- /dev/null +++ b/roles/shell/bash/files/inputrc @@ -0,0 +1,7 @@ +$include /etc/inputrc +# Readline configuration +# Can also be specified in bashrc with: bind "..." +set colored-completion-prefix on +# TAB: menu-complete +set show-all-if-ambiguous on +set show-all-if-unmodified on diff --git a/roles/shell/bash/tasks/main.yml b/roles/shell/bash/tasks/main.yml index d74421a..6bf3859 100644 --- a/roles/shell/bash/tasks/main.yml +++ b/roles/shell/bash/tasks/main.yml @@ -1,12 +1,20 @@ --- +- name: Create config dir + file: + path: $XDG_CONFIG_HOME/bash + state: directory - name: Add bashrc config template: src: bashrc.j2 - dest: $HOME/.bashrc + dest: $XDG_CONFIG_HOME/bash/bashrc - name: Add bash_profile config template: src: bash_profile.j2 - dest: $HOME/.bash_profile + dest: $XDG_CONFIG_HOME/bash/bash_profile +- name: Add inputrc config + copy: + src: inputrc + dest: $XDG_CONFIG_HOME/inputrc - name: Create bash state dir file: path: $XDG_STATE_HOME/bash diff --git a/roles/shell/bash/templates/bash_profile.j2 b/roles/shell/bash/templates/bash_profile.j2 index 8ffd818..4bcd09c 100644 --- a/roles/shell/bash/templates/bash_profile.j2 +++ b/roles/shell/bash/templates/bash_profile.j2 @@ -1,6 +1,8 @@ # Some variables are loaded via pam (see .config/pam_environment) +# This file is loaded thanks to as line in /etc/profile +# test "$BASH" && test -r "$XDG_CONFIG_HOME/bash/bash_profile" && . $XDG_CONFIG_HOME/bash/bash_profile -[[ -f ~/.bashrc ]] && . ~/.bashrc +[[ -f $XDG_CONFIG_HOME/bash/bashrc ]] && . $XDG_CONFIG_HOME/bash/bashrc {% if "graphical_vt" in features.get(profile, []) %} if [[ ! $DISPLAY && $XDG_VTNR -eq 1 ]]; then diff --git a/roles/shell/bash/templates/bashrc.j2 b/roles/shell/bash/templates/bashrc.j2 index 08518c9..b717f0e 100644 --- a/roles/shell/bash/templates/bashrc.j2 +++ b/roles/shell/bash/templates/bashrc.j2 @@ -27,7 +27,7 @@ alias mv="mv -i" alias cp="cp -i" alias rm="rm -i" alias psp="pstree -aUp $USER" -alias dotdrop="dotdrop --cfg $XDG_CONFIG_HOME/dotdrop/config.yaml" +alias info='info -v active-link-style=yellow,bold -v link-style=yellow' [[ -f /usr/share/stgit/completion/stgit-completion.bash ]] && . /usr/share/stgit/completion/stgit-completion.bash @@ -125,6 +125,7 @@ function git_prompt() { echo -e "($gitinfo) " fi } +{% set ps1_git = '\[$(git_prompt_color)\]$(git_prompt)' %} function error_code() { ret=$? @@ -139,14 +140,19 @@ function running_jobs() { echo "[$ret] " fi } +{% set ps1_status = '\[\\033[01;31m\]$(error_code)\[\\033[00;00m\]$(running_jobs)' -%} -{% if role.get(profile) == "fretlink" %} -PS1='\[\033[01;31m\]$(error_code)\[\033[00;00m\]$(running_jobs)\[\033[01;32m\]$(dev_prompt)\[$(git_prompt_color)\]$(git_prompt)\[\033[00;32m\]\u@\h\[\033[94m\] \w \$\[\033[00m\] ' -{% else %} -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 %} +{# Ensure new line before the prompt #} +{% set ps1_newline = '$(printf "%$((`tput cols`-1))s\\r")' -%} + +{% set ps1_other = '' %} +{% if role.get(profile) == "fretlink" -%} + {% set ps1_other = '\[\\033[01;32m\]$(dev_prompt)' %} +{%- endif %} + +PS1='{{ ps1_newline }}{{ ps1_status }}{{ ps1_other }}{{ ps1_git }}\[\033[00;32m\]\u@\h\[\033[94m\] \w \$\[\033[00m\] ' -PROMPT_COMMAND="[[ -f "$XDG_STATE_HOME/bash/bashrc_temp" ]] && . $XDG_STATE_HOME/bash/bashrc_temp" +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 -- 2.41.0