How to customize ps1

maybe a colorful ps1 :slight_smile:

You want a colourful cli on your router?

yes ,that would be cool :slight_smile:

Does the standard way of adding your PS1 changes to ~/.bashrc not work?

Did a quick check, in ~/.bashrc there is #force_color_prompt=yes. If I uncomment it then I get a color prompt in operation mode and it does survive a reboot.

yes ,good idea ,but it will not impact config mode

Yes, you are right. It won’t affect config mode. What would be your goal with the prompt being colored?

Like including information in the prompt you don’t get right now? Or different colors for operation and configure mode?

Although I use vyos as primary router ,I also use mikrotik for test and learning , the cli for mikrotik is not bad ,like it . Ros Cli provide full colorful features ,not only PS ,but I guess it would be hard for vyos now to have the similar feature.

Oh I see. I don’t know how much work it would be, or if it is even possible (I assume it is possible).

One would have to create either a feature request (or check if there is/was already one) or implement it themself and create a pull request (ideally with the possibility to switch it on or of)

I do this on our prod routers, so users can tell if they are in OP mode or CONFIG mode

3 Likes

And how do you do it, which config files are you modifying?

Might be a good idea. I made a task at ⚓ T7418 Make console prompts customizable for further discussions.

3 Likes

We use ansible to change users bashrc file, using lineinfile module, but we only change the force_colour_prompt=yes line.

Working on similar to what we do on our prod servers were when user is root then the prompt is red when its your user its green, looking to to do red for when in config mode and green otherwise.

At first I thought a coloured prompt was a silly idea but this is a good point. It’s actually something I do myself using SecreCRTs regex engine, but it would be cool to see this built in too.

2 Likes

bash_colours

# Works On Debian/Ubuntu
# enable color when you login as root user with sudo -i or sudo -s
if [ `whoami` == 'root' ]; then
        # Set RED prompt [\033[01;31m\]
        PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
        # Set GREEN  prompt [\033[01;32m\]
        PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
fi

Ansible

- name: Copy root colour change file
  ansible.builtin.copy:
    src: bash_colours
    dest: /root/.bash_colours
    owner: root
    group: root
    mode: "0644"
  when:
    - ansible_distribution == "Debian"

- name: Source colour change file in /root/.bashrc
  ansible.builtin.blockinfile:
    path: /root/.bashrc
    block: |
      source /root/.bash_colours
    state: present
    insertafter: EOF
  when:
    - ansible_distribution == "Debian"

This is what we use for our Debian servers, not tested against Vyos and the configure mode but with some tweaks it could work.

1 Like