Want to subscribe to topics you're interested in?
Become a Member

Beta Branch customise PS1 command prompt for clearer identification of server

Discussion in 'Centmin Mod Github Commits' started by eva2000, Feb 2, 2017.

Tags:
  1. eva2000

    eva2000 Administrator Staff Member

    54,895
    12,240
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,811
    Local Time:
    11:12 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    customise PS1 command prompt for clearer identification of server

    In 123.09beta01+ and higher customise PS1 command prompt to display full hostname instead of short form hostname and display time's hour:min as well for clearer identification of server when working in SSH sessions with multiple servers https://community.centminmod.com/posts/44161/.

    For existing Centmin Mod users, only takes affect next time you run centmin.sh and then exit your SSH session. Subsequent SSH sessions have the new custom prompt

    Code (Text):
    [18:02][root@host1.domain.com /home/nginx]$
    



    Continue reading...

    123.09beta01 branch
     
  2. eva2000

    eva2000 Administrator Staff Member

    54,895
    12,240
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,811
    Local Time:
    11:12 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    full working directory gets displayed too which can be lengthly on deep directories but it gives full display so you know exactly which directory you are working in

    Code (Text):
    [18:18][root@host1.domain.com /home/nginx/domains/demodomain.com/public/includes/1/2/3]$
    
     
  3. Jimmy

    Jimmy Well-Known Member

    1,788
    390
    83
    Oct 24, 2015
    East Coast USA
    Ratings:
    +990
    Local Time:
    9:12 AM
    TBH not sure about the full directory listing especially if the terminal window is narrow. Though, I do like the full hostname.
     
  4. eva2000

    eva2000 Administrator Staff Member

    54,895
    12,240
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,811
    Local Time:
    11:12 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    yeah true i.e. out of band KVM/IPMI consoles have narrow width hmmm

    changing it is easy backup and then edit /root/.bashrc and change
    Code (Text):
    export PS1="[\A][\u@\H \w]\\$ "
    

    to (lower case w to upper case W)
    Code (Text):
    export PS1="[\A][\u@\H \W]\\$ "
    


    changing PS1 command prompt is easy on the fly too

    find out the existing PS1 format via echo the $PS1 variable
    Code (Text):
    echo $PS1
    

    Code (Text):
    echo $PS1
    [\A][\u@\H \w]$
    

    take the output and assign it to PS1 and it is only temporarily for that SSH session just changing w to W
    Code (Text):
    PS1="[\A][\u@\H \W]\\$ "
    
     
    Last edited: Feb 2, 2017
  5. Jimmy

    Jimmy Well-Known Member

    1,788
    390
    83
    Oct 24, 2015
    East Coast USA
    Ratings:
    +990
    Local Time:
    9:12 AM
    Maybe, omit it and allow people to add it if they want. Probably most power users won't want it and I have a feeling most of your users are power users. On the other hand, it could be helpful to new users, though it wrapping onto another line could be confusing to new users especially if the terminal gets funky wrapping to the second line.
     
  6. eva2000

    eva2000 Administrator Staff Member

    54,895
    12,240
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,811
    Local Time:
    11:12 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    k just updated 123.09beta01 to upper case W for basename of working directory as wrapping to new line could cause problems !
     
  7. Sunka

    Sunka Well-Known Member

    1,150
    325
    83
    Oct 31, 2015
    Pula, Croatia
    Ratings:
    +525
    Local Time:
    2:12 PM
    Nginx 1.17.9
    MariaDB 10.3.22
    How to back to old way?
    I do not like it and it consume half of my cli?
     
  8. eva2000

    eva2000 Administrator Staff Member

    54,895
    12,240
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,811
    Local Time:
    11:12 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    in /root/.bashrc set export PS1 line to
    Code (Text):
    export PS1="[\u@\h \W]\\$ "
    

    logout and back into SSH

    but most SSH clients like secureCRT can set wider SSH windows ;)

    My secureCRT SSH window length width wise :)

    upload_2017-2-2_4-43-1.png
     
    Last edited: Feb 2, 2017
  9. Sunka

    Sunka Well-Known Member

    1,150
    325
    83
    Oct 31, 2015
    Pula, Croatia
    Ratings:
    +525
    Local Time:
    2:12 PM
    Nginx 1.17.9
    MariaDB 10.3.22
    Before:
    [root@upcloud ~]#

    Now:
    [root@upcloud ~]$

    Should I change

    export PS1="[\u@\h \W]\$ "

    to

    export PS1="[\u@\h \W]\# "

    I know, but I like to work on small size untill I need to resize (glances for example).
     
  10. eva2000

    eva2000 Administrator Staff Member

    54,895
    12,240
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,811
    Local Time:
    11:12 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    from How to: Change / Setup bash custom prompt (PS1)
    so root user with UID = 0 see #, if not root UID != 0 they see $

    but doesn't seem to be the case now

    Just comment out export line in /root/.bashrc then. Don't delete, as centmin.sh will re-add PS1 if you delete it.
     
  11. Jimmy

    Jimmy Well-Known Member

    1,788
    390
    83
    Oct 24, 2015
    East Coast USA
    Ratings:
    +990
    Local Time:
    9:12 AM
    I put in $ and logging in as root I saw $.

    I logged out and back into the session, still $.

    Users.........: Currently 1 user(s) logged on (includes: root)
     
  12. eva2000

    eva2000 Administrator Staff Member

    54,895
    12,240
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,811
    Local Time:
    11:12 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    ah for # to work for root user need double backslash on \\s
    Code (Text):
    export PS1="[\u@\h \W]\\$ "
    

    so backup and then edit /root/.bashrc
    changing the \$ to \\$
     
  13. Jimmy

    Jimmy Well-Known Member

    1,788
    390
    83
    Oct 24, 2015
    East Coast USA
    Ratings:
    +990
    Local Time:
    9:12 AM
    That works!
     
  14. Sunka

    Sunka Well-Known Member

    1,150
    325
    83
    Oct 31, 2015
    Pula, Croatia
    Ratings:
    +525
    Local Time:
    2:12 PM
    Nginx 1.17.9
    MariaDB 10.3.22
    Now it is working.
     
  15. Sunka

    Sunka Well-Known Member

    1,150
    325
    83
    Oct 31, 2015
    Pula, Croatia
    Ratings:
    +525
    Local Time:
    2:12 PM
    Nginx 1.17.9
    MariaDB 10.3.22
    Tried to add coluors but ended with strange thing. If cli window is smaller than command input, than command at the end go back on start crossing hostname on the beginning
     
  16. eva2000

    eva2000 Administrator Staff Member

    54,895
    12,240
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,811
    Local Time:
    11:12 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    only if you add colours right ?
     
  17. Sunka

    Sunka Well-Known Member

    1,150
    325
    83
    Oct 31, 2015
    Pula, Croatia
    Ratings:
    +525
    Local Time:
    2:12 PM
    Nginx 1.17.9
    MariaDB 10.3.22
    This is with resized cli window

    1.PNG

    This is with full screen cli window

    2.PNG


    This is code:
    Code:
    export PS1="\e[1;32m [\u@\h \W]\\$ \e[m "
     
  18. pamamolf

    pamamolf Premium Member Premium Member

    4,086
    428
    83
    May 31, 2014
    Ratings:
    +834
    Local Time:
    3:12 PM
    Nginx-1.25.x
    MariaDB 10.3.x
    The root@hostname is very useful but i don't like the working directory there .... :)

    How can i disable that working directory there?

    Can't work at all on my tablet with it :(

    It will be better to not have this one as default please.

    Thanks
     
    Last edited: Feb 2, 2017
  19. eva2000

    eva2000 Administrator Staff Member

    54,895
    12,240
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,811
    Local Time:
    11:12 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
  20. eva2000

    eva2000 Administrator Staff Member

    54,895
    12,240
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,811
    Local Time:
    11:12 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Yeah not what can do about that.. probably better to not use colours then