自 GNOME40 尝鲜以来已许久再未摸过桌面发行版,ZSH 似乎成了唯一能够在终端上聊以慰藉的工具,但是每每搭建新的虚拟机总是不可避免的重复如下步骤:

apt install -y zsh
apt install -y fonts-powerlinecurl -O https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh
sed -i 's/-ohmyzsh\/ohmyzsh/-mirrors\/oh-my-zsh/g' install.sh
sed -i 's/-https:\/\/github.com\/${REPO}.git/-https:\/\/gitee.com\/${REPO}.git/g' install.sh
./install.shchsh -s $(which zsh) root
sed -i 's/ZSH_THEME="robbyrussell"/ZSH_THEME="ys"/g' ~/.zshrc
echo "alias ll='ls -alhF --time-style=long-iso'" >> ~/.zshrc

然而 ZSH 通过三两条命令搞定针对所有用户的默认配置,似乎并不是特别的容易。

后来慢慢摸索着发现搞定 Bash 默认配置实际上容易很多。比如 ubuntu 上 root 用户没有着色,可以直接拿模板用户去覆盖 root 用户:

cp /etc/skel/.bashrc ~/

再进一步甚至可以在/etc/bash.bashrcPS1相关配置之后添加源于/etc/skel/.bashrc的以下内容:

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yesif [ -n "$force_color_prompt" ]; thenif [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then# We have color support; assume it's compliant with Ecma-48# (ISO/IEC-6429). (Lack of such support is extremely rare, and such# a case would tend to support setf rather than setaf.)color_prompt=yeselsecolor_prompt=fi
fiif [ "$color_prompt" = yes ]; thenPS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
elsePS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

再取消代码补全相关的注释,如此每个新用户即可直接:

# 直接删除
rm ~/.bashrc# ubuntu 默认 /etc/profille 会去加载 /etc/bash.bashrc 而 centos 默认需要手动 source /etc/bashrc
source /etc/profile

然而 centos 中的PS1却没有可以直接 Ctrl+C、Ctrl+V 的来源,大概搜了下(https://www.cnblogs.com/iois/p/11665825.html)其中配色方案大致按照\[\e<A>;<B>;<F>m\]的顺序组合:

文本属性(A) 背景颜色(B) 文本颜色(F)
00:重置文本和背景 40:黑色 30:黑色
01:设置高亮度 41:红色 31:红色
04:下划线 42:绿色 32:绿色
05:闪烁 43:黄色 33:黄色
07:反显 44:蓝色 34:蓝色
08:消隐 45:紫色 35:紫色
46:青色 36:青色
47:白色 37:白色

于是就可以试试:

export PS1='[\[\e[01;05;32m\]\u\[\e[00m\]@\[\e[01;33m\]\h\[\e[00m\]:\[\e[01;34m\]\w\[\e[00m\]]\$ '


更改到 centos 的/etc/bashrc中即可永久生效。为了使得 centos 和 ubuntu 的行为一致,可以在/etc/profile中也去加载/etc/bashrc

cat >> /etc/profile << EOF
if [ -f /etc/bashrc ]; then . /etc/bashrc
fi
EOFsource /etc/profile

【Linux】Bash的折衷美化方案——PS1相关推荐

  1. linux bash 字符串 连接,Linux Bash 中字符串操作

    Linux Bash 中字符串操作 所谓 "子字符串" 就是出现在其它字符串内的字符串. 比如 "3382" 就是 "this is a 3382 t ...

  2. linux bash技巧_Bash提示技巧和窍门

    linux bash技巧 在Linux中启动终端的任何人都熟悉默认的Bash提示符: [ user @ $host ~ ] $ 但是您知道这是完全可定制的并且可以包含一些非常有用的信息吗? 这里有一些 ...

  3. Linux Bash漏洞最新最全的修复方法

    原文链接:Linux Bash漏洞测试方法与修复方法http://www.jishubu.net/yunwei/anquan/382.html Linux 用户今天又得到了一个"惊喜&quo ...

  4. Linux bash命令

    查看当前用户 whoami 查看当前路径 pwd ~ 用户的家目录, /root  /home/yangxinxin 主机名 hostname PS1变量控制 PS1='[\u@\h \W]\$ ' ...

  5. linux bash 变量_如何在Linux上的Bash中设置环境变量

    linux bash 变量 fatmawati achmad zaenuri/Shutterstock Fatmawati achmad zaenuri / Shutterstock There's ...

  6. Linux下的中文美化问题

    明明白白安装中文字体 转http://www.fwolf.com/blog/post/170 Ubuntu 6.06 dapper对中文的支持应该说是一向不错的,包括现在默认安装就包含了scim输入法 ...

  7. 脚本 linux bash PowerShell、alibaba clound toolkit OpenSSH

    ##linux bash 和 windows powershell 老旧的cmd (command) 一. bash shell用途 运维命令: linux bash:linux 使用bash 发布j ...

  8. linux中感叹号的作用,感叹号在Linux bash中使用技巧

    1. 重复执行上一条指令  !! [root@iZ23t6nzr7dZ python]# ls /usr/local/ aegis bin etc games include lib lib64 li ...

  9. Linux Bash小结1

    1.Linux Bash变量类型 A 本地变量 B 环境变量 C 位置变量 D 特殊变量 需要注意的是: 父SHELL和子SHELL是两个不同的进程,他们不会共享本地变量. 环境变量对当前SHELL及 ...

最新文章

  1. 剑指offer:给定一个数组A[0,1,...,n-1],请构建一个数组B[0,1,..,n-1],其中B中的元素B[i]=A[0]*A[1]*...*A[i-1]*A[i+1]*...*A[n-1]
  2. research meeting updates points
  3. Linux 指令篇:档案目录管理--chown
  4. 170329、用 Maven 部署 war 包到远程 Tomcat 服务器
  5. oracle进程用户,关于oracle用户进程,服务进程,后…
  6. 【python】python 爬虫(python抓取网站的图片)
  7. Unity中Android API 28之后无法HTTP请求
  8. spyder python调试查看类信息_使用Spyder进行Python调试
  9. 数据库设计:范式与反范式
  10. javascript 搜索并高亮显示
  11. 使用CrossFTP跨越不同站点复制/移动数据
  12. 特斯拉为什么要“干掉”保险丝和继电器?
  13. Linux如何搜索查找文件里面内容
  14. MATLAB2018B下用Faster-RCNN做目标检测的训练和测试步骤
  15. MSP430单片机GPIO编程入门教程
  16. 交付管理——怎样管控项目成本
  17. java中文转拼音_java中文转拼音
  18. OpenStack和Open Source MANO:NFV部署两大支柱
  19. 2019瓜子网后台开发笔试题目
  20. 批量下载抖音快手视频

热门文章

  1. Windows10企业版下载与安装教程
  2. 要提高情商,我推荐你看这本书
  3. 3GPP LTE中的OFDMA和SC-FDMA性能比较
  4. windows下jenkins的安装
  5. Winyao 推出了8125-mPC系列2.5G Mini PCIE 的网卡.RTL8125B芯片
  6. 机器学习从公理到算法
  7. 悟空crm环境部署-Java的war包方式
  8. Indent tool and KR code style
  9. ScreenFlow 9.0.1中文汉化
  10. 从 0 到 1 用 Vue 封装一个日历组件