Want more timely Centmin Mod News Updates?
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

    34,581
    7,650
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +11,766
    Local Time:
    4:43 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    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][[email protected] /home/nginx]$
    


    Continue reading...

    123.09beta01 branch
     
    • Like Like x 2
  2. eva2000

    eva2000 Administrator Staff Member

    34,581
    7,650
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +11,766
    Local Time:
    4:43 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    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][[email protected] /home/nginx/domains/demodomain.com/public/includes/1/2/3]$
    
     
  3. Jimmy

    Jimmy Premium Member Premium Member

    1,279
    268
    83
    Oct 24, 2015
    East Coast USA
    Ratings:
    +660
    Local Time:
    2:43 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

    34,581
    7,650
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +11,766
    Local Time:
    4:43 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    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][\[email protected]\H \w]\\$ "
    

    to (lower case w to upper case W)
    Code (Text):
    export PS1="[\A][\[email protected]\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][\[email protected]\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][\[email protected]\H \W]\\$ "
    
     
    Last edited: Feb 2, 2017
  5. Jimmy

    Jimmy Premium Member Premium Member

    1,279
    268
    83
    Oct 24, 2015
    East Coast USA
    Ratings:
    +660
    Local Time:
    2:43 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

    34,581
    7,650
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +11,766
    Local Time:
    4:43 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    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 Well-Known Member

    986
    266
    63
    Oct 31, 2015
    Rijeka, Croatia
    Ratings:
    +439
    Local Time:
    8:43 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

    34,581
    7,650
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +11,766
    Local Time:
    4:43 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    in /root/.bashrc set export PS1 line to
    Code (Text):
    export PS1="[\[email protected]\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

    986
    266
    63
    Oct 31, 2015
    Rijeka, Croatia
    Ratings:
    +439
    Local Time:
    8:43 AM
    Nginx 1.13.3
    MariaDB 10.1.24
  10. eva2000

    eva2000 Administrator Staff Member

    34,581
    7,650
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +11,766
    Local Time:
    4:43 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    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,279
    268
    83
    Oct 24, 2015
    East Coast USA
    Ratings:
    +660
    Local Time:
    2:43 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

    34,581
    7,650
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +11,766
    Local Time:
    4:43 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    ah for # to work for root user need double backslash on \\s
    Code (Text):
    export PS1="[\[email protected]\h \W]\\$ "
    

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

    Jimmy Premium Member Premium Member

    1,279
    268
    83
    Oct 24, 2015
    East Coast USA
    Ratings:
    +660
    Local Time:
    2:43 AM
    1.13.x
    MariaDB 10.1.x
    That works!
     
    • Like Like x 1
  14. Sunka

    Sunka Well-Known Member

    986
    266
    63
    Oct 31, 2015
    Rijeka, Croatia
    Ratings:
    +439
    Local Time:
    8:43 AM
    Nginx 1.13.3
    MariaDB 10.1.24
    Now it is working.
     
  15. Sunka

    Sunka Well-Known Member

    986
    266
    63
    Oct 31, 2015
    Rijeka, Croatia
    Ratings:
    +439
    Local Time:
    8:43 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

    34,581
    7,650
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +11,766
    Local Time:
    4:43 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    only if you add colours right ?
     
  17. Sunka

    Sunka Well-Known Member

    986
    266
    63
    Oct 31, 2015
    Rijeka, Croatia
    Ratings:
    +439
    Local Time:
    8:43 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 [\[email protected]\h \W]\\$ \e[m "
     
    • Informative Informative x 1
  18. pamamolf

    pamamolf Well-Known Member

    3,102
    294
    83
    May 31, 2014
    Ratings:
    +527
    Local Time:
    9:43 AM
    Nginx-1.13.x
    MariaDB 10.1.x
    The [email protected] 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

    34,581
    7,650
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +11,766
    Local Time:
    4:43 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
  20. eva2000

    eva2000 Administrator Staff Member

    34,581
    7,650
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +11,766
    Local Time:
    4:43 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
..