Get the App
SLTechnology News&Howtos  ›  Servers  › 

Beautify Linux terminals and Shell prompts

Shulou Source: shulou.com Published: 2022-06-02 05:45:55 10月06日 Update

In this article, we'll show you some simple and interesting Linux tips, and we'll show you how to make your terminal and shell have beautiful character capabilities. At the end of this guide, you will learn how to customize the shell prompt using Bash variables and escape characters.

In Bash, you can add emoticons, change colors, add font styles, and run commands that are executed each time you draw a prompt, such as displaying git branches.

To customize the Linux shell prompt to suit this holiday season, you need to make some changes to your ~ / .bashrc file.

$nano ~ / .bashrc

Add the following to the end of your ~ / .bashrc file

# print the git branch name if in a git projectparse_git_branch () {git branch 2 > / dev/null | sed-e'/ ^ [^ *] / d'-e's account *\ (. *\) / /'} # set the input prompt symbolARROW= "❯" # define text formattingPROMPT_BOLD= "$(tput bold)" PROMPT_UNDERLINE= "$(tput smul)" PROMPT_FG_GREEN= "$(tput setaf 2)" PROMPT_FG_CYAN= "$(tput setaf 6)" PROMPT_FG _ YELLOW= "$(tput setaf 3)" PROMPT_FG_MAGENTA= "$(tput setaf 5)" PROMPT_RESET= "$(tput sgr0)" # save each section prompt section in variablePROMPT_SECTION_SHELL= "\ [$PROMPT_BOLD$PROMPT_FG_GREEN\]\ s\ [$PROMPT_RESET\]" PROMPT_SECTION_DIRECTORY= "\ [$PROMPT_UNDERLINE$PROMPT_FG_CYAN\]\ W\ [$PROMPT_RESET\]" PROMPT_SECTION_GIT_BRANCH= "\ [$PROMPT_FG_YELLOW\]\ `parse _ git_branch\ `\ [$PROMPT_RESET\] "PROMPT_SECTION_ARROW="\ [$PROMPT_FG_MAGENTA\] $ARROW\ [$PROMPT_RESET\] "# set the prompt string using each section variablePS1="? $PROMPT_SECTION_SHELL?? $PROMPT_SECTION_DIRECTORY? $PROMPT_SECTION_GIT_BRANCH?? $PROMPT_SECTION_ARROW "

Save the file and close it.

To make the changes work, you can close and reopen the terminal window, or use the following command to load the modified settings immediately to make them take effect.

$source ~ / .bashrc

In this article, we showed how to beautify the terminal and shell prompts in Linux, as well as how to customize the shell prompt using Bash variables and escape characters. I hope you like it.

The original text is from: https://www.linuxprobe.com/linux-shell-prompt.html

Tags: Prompts prompts terminals characters files variables commands escapes interesting beautiful festival content branches functions original text fonts techniques guides endings styles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Linux Docker Microsoft MariaDB