Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Beautify Linux terminals and Shell prompts

2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report