Author Topic: How to bring a little bling bling to your Terminal  (Read 556 times)

0 Members and 1 Guest are viewing this topic.

Offline TheAkantor

  • Newly Subscribed
  • *
  • Posts: 24
  • Karma: 8
  • New Forum User
    • View Profile
  • Peppermint version(s): Peppermint 10 Respin
How to bring a little bling bling to your Terminal
« on: February 07, 2020, 07:12:25 am »
Bringing just a little customization to the terminal



Step 1. Instal powerline fonts, can be found in the software manager or just type in the terminal
Code: [Select]
sudo apt install fonts-powerline

Step 2.
Open your file explorer and go your home directory, right click on a empty space and choose Show Hidden Files



Step 3.
Now that you can see the hidden files, i advice making a backup of the original .bashrc just in case you messed up somehow , go back to the original file .bashrc and open it with the text editor.

Scroll to the end press enter to add a new line and then copy and paste the code that i have in the spoiler below and save:

Spoiler (click here to view / hide)
################################################################################
##  FUNCTIONS                                                                 ##
################################################################################

##
##   ARRANGE $PWD AND STORE IT IN $NEW_PWD
##   * The home directory (HOME) is replaced with a ~
##   * The last pwdmaxlen characters of the PWD are displayed
##   * Leading partial directory names are striped off
##      /home/me/stuff -> ~/stuff (if USER=me)
##      /usr/share/big_dir_name -> ../share/big_dir_name (if pwdmaxlen=20)
##
##   Original source: WOLFMAN'S color bash promt
##   https://wiki.chakralinux.org/index.php?title=Color_Bash_Prompt#Wolfman.27s
##
bash_prompt_command() {
   # How many characters of the $PWD should be kept
   local pwdmaxlen=25

   # Indicate that there has been dir truncation
   local trunc_symbol=".."

   # Store local dir
   local dir=${PWD##*/}

   # Which length to use
   pwdmaxlen=$(( ( pwdmaxlen < ${#dir} ) ? ${#dir} : pwdmaxlen ))

   NEW_PWD=${PWD/#$HOME/\~}
   
   local pwdoffset=$(( ${#NEW_PWD} - pwdmaxlen ))

   # Generate name
   if [ ${pwdoffset} -gt "0" ]
   then
      NEW_PWD=${NEW_PWD:$pwdoffset:$pwdmaxlen}
      NEW_PWD=${trunc_symbol}/${NEW_PWD#*/}
   fi
}




##
##   GENERATE A FORMAT SEQUENCE
##
format_font()
{
   ## FIRST ARGUMENT TO RETURN FORMAT STRING
   local output=$1


   case $# in
   2)
      eval $output="'\[\033[0;${2}m\]'"
      ;;
   3)
      eval $output="'\[\033[0;${2};${3}m\]'"
      ;;
   4)
      eval $output="'\[\033[0;${2};${3};${4}m\]'"
      ;;
   *)
      eval $output="'\[\033[0m\]'"
      ;;
   esac
}



##
## COLORIZE BASH PROMT
##
bash_prompt() {

   ############################################################################
   ## COLOR CODES                                                            ##
   ## These can be used in the configuration below                           ##
   ############################################################################
   
   ## FONT EFFECT
   local      NONE='0'
   local      BOLD='1'
   local       DIM='2'
   local UNDERLINE='4'
   local     BLINK='5'
   local    INVERT='7'
   local    HIDDEN='8'
   
   
   ## COLORS
   local   DEFAULT='9'
   local     BLACK='0'
   local       RED='1'
   local     GREEN='2'
   local    YELLOW='3'
   local      BLUE='4'
   local   MAGENTA='5'
   local      CYAN='6'
   local    L_GRAY='7'
   local    D_GRAY='60'
   local     L_RED='61'
   local   L_GREEN='62'
   local  L_YELLOW='63'
   local    L_BLUE='64'
   local L_MAGENTA='65'
   local    L_CYAN='66'
   local     WHITE='67'
   
   
   ## TYPE
   local     RESET='0'
   local    EFFECT='0'
   local     COLOR='30'
   local        BG='40'
   
   
   ## 256 COLOR CODES
   local NO_FORMAT="\[\033[0m\]"
   local ORANGE_BOLD="\[\033[1;38;5;208m\]"
   local TOXIC_GREEN_BOLD="\[\033[1;38;5;118m\]"
   local RED_BOLD="\[\033[1;38;5;1m\]"
   local CYAN_BOLD="\[\033[1;38;5;87m\]"
   local BLACK_BOLD="\[\033[1;38;5;0m\]"
   local WHITE_BOLD="\[\033[1;38;5;15m\]"
   local GRAY_BOLD="\[\033[1;90m\]"
   local BLUE_BOLD="\[\033[1;38;5;74m\]"
   
   
   
   
   
   ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ## 
     ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##
   ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##

   
   
   ##                          CONFIGURE HERE                                ##

   
   
   ############################################################################
   ## CONFIGURATION                                                          ##
   ## Choose your color combination here                                     ##
   ############################################################################
   local FONT_COLOR_1=$WHITE
   local BACKGROUND_1=$BLUE
   local TEXTEFFECT_1=$BOLD
   
   local FONT_COLOR_2=$WHITE
   local BACKGROUND_2=$L_BLUE
   local TEXTEFFECT_2=$BOLD
   
   local FONT_COLOR_3=$D_GRAY
   local BACKGROUND_3=$WHITE
   local TEXTEFFECT_3=$BOLD
   
   local PROMT_FORMAT=$BLUE_BOLD

   
   ############################################################################
   ## EXAMPLE CONFIGURATIONS                                                 ##
   ## I use them for different hosts. Test them out ;)                       ##
   ############################################################################
   
   ## CONFIGURATION: BLUE-WHITE
   if [ "$HOSTNAME" = dell ]; then
      FONT_COLOR_1=$WHITE; BACKGROUND_1=$BLUE; TEXTEFFECT_1=$BOLD
      FONT_COLOR_2=$WHITE; BACKGROUND_2=$L_BLUE; TEXTEFFECT_2=$BOLD   
      FONT_COLOR_3=$D_GRAY; BACKGROUND_3=$WHITE; TEXTEFFECT_3=$BOLD   
      PROMT_FORMAT=$CYAN_BOLD
   fi
   
   ## CONFIGURATION: BLACK-RED
   if [ "$HOSTNAME" = giraff6 ]; then
      FONT_COLOR_1=$WHITE; BACKGROUND_1=$BLACK; TEXTEFFECT_1=$BOLD
      FONT_COLOR_2=$WHITE; BACKGROUND_2=$D_GRAY; TEXTEFFECT_2=$BOLD
      FONT_COLOR_3=$WHITE; BACKGROUND_3=$RED; TEXTEFFECT_3=$BOLD
      PROMT_FORMAT=$RED_BOLD
   fi
   
   ## CONFIGURATION: RED-BLACK
   #FONT_COLOR_1=$WHITE; BACKGROUND_1=$RED; TEXTEFFECT_1=$BOLD
   #FONT_COLOR_2=$WHITE; BACKGROUND_2=$D_GRAY; TEXTEFFECT_2=$BOLD
   #FONT_COLOR_3=$WHITE; BACKGROUND_3=$BLACK; TEXTEFFECT_3=$BOLD
   #PROMT_FORMAT=$RED_BOLD

   ## CONFIGURATION: CYAN-BLUE
   if [ "$HOSTNAME" = sharkoon ]; then
      FONT_COLOR_1=$BLACK; BACKGROUND_1=$L_CYAN; TEXTEFFECT_1=$BOLD
      FONT_COLOR_2=$WHITE; BACKGROUND_2=$L_BLUE; TEXTEFFECT_2=$BOLD
      FONT_COLOR_3=$WHITE; BACKGROUND_3=$BLUE; TEXTEFFECT_3=$BOLD
      PROMT_FORMAT=$CYAN_BOLD
   fi
   
   ## CONFIGURATION: GRAY-SCALE
   if [ "$HOSTNAME" = giraff ]; then
      FONT_COLOR_1=$WHITE; BACKGROUND_1=$BLACK; TEXTEFFECT_1=$BOLD
      FONT_COLOR_2=$WHITE; BACKGROUND_2=$D_GRAY; TEXTEFFECT_2=$BOLD
      FONT_COLOR_3=$WHITE; BACKGROUND_3=$L_GRAY; TEXTEFFECT_3=$BOLD
      PROMT_FORMAT=$BLACK_BOLD
   fi
   
   ## CONFIGURATION: GRAY-CYAN
   if [ "$HOSTNAME" = light ]; then
      FONT_COLOR_1=$WHITE; BACKGROUND_1=$BLACK; TEXTEFFECT_1=$BOLD
      FONT_COLOR_2=$WHITE; BACKGROUND_2=$D_GRAY; TEXTEFFECT_2=$BOLD
      FONT_COLOR_3=$BLACK; BACKGROUND_3=$L_CYAN; TEXTEFFECT_3=$BOLD
      PROMT_FORMAT=$CYAN_BOLD
   fi
   
   
   ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ## 
     ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##
   ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##    

   
   
   
   ############################################################################
   ## TEXT FORMATING                                                         ##
   ## Generate the text formating according to configuration                 ##
   ############################################################################
   
   ## CONVERT CODES: add offset
   FC1=$(($FONT_COLOR_1+$COLOR))
   BG1=$(($BACKGROUND_1+$BG))
   FE1=$(($TEXTEFFECT_1+$EFFECT))
   
   FC2=$(($FONT_COLOR_2+$COLOR))
   BG2=$(($BACKGROUND_2+$BG))
   FE2=$(($TEXTEFFECT_2+$EFFECT))
   
   FC3=$(($FONT_COLOR_3+$COLOR))
   BG3=$(($BACKGROUND_3+$BG))
   FE3=$(($TEXTEFFECT_3+$EFFECT))
   
   FC4=$(($FONT_COLOR_4+$COLOR))
   BG4=$(($BACKGROUND_4+$BG))
   FE4=$(($TEXTEFFECT_4+$EFFECT))
   

   ## CALL FORMATING HELPER FUNCTION: effect + font color + BG color
   local TEXT_FORMAT_1
   local TEXT_FORMAT_2
   local TEXT_FORMAT_3
   local TEXT_FORMAT_4   
   format_font TEXT_FORMAT_1 $FE1 $FC1 $BG1
   format_font TEXT_FORMAT_2 $FE2 $FC2 $BG2
   format_font TEXT_FORMAT_3 $FC3 $FE3 $BG3
   format_font TEXT_FORMAT_4 $FC4 $FE4 $BG4
   
   
   # GENERATE PROMT SECTIONS
   local PROMT_USER=$"$TEXT_FORMAT_1 \u "
   local PROMT_HOST=$"$TEXT_FORMAT_2 \h "
   local PROMT_PWD=$"$TEXT_FORMAT_3 \${NEW_PWD} "
   local PROMT_INPUT=$"$PROMT_FORMAT "


   ############################################################################
   ## SEPARATOR FORMATING                                                    ##
   ## Generate the separators between sections                               ##
   ## Uses background colors of the sections                                 ##
   ############################################################################
   
   ## CONVERT CODES
   TSFC1=$(($BACKGROUND_1+$COLOR))
   TSBG1=$(($BACKGROUND_2+$BG))
   
   TSFC2=$(($BACKGROUND_2+$COLOR))
   TSBG2=$(($BACKGROUND_3+$BG))
   
   TSFC3=$(($BACKGROUND_3+$COLOR))
   TSBG3=$(($DEFAULT+$BG))
   

   ## CALL FORMATING HELPER FUNCTION: effect + font color + BG color
   local SEPARATOR_FORMAT_1
   local SEPARATOR_FORMAT_2
   local SEPARATOR_FORMAT_3
   format_font SEPARATOR_FORMAT_1 $TSFC1 $TSBG1
   format_font SEPARATOR_FORMAT_2 $TSFC2 $TSBG2
   format_font SEPARATOR_FORMAT_3 $TSFC3 $TSBG3
   

   # GENERATE SEPARATORS WITH FANCY TRIANGLE
   local TRIANGLE=$'\uE0B0'   
   local SEPARATOR_1=$SEPARATOR_FORMAT_1$TRIANGLE
   local SEPARATOR_2=$SEPARATOR_FORMAT_2$TRIANGLE
   local SEPARATOR_3=$SEPARATOR_FORMAT_3$TRIANGLE



   ############################################################################
   ## WINDOW TITLE                                                           ##
   ## Prevent messed up terminal-window titles                               ##
   ############################################################################
   case $TERM in
   xterm*|rxvt*)
      local TITLEBAR='\[\033]0;\u:${NEW_PWD}\007\]'
      ;;
   *)
      local TITLEBAR=""
      ;;
   esac



   ############################################################################
   ## BASH PROMT                                                             ##
   ## Generate promt and remove format from the rest                         ##
   ############################################################################
   PS1="$TITLEBAR\n${PROMT_USER}${SEPARATOR_1}${PROMT_HOST}${SEPARATOR_2}${PROMT_PWD}${SEPARATOR_3}${PROMT_INPUT}"

   

   ## For terminal line coloring, leaving the rest standard
   none="$(tput sgr0)"
   trap 'echo -ne "${none}"' DEBUG
}




################################################################################
##  MAIN                                                                      ##
################################################################################

##   Bash provides an environment variable called PROMPT_COMMAND.
##   The contents of this variable are executed as a regular Bash command
##   just before Bash displays a prompt.
##   We want it to call our own command to truncate PWD and store it in NEW_PWD
PROMPT_COMMAND=bash_prompt_command

##   Call bash_promnt only once, then unset it (not needed any more)
##   It will set $PS1 with colors and relative to $NEW_PWD,
##   which gets updated by $PROMT_COMMAND on behalf of the terminal
bash_prompt
unset bash_prompt



### EOF ###
[close]

If you have the terminal opened then close it and reopen to see the change.


This was made for the user but if you type in the terminal
Code: [Select]
sudo su
and enter you password you will notice that when on root privileges the terminal show the default look.
In order to change it we also need to do the the same thing to the .bashrc file on our system root folder.
Now that you seen that the Terminal when on root privileges havent changed close terminal and reopen it.

Step 4. Modifying the .bashrc file on root, the friendly way
First step is making a backup of the .bashrc file on the root folder with command line bellow:

Code: [Select]
sudo cp -v /root/.bashrc /root/.bashrc.bak

Enter your password when asked and press enter.
Now that the backup file was made lets modify the original, so lets open it with a simple command line:

Code: [Select]
sudo xed /root/.bashrc

Enter your password if asked, you are now in the Xed text editor with elevated privileges, copy the code provided on Step 3 and paste it to the end of the file, save it with (Ctrl+s) and exit (Ctrl+q)

To see if the changes were applied correctly type
Code: [Select]
sudo su
on the terminal and enter your password when asked.

Alternative way to do Step 4,I ADVISE DOING THE COMMAND LINE METHOD
Spoiler (click here to view / hide)



When opening the root folder it will ask for your, root password.

Again i strongly advice make a backup of the .bashrc file on the root

We just need to make the same steps as on Step.3 but on root folder.
[close]

Hope this guide helps bring some bling bling to your terminal and sorry if there was already a guide for this.

Credits:
Chris Titus Tech video tutorial.
Andres Gongora for the script.
AndyInMokum for the safer way to modify the root file.

Bellow is the full script:
Spoiler (click here to view / hide)
#!/bin/sh

##   +-----------------------------------+-----------------------------------+
##   |                                                                       |
##   |                            FANCY BASH PROMT                           |
##   |                                                                       |
##   | Copyright (c) 2018, Andres Gongora <mail@andresgongora.com>.          |
##   |                                                                       |
##   | This program is free software: you can redistribute it and/or modify  |
##   | it under the terms of the GNU General Public License as published by  |
##   | the Free Software Foundation, either version 3 of the License, or     |
##   | (at your option) any later version.                                   |
##   |                                                                       |
##   | This program is distributed in the hope that it will be useful,       |
##   | but WITHOUT ANY WARRANTY; without even the implied warranty of        |
##   | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         |
##   | GNU General Public License for more details.                          |
##   |                                                                       |
##   | You should have received a copy of the GNU General Public License     |
##   | along with this program. If not, see <http://www.gnu.org/licenses/>.  |
##   |                                                                       |
##   +-----------------------------------------------------------------------+


##
##   DESCRIPTION:
##   This script updates your "PS1" environment variable to display colors.
##   Addicitionally, it also shortens the name of your current part to maximum
##   25 characters, which is quite useful when working in deeply nested folders.
##
##
##
##   INSTALLATION:
##   Copy this script to your home folder and rename it to ".fancy-bash-promt.sh"
##   Run this command from any terminal:
##      echo "source ~/.fancy-bash-promt.sh" >> ~/.bashrc
##
##   Alternatively, copy the content of this file into your .bashrc file
##
##
##
##   FUNCTIONS:
##
##   * bash_prompt_command()
##     This function takes your current working directory and stores a shortened
##     version in the variable "NEW_PWD".
##
##   * format_font()
##     A small helper function to generate color formating codes from simple
##     number codes (defined below as local variables for convenience).
##
##   * bash_prompt()
##     This function colorizes the bash promt. The exact color scheme can be
##     configured here. The structure of the function is as follows:
##      1. A. Definition of available colors for 16 bits.
##      1. B. Definition of some colors for 256 bits (add your own).
##      2. Configuration >> EDIT YOUR PROMT HERE<<.
##      4. Generation of color codes.
##      5. Generation of window title (some terminal expect the first
##         part of $PS1 to be the window title)
##      6. Formating of the bash promt ($PS1).
##
##   * Main script body:   
##     It calls the adequate helper functions to colorize your promt and sets
##     a hook to regenerate your working directory "NEW_PWD" when you change it.
##




################################################################################
##  FUNCTIONS                                                                 ##
################################################################################

##
##   ARRANGE $PWD AND STORE IT IN $NEW_PWD
##   * The home directory (HOME) is replaced with a ~
##   * The last pwdmaxlen characters of the PWD are displayed
##   * Leading partial directory names are striped off
##      /home/me/stuff -> ~/stuff (if USER=me)
##      /usr/share/big_dir_name -> ../share/big_dir_name (if pwdmaxlen=20)
##
##   Original source: WOLFMAN'S color bash promt
##   https://wiki.chakralinux.org/index.php?title=Color_Bash_Prompt#Wolfman.27s
##
bash_prompt_command() {
   # How many characters of the $PWD should be kept
   local pwdmaxlen=25

   # Indicate that there has been dir truncation
   local trunc_symbol=".."

   # Store local dir
   local dir=${PWD##*/}

   # Which length to use
   pwdmaxlen=$(( ( pwdmaxlen < ${#dir} ) ? ${#dir} : pwdmaxlen ))

   NEW_PWD=${PWD/#$HOME/\~}
   
   local pwdoffset=$(( ${#NEW_PWD} - pwdmaxlen ))

   # Generate name
   if [ ${pwdoffset} -gt "0" ]
   then
      NEW_PWD=${NEW_PWD:$pwdoffset:$pwdmaxlen}
      NEW_PWD=${trunc_symbol}/${NEW_PWD#*/}
   fi
}




##
##   GENERATE A FORMAT SEQUENCE
##
format_font()
{
   ## FIRST ARGUMENT TO RETURN FORMAT STRING
   local output=$1


   case $# in
   2)
      eval $output="'\[\033[0;${2}m\]'"
      ;;
   3)
      eval $output="'\[\033[0;${2};${3}m\]'"
      ;;
   4)
      eval $output="'\[\033[0;${2};${3};${4}m\]'"
      ;;
   *)
      eval $output="'\[\033[0m\]'"
      ;;
   esac
}



##
## COLORIZE BASH PROMT
##
bash_prompt() {

   ############################################################################
   ## COLOR CODES                                                            ##
   ## These can be used in the configuration below                           ##
   ############################################################################
   
   ## FONT EFFECT
   local      NONE='0'
   local      BOLD='1'
   local       DIM='2'
   local UNDERLINE='4'
   local     BLINK='5'
   local    INVERT='7'
   local    HIDDEN='8'
   
   
   ## COLORS
   local   DEFAULT='9'
   local     BLACK='0'
   local       RED='1'
   local     GREEN='2'
   local    YELLOW='3'
   local      BLUE='4'
   local   MAGENTA='5'
   local      CYAN='6'
   local    L_GRAY='7'
   local    D_GRAY='60'
   local     L_RED='61'
   local   L_GREEN='62'
   local  L_YELLOW='63'
   local    L_BLUE='64'
   local L_MAGENTA='65'
   local    L_CYAN='66'
   local     WHITE='67'
   
   
   ## TYPE
   local     RESET='0'
   local    EFFECT='0'
   local     COLOR='30'
   local        BG='40'
   
   
   ## 256 COLOR CODES
   local NO_FORMAT="\[\033[0m\]"
   local ORANGE_BOLD="\[\033[1;38;5;208m\]"
   local TOXIC_GREEN_BOLD="\[\033[1;38;5;118m\]"
   local RED_BOLD="\[\033[1;38;5;1m\]"
   local CYAN_BOLD="\[\033[1;38;5;87m\]"
   local BLACK_BOLD="\[\033[1;38;5;0m\]"
   local WHITE_BOLD="\[\033[1;38;5;15m\]"
   local GRAY_BOLD="\[\033[1;90m\]"
   local BLUE_BOLD="\[\033[1;38;5;74m\]"
   
   
   
   
   
   ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ## 
     ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##
   ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##

   
   
   ##                          CONFIGURE HERE                                ##

   
   
   ############################################################################
   ## CONFIGURATION                                                          ##
   ## Choose your color combination here                                     ##
   ############################################################################
   local FONT_COLOR_1=$WHITE
   local BACKGROUND_1=$BLUE
   local TEXTEFFECT_1=$BOLD
   
   local FONT_COLOR_2=$WHITE
   local BACKGROUND_2=$L_BLUE
   local TEXTEFFECT_2=$BOLD
   
   local FONT_COLOR_3=$D_GRAY
   local BACKGROUND_3=$WHITE
   local TEXTEFFECT_3=$BOLD
   
   local PROMT_FORMAT=$BLUE_BOLD

   
   ############################################################################
   ## EXAMPLE CONFIGURATIONS                                                 ##
   ## I use them for different hosts. Test them out ;)                       ##
   ############################################################################
   
   ## CONFIGURATION: BLUE-WHITE
   if [ "$HOSTNAME" = dell ]; then
      FONT_COLOR_1=$WHITE; BACKGROUND_1=$BLUE; TEXTEFFECT_1=$BOLD
      FONT_COLOR_2=$WHITE; BACKGROUND_2=$L_BLUE; TEXTEFFECT_2=$BOLD   
      FONT_COLOR_3=$D_GRAY; BACKGROUND_3=$WHITE; TEXTEFFECT_3=$BOLD   
      PROMT_FORMAT=$CYAN_BOLD
   fi
   
   ## CONFIGURATION: BLACK-RED
   if [ "$HOSTNAME" = giraff6 ]; then
      FONT_COLOR_1=$WHITE; BACKGROUND_1=$BLACK; TEXTEFFECT_1=$BOLD
      FONT_COLOR_2=$WHITE; BACKGROUND_2=$D_GRAY; TEXTEFFECT_2=$BOLD
      FONT_COLOR_3=$WHITE; BACKGROUND_3=$RED; TEXTEFFECT_3=$BOLD
      PROMT_FORMAT=$RED_BOLD
   fi
   
   ## CONFIGURATION: RED-BLACK
   #FONT_COLOR_1=$WHITE; BACKGROUND_1=$RED; TEXTEFFECT_1=$BOLD
   #FONT_COLOR_2=$WHITE; BACKGROUND_2=$D_GRAY; TEXTEFFECT_2=$BOLD
   #FONT_COLOR_3=$WHITE; BACKGROUND_3=$BLACK; TEXTEFFECT_3=$BOLD
   #PROMT_FORMAT=$RED_BOLD

   ## CONFIGURATION: CYAN-BLUE
   if [ "$HOSTNAME" = sharkoon ]; then
      FONT_COLOR_1=$BLACK; BACKGROUND_1=$L_CYAN; TEXTEFFECT_1=$BOLD
      FONT_COLOR_2=$WHITE; BACKGROUND_2=$L_BLUE; TEXTEFFECT_2=$BOLD
      FONT_COLOR_3=$WHITE; BACKGROUND_3=$BLUE; TEXTEFFECT_3=$BOLD
      PROMT_FORMAT=$CYAN_BOLD
   fi
   
   ## CONFIGURATION: GRAY-SCALE
   if [ "$HOSTNAME" = giraff ]; then
      FONT_COLOR_1=$WHITE; BACKGROUND_1=$BLACK; TEXTEFFECT_1=$BOLD
      FONT_COLOR_2=$WHITE; BACKGROUND_2=$D_GRAY; TEXTEFFECT_2=$BOLD
      FONT_COLOR_3=$WHITE; BACKGROUND_3=$L_GRAY; TEXTEFFECT_3=$BOLD
      PROMT_FORMAT=$BLACK_BOLD
   fi
   
   ## CONFIGURATION: GRAY-CYAN
   if [ "$HOSTNAME" = light ]; then
      FONT_COLOR_1=$WHITE; BACKGROUND_1=$BLACK; TEXTEFFECT_1=$BOLD
      FONT_COLOR_2=$WHITE; BACKGROUND_2=$D_GRAY; TEXTEFFECT_2=$BOLD
      FONT_COLOR_3=$BLACK; BACKGROUND_3=$L_CYAN; TEXTEFFECT_3=$BOLD
      PROMT_FORMAT=$CYAN_BOLD
   fi
   
   
   ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ## 
     ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##
   ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##    

   
   
   
   ############################################################################
   ## TEXT FORMATING                                                         ##
   ## Generate the text formating according to configuration                 ##
   ############################################################################
   
   ## CONVERT CODES: add offset
   FC1=$(($FONT_COLOR_1+$COLOR))
   BG1=$(($BACKGROUND_1+$BG))
   FE1=$(($TEXTEFFECT_1+$EFFECT))
   
   FC2=$(($FONT_COLOR_2+$COLOR))
   BG2=$(($BACKGROUND_2+$BG))
   FE2=$(($TEXTEFFECT_2+$EFFECT))
   
   FC3=$(($FONT_COLOR_3+$COLOR))
   BG3=$(($BACKGROUND_3+$BG))
   FE3=$(($TEXTEFFECT_3+$EFFECT))
   
   FC4=$(($FONT_COLOR_4+$COLOR))
   BG4=$(($BACKGROUND_4+$BG))
   FE4=$(($TEXTEFFECT_4+$EFFECT))
   

   ## CALL FORMATING HELPER FUNCTION: effect + font color + BG color
   local TEXT_FORMAT_1
   local TEXT_FORMAT_2
   local TEXT_FORMAT_3
   local TEXT_FORMAT_4   
   format_font TEXT_FORMAT_1 $FE1 $FC1 $BG1
   format_font TEXT_FORMAT_2 $FE2 $FC2 $BG2
   format_font TEXT_FORMAT_3 $FC3 $FE3 $BG3
   format_font TEXT_FORMAT_4 $FC4 $FE4 $BG4
   
   
   # GENERATE PROMT SECTIONS
   local PROMT_USER=$"$TEXT_FORMAT_1 \u "
   local PROMT_HOST=$"$TEXT_FORMAT_2 \h "
   local PROMT_PWD=$"$TEXT_FORMAT_3 \${NEW_PWD} "
   local PROMT_INPUT=$"$PROMT_FORMAT "


   ############################################################################
   ## SEPARATOR FORMATING                                                    ##
   ## Generate the separators between sections                               ##
   ## Uses background colors of the sections                                 ##
   ############################################################################
   
   ## CONVERT CODES
   TSFC1=$(($BACKGROUND_1+$COLOR))
   TSBG1=$(($BACKGROUND_2+$BG))
   
   TSFC2=$(($BACKGROUND_2+$COLOR))
   TSBG2=$(($BACKGROUND_3+$BG))
   
   TSFC3=$(($BACKGROUND_3+$COLOR))
   TSBG3=$(($DEFAULT+$BG))
   

   ## CALL FORMATING HELPER FUNCTION: effect + font color + BG color
   local SEPARATOR_FORMAT_1
   local SEPARATOR_FORMAT_2
   local SEPARATOR_FORMAT_3
   format_font SEPARATOR_FORMAT_1 $TSFC1 $TSBG1
   format_font SEPARATOR_FORMAT_2 $TSFC2 $TSBG2
   format_font SEPARATOR_FORMAT_3 $TSFC3 $TSBG3
   

   # GENERATE SEPARATORS WITH FANCY TRIANGLE
   local TRIANGLE=$'\uE0B0'   
   local SEPARATOR_1=$SEPARATOR_FORMAT_1$TRIANGLE
   local SEPARATOR_2=$SEPARATOR_FORMAT_2$TRIANGLE
   local SEPARATOR_3=$SEPARATOR_FORMAT_3$TRIANGLE



   ############################################################################
   ## WINDOW TITLE                                                           ##
   ## Prevent messed up terminal-window titles                               ##
   ############################################################################
   case $TERM in
   xterm*|rxvt*)
      local TITLEBAR='\[\033]0;\u:${NEW_PWD}\007\]'
      ;;
   *)
      local TITLEBAR=""
      ;;
   esac



   ############################################################################
   ## BASH PROMT                                                             ##
   ## Generate promt and remove format from the rest                         ##
   ############################################################################
   PS1="$TITLEBAR\n${PROMT_USER}${SEPARATOR_1}${PROMT_HOST}${SEPARATOR_2}${PROMT_PWD}${SEPARATOR_3}${PROMT_INPUT}"

   

   ## For terminal line coloring, leaving the rest standard
   none="$(tput sgr0)"
   trap 'echo -ne "${none}"' DEBUG
}




################################################################################
##  MAIN                                                                      ##
################################################################################

##   Bash provides an environment variable called PROMPT_COMMAND.
##   The contents of this variable are executed as a regular Bash command
##   just before Bash displays a prompt.
##   We want it to call our own command to truncate PWD and store it in NEW_PWD
PROMPT_COMMAND=bash_prompt_command

##   Call bash_promnt only once, then unset it (not needed any more)
##   It will set $PS1 with colors and relative to $NEW_PWD,
##   which gets updated by $PROMT_COMMAND on behalf of the terminal
bash_prompt
unset bash_prompt



### EOF ###

[close]
« Last Edit: February 11, 2020, 05:44:43 am by TheAkantor »

Online VinDSL

  • Administrator
  • Hero
  • *****
  • Posts: 5730
  • Karma: 1085
  • Team Peppermint
    • View Profile
  • Peppermint version(s): Developmental Builds
Re: How to bring a little bling bling to your Terminal
« Reply #1 on: February 07, 2020, 08:30:51 am »
Good job!   :)








Offline compicat

  • Newly Subscribed
  • *
  • Posts: 9
  • Karma: 1
  • New Forum User
    • View Profile
  • Peppermint version(s): Peppermint 10
Re: How to bring a little bling bling to your Terminal
« Reply #2 on: February 10, 2020, 05:10:47 pm »
Thanks for great share.

Offline AndyInMokum

  • Global Moderator
  • Hero
  • *****
  • Posts: 4889
  • Karma: 1058
  • "Keep on Rockin' in the Free World"
    • View Profile
  • Peppermint version(s): PM 9 & PM 10 (64-bit)
Re: How to bring a little bling bling to your Terminal
« Reply #3 on: February 10, 2020, 06:10:17 pm »
Nice job  ;).  However, I'm going to make a couple of constructive criticisms.  There is no need to drop to root user in the terminal.  In fact, I strongly recommend it's not done unless absolutely necessary.  There are too many new Linux users trying out PeppermintOS.  Dropping to root is courting disaster  :'(.  I strongly recommend using these command to first back up /root/.bashrc:
Code: [Select]
sudo cp -v /root/.bashrc /root/.bashrc.bak
Enter your user password when asked, hit enter and you're done.  To open /root/.bashrc using the Xed text editor as root:
Code: [Select]
sudo xed /root/.bashrc
Enter your user password if asked.  Xed will open up with elevated privileges.  Make the edits and save, (Ctrl+s).  Exit Xed, (Ctrl+q).  Doing things this way leaves nothing in the terminal as root  ;).

Backup! Backup! Backup! If you're missing any of these -  you ain't Backed Up!
For my system info please L/click HERE.

Offline TheAkantor

  • Newly Subscribed
  • *
  • Posts: 24
  • Karma: 8
  • New Forum User
    • View Profile
  • Peppermint version(s): Peppermint 10 Respin
Re: How to bring a little bling bling to your Terminal
« Reply #4 on: February 11, 2020, 03:27:28 am »
Thank you both, about that command line wasnt aware of it, anyway im a noob myself have alot to learn and that sure is a safer way to edit the root file.
Constructive criticism is always welcome, ill edit the topic later with your tip since im on the phone now.

Offline Slim.Fatz

  • Global Moderator
  • Veteran
  • *****
  • Posts: 2201
  • Karma: 593
  • Where's the mouse?
    • View Profile
  • Peppermint version(s): Peppermint 7, 8.5 & 10 - 64bit
Re: How to bring a little bling bling to your Terminal
« Reply #5 on: February 11, 2020, 03:37:30 am »
Hi TheAkantor,

Thanks for for the tutorial and for planning the change concerning the use of the root terminal. I was actually considering using my Global Mod status to make this change just to make it less risky.  ;) But I prefer to let the original author (in this case: you) make such changes.  8)

Regards,

-- Slim
"Life first -- Peppermint a close 2nd!" -- Zeb

Tread lightly: Fluxbox, JWM, i3, Openbox, awesome

Offline TheAkantor

  • Newly Subscribed
  • *
  • Posts: 24
  • Karma: 8
  • New Forum User
    • View Profile
  • Peppermint version(s): Peppermint 10 Respin
Re: How to bring a little bling bling to your Terminal
« Reply #6 on: February 11, 2020, 05:09:26 am »
Hi, im back just modified the instructions hope its more clear, i ended lefting the old one for root also but on a spoiler and advising to do the command line option instead. Feel free to edit if needed.

Offline AndyInMokum

  • Global Moderator
  • Hero
  • *****
  • Posts: 4889
  • Karma: 1058
  • "Keep on Rockin' in the Free World"
    • View Profile
  • Peppermint version(s): PM 9 & PM 10 (64-bit)
Re: How to bring a little bling bling to your Terminal
« Reply #7 on: February 11, 2020, 07:54:38 am »
Hi, im back just modified the instructions hope its more clear, i ended lefting the old one for root also but on a spoiler and advising to do the command line option instead. Feel free to edit if needed.

Thanks TheAkantor for that, you've just made working will elevated privileges much safer :).  Especially for new Linux users ;).  Working as root is really unforgiving.  You don't get the chance to review your changes.  One you hit the enter key, there's no turning back :o.  When using sudo, you have a safety net.  You're asked for your password and if you want to continue.  It doesn't eliminate screw ups; however, along with good backing up habits, it does seriously reduce the chances of screw ups ;D.

Some distros work as root by default.  Kali is one such distro.  This is a very specialized Debian based distro, designed for network diagnostics.  Its main users are professional network specialists.  Distros like Kali, are very much the exception to the rule though ;).
Backup! Backup! Backup! If you're missing any of these -  you ain't Backed Up!
For my system info please L/click HERE.