Get the most out of your Centmin Mod LEMP stack
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

    30,613
    6,862
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,304
    Local Time:
    8:49 PM
    Nginx 1.13.x
    MariaDB 5.5
    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
     
    • Like Like x 2
  2. eva2000

    eva2000 Administrator Staff Member

    30,613
    6,862
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,304
    Local Time:
    8:49 PM
    Nginx 1.13.x
    MariaDB 5.5
    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 Premium Member Premium Member

    1,140
    252
    83
    Oct 24, 2015
    East Coast USA
    Ratings:
    +609
    Local Time:
    5:49 AM
    1.13.x
    MariaDB 10.1.x
    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

    30,613
    6,862
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,304
    Local Time:
    8:49 PM
    Nginx 1.13.x
    MariaDB 5.5
    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 Premium Member Premium Member

    1,140
    252
    83
    Oct 24, 2015
    East Coast USA
    Ratings:
    +609
    Local Time:
    5:49 AM
    1.13.x
    MariaDB 10.1.x
    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.
     
    • Agree Agree x 1
  6. eva2000

    eva2000 Administrator Staff Member

    30,613
    6,862
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,304
    Local Time:
    8:49 PM
    Nginx 1.13.x
    MariaDB 5.5
    k just updated 123.09beta01 to upper case W for basename of working directory as wrapping to new line could cause problems !
     
    • Like Like x 1
  7. Sunka

    Sunka Active Member

    926
    240
    43
    Oct 31, 2015
    Rijeka, Croatia
    Ratings:
    +389
    Local Time:
    11:49 AM
    Nginx 1.13.3
    MariaDB 10.1.24
    How to back to old way?
    I do not like it and it consume half of my cli?
     
  8. eva2000

    eva2000 Administrator Staff Member

    30,613
    6,862
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,304
    Local Time:
    8:49 PM
    Nginx 1.13.x
    MariaDB 5.5
    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 Active Member

    926
    240
    43
    Oct 31, 2015
    Rijeka, Croatia
    Ratings:
    +389
    Local Time:
    11:49 AM
    Nginx 1.13.3
    MariaDB 10.1.24
    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

    30,613
    6,862
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,304
    Local Time:
    8:49 PM
    Nginx 1.13.x
    MariaDB 5.5
    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 Premium Member Premium Member

    1,140
    252
    83
    Oct 24, 2015
    East Coast USA
    Ratings:
    +609
    Local Time:
    5:49 AM
    1.13.x
    MariaDB 10.1.x
    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

    30,613
    6,862
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,304
    Local Time:
    8:49 PM
    Nginx 1.13.x
    MariaDB 5.5
    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 \\$
     
    • Like Like x 1
  13. Jimmy

    Jimmy Premium Member Premium Member

    1,140
    252
    83
    Oct 24, 2015
    East Coast USA
    Ratings:
    +609
    Local Time:
    5:49 AM
    1.13.x
    MariaDB 10.1.x
    That works!
     
    • Like Like x 1
  14. Sunka

    Sunka Active Member

    926
    240
    43
    Oct 31, 2015
    Rijeka, Croatia
    Ratings:
    +389
    Local Time:
    11:49 AM
    Nginx 1.13.3
    MariaDB 10.1.24
    Now it is working.
     
  15. Sunka

    Sunka Active Member

    926
    240
    43
    Oct 31, 2015
    Rijeka, Croatia
    Ratings:
    +389
    Local Time:
    11:49 AM
    Nginx 1.13.3
    MariaDB 10.1.24
    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

    30,613
    6,862
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,304
    Local Time:
    8:49 PM
    Nginx 1.13.x
    MariaDB 5.5
    only if you add colours right ?
     
  17. Sunka

    Sunka Active Member

    926
    240
    43
    Oct 31, 2015
    Rijeka, Croatia
    Ratings:
    +389
    Local Time:
    11:49 AM
    Nginx 1.13.3
    MariaDB 10.1.24
    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 "
     
    • Informative Informative x 1
  18. pamamolf

    pamamolf Well-Known Member

    2,774
    245
    63
    May 31, 2014
    Ratings:
    +437
    Local Time:
    12:49 PM
    Nginx-1.13.x
    MariaDB 10.1.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

    30,613
    6,862
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,304
    Local Time:
    8:49 PM
    Nginx 1.13.x
    MariaDB 5.5
  20. eva2000

    eva2000 Administrator Staff Member

    30,613
    6,862
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,304
    Local Time:
    8:49 PM
    Nginx 1.13.x
    MariaDB 5.5
    Yeah not what can do about that.. probably better to not use colours then