Procházet zdrojové kódy

Allow setting system-wide prompt

tags/2016.12
Filip Pytloun před 9 roky
rodič
revize
1f40dac0df
4 změnil soubory, kde provedl 60 přidání a 0 odebrání
  1. +18
    -0
      README.rst
  2. +20
    -0
      linux/files/prompt.sh
  3. +3
    -0
      linux/system/init.sls
  4. +19
    -0
      linux/system/prompt.sls

+ 18
- 0
README.rst Zobrazit soubor

@@ -217,6 +217,24 @@ rc.local example
# By default this script does nothing.
exit 0

Prompt
~~~~~~

Setting prompt is implemented by creating ``/etc/profile.d/prompt.sh``. Every
user can have different prompt.

.. code-block:: yaml

linux:
system:
prompt:
root: \\n\\[\\033[0;37m\\]\\D{%y/%m/%d %H:%M:%S} $(hostname -f)\\[\\e[0m\\]\\n\\[\\e[1;31m\\][\\u@\\h:\\w]\\[\\e[0m\\]
default: \\n\\D{%y/%m/%d %H:%M:%S} $(hostname -f)\\n[\\u@\\h:\\w]

On Debian systems to set prompt system-wide it's necessary to remove setting
PS1 in ``/etc/bash.bashrc`` and ``~/.bashrc`` (which comes from
``/etc/skel/.bashrc``). This formula will do this automatically, but will not
touch existing user's ``~/.bashrc`` files.

Linux network
-------------

+ 20
- 0
linux/files/prompt.sh Zobrazit soubor

@@ -0,0 +1,20 @@
{%- from "linux/map.jinja" import system with context %}

# Don't set special prompt when not using Bash or ZSH
[ -n "$BASH_VERSION" -o -n "$ZSH_VERSION" ] || return 0

# Don't set prompt on non-interactive shell
[[ $- == *i* ]] || return 0

{%- for user, prompt in system.prompt.iteritems() %}
{% if user != default %}
if [ "$USERNAME" == "{{ user }}" ]; then
export PS1="{{ prompt }} "
return 0
fi
{% endif %}
{%- endfor %}

{% if system.prompt.default is defined %}
export PS1="{{ system.prompt.default }} "
{%- endif %}

+ 3
- 0
linux/system/init.sls Zobrazit soubor

@@ -45,3 +45,6 @@ include:
{%- if system.limit|length > 0 %}
- linux.system.limit
{%- endif %}
{%- if system.prompt is defined %}
- linux.system.prompt
{%- endif %}

+ 19
- 0
linux/system/prompt.sls Zobrazit soubor

@@ -0,0 +1,19 @@
{%- from "linux/map.jinja" import system with context %}
{%- if system.enabled %}

/etc/profile.d/prompt.sh:
file.managed:
- source: salt://linux/files/prompt.sh
- template: jinja

/etc/bash.bashrc:
file.replace:
- pattern: ".*PS1=.*"
- repl: "# Prompt is set by /etc/profile.d/prompt.sh"

/etc/skel/.bashrc:
file.replace:
- pattern: ".*PS1=.*"
- repl: "# Prompt is set by /etc/profile.d/prompt.sh"

{%- endif %}

Načítá se…
Zrušit
Uložit