linux终端美化 oh-my-bash安装

之前一直在用zsh终端,然后安装oh-my-zsh,配置后感觉特别清爽,于是想bash终端下是否存在类似的软件,找了下发现了oh-my-bash。特记录下安装使用过程
oh my bash官网:https://ohmybash.nntoan.com/
oh my bash github:https://github.com/ohmybash/oh-my-bash

系统终端SHELL类型确认

# 查看当前shell类型
root@node01:~# echo $SHELL
/bin/bash
root@node01:~#
# 查看当前系统信息
root@node01:~# lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 22.04.4 LTS
Release:	22.04
Codename:	jammy
root@node01:~#

安装oh my bash

# 备份现有的.bashrc文件
root@node01:~# cp ~/.bashrc ~/.bashrc.orig
root@node01:~#
# 安装并应用 oh my bash
root@node01:~# bash -c "$(curl -fsSL https://raw.githubusercontent.com/ohmybash/oh-my-bash/master/tools/install.sh)"
Cloning Oh My Bash...
$ git clone --depth=1 https://github.com/ohmybash/oh-my-bash.git /root/.oh-my-bash
Cloning into '/root/.oh-my-bash'...
remote: Enumerating objects: 490, done.
remote: Counting objects: 100% (490/490), done.
remote: Compressing objects: 100% (454/454), done.
remote: Total 490 (delta 26), reused 335 (delta 22), pack-reused 0 (from 0)
Receiving objects: 100% (490/490), 4.01 MiB | 5.72 MiB/s, done.
Resolving deltas: 100% (26/26), done.
Looking for an existing bash config...
Found ~/.bashrc. Backing up to /root/.bashrc.omb-backup-20241115113454
$ mv /root/.bashrc /root/.bashrc.omb-backup-20241115113454
Copying the Oh-My-Bash template file to ~/.bashrc
$ mv -f /root/.bashrc.omb-temp /root/.bashrc
         __                          __               __
  ____  / /_     ____ ___  __  __   / /_  ____ ______/ /_
 / __ \/ __ \   / __ `__ \/ / / /  / __ \/ __ `/ ___/ __ \
/ /_/ / / / /  / / / / / / /_/ /  / /_/ / /_/ (__  ) / / /
\____/_/ /_/  /_/ /_/ /_/\__, /  /_.___/\__,_/____/_/ /_/
                        /____/                            .... is now installed!
Please look over the ~/.bashrc file to select a theme, plugins, completions, aliases, and options
To keep up on the latest news and updates, follow us on GitHub: https://github.com/ohmybash/oh-my-bash
11:34:55 root@node01 ~ →

修改oh my bash主题

  • 查看安装完成后默认存在的主题
# 查看当前存在的主题
11:36:03 root@node01 ~ → ls ~/.oh-my-bash/themes/
90210                        font                    powerline-naked
THEMES.md                    gallifrey               powerline-plain
absimple                     garo                    powerline-wizard
agnoster                     half-life               primer
axin                         hawaii50                pro
bakke                        ht                      pure
binaryanomaly                iterate                 purity
bobby                        kitsune                 pzq
bobby-python                 lambda                  rainbowbrite
brainy                       luan                    rana
brunton                      mairan                  rjorgenson
candy                        mbriggs                 robbyrussell
clean                        minimal                 roderik
cooperkid                    minimal-gh              rr
cupcake                      modern                  sexy
demula                       modern-t                simple
developer                    morris                  sirup
dos                          n0qorg                  slick
doubletime                   nwinkler                standard
doubletime_multiline         nwinkler_random_colors  tonka
doubletime_multiline_pyonly  pete                    tonotdo
dulcie                       powerbash10k            tylenol
duru                         powerline               vscode
edsonarios                   powerline-icon          wanelo
emperor                      powerline-light         zitron
envy                         powerline-multiline     zork
11:36:08 root@node01 ~ →
  • 修改oh my bash主题为robbyrussell,关键词为.bashrc内的OSH_THEME
# 修改当前注入为robbyrussell
11:39:02 root@node01 ~ → cat ~/.bashrc | grep "OSH_THEME"
#OSH_THEME="font"
OSH_THEME="robbyrussell"
# If you set OSH_THEME to "random", you can ignore themes you don't like.
11:39:12 root@node01 ~ →
  • 加载修改后的.bashrc配置,使其生效
# 加载配置文件,使其生效
11:41:05 root@node01 ~ → source .bashrc

➜  ~
➜  ~ uname -a
Linux node01.sec.lab 5.15.0-124-generic #134-Ubuntu SMP Fri Sep 27 20:20:17 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
➜  ~

修改robbyrussell主题显示内容

  • 默认robbyrussell不显示主机名和用户名,存在多台机器时无法区分,故对原有配置进行配置增加
root@node01 ➜  ~ cat ~/.oh-my-bash/themes/robbyrussell/robbyrussell.theme.sh
#! bash oh-my-bash.module

# This theme attempts to replicate the default "robbyrussell" theme from ohmyzsh:
#  https://github.com/ohmyzsh/ohmyzsh/blob/master/themes/robbyrussell.zsh-theme

# Example outside git repo:
# ➜  ~
# Example inside clean git repo:
# ➜  config-files git:(main)
# Example inside dirty git repo:
# ➜  config-files git:(main ?:1) ✗
# Example with virtual environment:
# ➜  (env1) ~
# Example with virtual environment and inside git repo:
# ➜  (env1) config-files git:(main)
# python_venv setup
OMB_PROMPT_VIRTUALENV_FORMAT='(%s) '
OMB_PROMPT_SHOW_PYTHON_VENV=${OMB_PROMPT_SHOW_PYTHON_VENV:=true}

function _omb_theme_PROMPT_COMMAND() {
    if [[ "$?" == 0 ]]; then
        local arrow_color="${_omb_prompt_bold_green}"
    else
        local arrow_color="${_omb_prompt_bold_brown}"
    fi
    # set the python_venv format
    local python_venv; _omb_prompt_get_python_venv
    python_venv="$_omb_prompt_olive$python_venv"
    local base_directory="${_omb_prompt_bold_teal}\W${_omb_prompt_reset_color}"
    local GIT_THEME_PROMPT_PREFIX="${_omb_prompt_bold_navy}git:(${_omb_prompt_bold_brown}"
    local SVN_THEME_PROMPT_PREFIX="${_omb_prompt_bold_navy}svn:(${_omb_prompt_bold_brown}"
    local HG_THEME_PROMPT_PREFIX="${_omb_prompt_bold_navy}hg:(${_omb_prompt_bold_brown}"
    local SCM_THEME_PROMPT_SUFFIX="${_omb_prompt_reset_color}"
    local SCM_THEME_PROMPT_CLEAN="${_omb_prompt_bold_navy})${_omb_prompt_reset_color}"
    local SCM_THEME_PROMPT_DIRTY="${_omb_prompt_bold_navy}) ${_omb_prompt_olive}✗${_omb_prompt_reset_color}"
    local arrow="${arrow_color}➜${_omb_prompt_reset_color}"
    local hostname="${_omb_prompt_bold_blue}\u@\h${_omb_prompt_reset_color}"

    PS1="${hostname} ${arrow}  ${python_venv}${base_directory} "

    local scm_info=$(scm_prompt_info)

    PS1+=${scm_info:+$scm_info }
    PS1+=${_omb_prompt_normal}
}

_omb_util_add_prompt_command _omb_theme_PROMPT_COMMAND

posted @ 2024-11-15 11:47  二乘八是十六  阅读(40)  评论(0编辑  收藏  举报