【iTerm2】美化你的Terminal 赠佛祖像

我们开发就是喜欢各种酷炫的东西,对于有洁癖的我,连命令行都不放过了

先上图看效果,命令行显示高亮部分

实现过程:

第一步:.bash_prompt脚本

# ~/.bash_prompt
# This prompt inspired by gf3, sindresorhus, alrra, and mathiasbynens.
# but customized to me. <3

default_username='paulirish'

#eval "$(thefuck --alias)"

if [[ -n "$ZSH_VERSION" ]]; then  # quit now if in zsh
    return 1 2> /dev/null || exit 1;
fi;

if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then
    export TERM=gnome-256color
elif infocmp xterm-256color >/dev/null 2>&1; then
    export TERM=xterm-256color
fi

set_prompts() {

    local black="" blue="" bold="" cyan="" green="" orange=""           purple="" red="" reset="" white="" yellow=""

    local dateCmd=""

    if [ -x /usr/bin/tput ] && tput setaf 1 &> /dev/null; then

        tput sgr0 # Reset colors

        bold=$(tput bold)
        reset=$(tput sgr0)

        # Solarized colors
        # (https://github.com/altercation/solarized/tree/master/iterm2-colors-solarized#the-values)
        black=$(tput setaf 0)
        blue=$(tput setaf 33)
        cyan=$(tput setaf 37)
        green=$(tput setaf 190)
        orange=$(tput setaf 172)
        purple=$(tput setaf 141)
        red=$(tput setaf 124)
        violet=$(tput setaf 61)
        magenta=$(tput setaf 9)
        white=$(tput setaf 8)
        yellow=$(tput setaf 136)

    else

        bold=""
        reset="\e[0m"

        black="\e[1;30m"
        blue="\e[1;34m"
        cyan="\e[1;36m"
        green="\e[1;32m"
        orange="\e[1;33m"
        purple="\e[1;35m"
        red="\e[1;31m"
        magenta="\e[1;31m"
        violet="\e[1;35m"
        white="\e[1;37m"
        yellow="\e[1;33m"

    fi

    # Only show username/host if not default
    function usernamehost() {

        # Highlight the user name when logged in as root.
        if [[ "${USER}" == *"root" ]]; then
            userStyle="${red}";
        else
            userStyle="${magenta}";
        fi;

        userhost=""
        userhost+="\[${userStyle}\]$USER "
        userhost+="${white}at "
        userhost+="${orange}$HOSTNAME "
        userhost+="${white}in"

        if [ $USER != "$default_username" ]; then echo $userhost ""; fi
    }

    function prompt_git() {
        # this is >5x faster than mathias's.

        # check if we're in a git repo. (fast)
        git rev-parse --is-inside-work-tree &>/dev/null || return

        # check for what branch we're on. (fast)
        #   if… HEAD isn’t a symbolic ref (typical branch),
        #   then… get a tracking remote branch or tag
        #   otherwise… get the short SHA for the latest commit
        #   lastly just give up.
        branchName="$(git symbolic-ref --quiet --short HEAD 2> /dev/null ||             git describe --all --exact-match HEAD 2> /dev/null ||             git rev-parse --short HEAD 2> /dev/null ||             echo '(unknown)')";

        ## early exit for Chromium & Blink repo, as the dirty check takes ~5s
        ## also recommended (via goo.gl/wAVZLa ) : sudo sysctl kern.maxvnodes=$((512*1024))
        repoUrl=$(git config --get remote.origin.url)
        if grep -q chromium.googlesource.com <<<$repoUrl; then
            dirty=" ?"
        else

            # check if it's dirty (slow)
            #   technique via github.com/git/git/blob/355d4e173/contrib/completion/git-prompt.sh#L472-L475
            dirty=$(git diff --no-ext-diff --quiet --ignore-submodules --exit-code || echo -e "*")

            # mathias has a few more checks some may like:
            #    github.com/mathiasbynens/dotfiles/blob/a8bd0d4300/.bash_prompt#L30-L43
        fi

        [ -n "${s}" ] && s=" [${s}]";
        echo -e "${1}${branchName}${2}$dirty";

        return
    }

    # ------------------------------------------------------------------
    # | Prompt string                                                  |
    # ------------------------------------------------------------------

    PS1="\[\033]0;\w\007\]"                                 # terminal title (set to the current working directory)
    PS1+="\n\[$bold\]"
    PS1+="\[$(usernamehost)\]"                              # username at host
    PS1+="\[$green\]\w"                                     # working directory
    PS1+="\$(prompt_git \"$white on $purple\" \"$cyan\")"   # git repository details
    PS1+="\n"
    PS1+="\[$reset$white\]\\$ \[$reset\]"

    export PS1

    # ------------------------------------------------------------------
    # | Subshell prompt string                                         |
    # ------------------------------------------------------------------

    export PS2="? "

    # ------------------------------------------------------------------
    # | Debug prompt string  (when using `set -x`)                     |
    # ------------------------------------------------------------------

    # When debugging a shell script via `set -x` this tricked-out prompt is used.

    # The first character (+) is used and repeated for stack depth
    # Then, we log the current time, filename and line number, followed by function name, followed by actual source line

    # FWIW, I have spent hours attempting to get time-per-command in here, but it's not possible. ~paul
    export PS4='+ \011\e[1;30m\t\011\e[1;34m${BASH_SOURCE}\e[0m:\e[1;36m${LINENO}\e[0m \011 ${FUNCNAME[0]:+\e[0;35m${FUNCNAME[0]}\e[1;30m()\e[0m:\011\011 }'

    # shoutouts:
    #   https://github.com/dholm/dotshell/blob/master/.local/lib/sh/profile.sh is quite nice.
    #   zprof is also hot.

}

set_prompts
unset set_prompts

第二步:加入bash_profile

$ vim ~/.bash_profile
## add code to buttom
[[ -s $HOME/.bash_prompt ]] && source $HOME/.bash_prompt

重新打开命令行 或者执行 source ~/.bash_profile  就可以看到效果了,是不是非常炫呀

------------------------我是优雅分割线-----------------------

命令行 佛祖像

$ vim ~/.bash_profile

## add code to buttom

echo -ne "\033[0;33m"
cat<<EOT
                                  _oo0oo_
                                 088888880
                                 88" . "88
                                 (| -_- |)
                                  0\ = /0
                               ___/'---'\___
                             .' \\\\|     |// '.
                            / \\\\|||  :  |||// \                           /_ ||||| -:- |||||- \                          |   | \\\\\\  -  /// |   |
                          | \_|  ''\---/''  |_/ |
                          \  .-\__  '-'  __/-.  /
                        ___'. .'  /--.--\  '. .'___
                     ."" '<  '.___\_<|>_/___.' >'  "".
                    | | : '-  \'.;'\ _ /';.'/ - ' : | |
                    \  \ '_.   \_ __\ /__ _/   .-' /  /
                ====='-.____'.___ \_____/___.-'____.-'=====
                                  '=---='

              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                        天下武功  iii  唯快不破
EOT
echo -ne "\033[m"

原文地址:【iTerm2】美化你的Terminal 赠佛祖像
标签:iTerm2   terminal   佛祖

智能推荐

  • In MySQL, a zero number equals any string
  • nginx rewrite 参数和例子
  • virtualbox + ubuntu虚拟机 目录共享
  • Ubuntu apparmor何方神圣
  • Yii2 捕获错误日志
时间: 2024-07-28 20:43:08

【iTerm2】美化你的Terminal 赠佛祖像的相关文章

【Demo】HTML5 拍照

本文主要讲解 手机浏览器 如何拍照 为什么会有这个需求 最近做一个项目要用到拍照然后上传照片,但是网页拍照一般都是用Flash做的,而我们主要是H5页面,如果在微信里面有权限就可以通过JSSDK调起摄像头拍照的.这里我们主要说下手机端浏览器如何调起摄像头 H5如何打开摄像头 不需要特别的支持,只需要一行代码就可以了 <input id="upload" type="file" accept="image/*;" capture="

OSX + iTerm2 + vim + ssh + CentOS/本机颜色配置原理小分析

前一段时间需要从本地SSH到某台云服务器查看配置文件,BOSS在我边上跟我一起找文件.找毕,BOSS说:“你这颜色看着不难受么?辨识度太低了”当时我的屏幕是这样的: 其实我也是这么认为的,这颜色太惨了.漆黑的背景,深深蓝色的标识符,实在是看不清楚.说搞就搞,网上找各种配色方案,先来一打iTerm2的配色方案,再把其中的背景图片也设置一下,先不说远端服务器的效果(因为有坑,后说),本机已经是这样的了: 一不做而不休,把本机的oh-my-zsh也在自己CentOS的腾讯云主机里搞一套,当然vim的配

kali2.0安装及使用笔记(附带vim配置,长期更新)

作者:King-CDQ 时间:16/08/19 原创文章,转载请注明出处(作者和原文链接). 如有特别用途,请与我联系邮箱:[email protected] 早就听说Kali的大名,整合多款渗透测试的软件,让想尝试一把黑客感觉的我跃跃欲试,但是苦于没有时间, 一直没有安装.正好今年(2016年)kali大更,更是推出了rolling版本,这次我就直接安装kali2.0,同时分享 给大家我的安装过程和系统的相关配置,同时作为我使用kali的笔记,有什么好用的软件我都会记录下来, 长期记录,作为以

使用iTerm2替代Mac自带Terminal终端

使用iTerm2来替代Terminal终端.整体的搭配组合为:iTerm2+Oh my zsh +zsh iTerm2是Terminal的替代品,是一款比较小众的软件,比Terminal优秀太多了.下载官网为http://www.iterm2.cn/,下载后直接安装即可.iTerm2可以设置主题,支持画面分隔.各种快捷键.Mac默认使用的shell是bash,我们可以换成zsh,搭配iTerm2使用,用起来十分顺手. (1)现在假设大家都安装了iTerm2,我们先把bash切换成zsh,使用命令

mac&#39;s native Terminal VS iterm2

俗话说"工欲善其事必先利其器",没错,对于运维更是如此,每天都需要用终端远程管理服务器,这个终端就是运维的器,废话少说: mac native Terminal已经很好用,虽然有些不足,直到发现iterm2... 以下仅列举iterm2完胜terminal的.让你心动的features: 1.support  zmodem(for simply transfer file between local and remote server,在windows下只有secureCRT支持) 2

Mac OS 终端美化:iterm2 + zsh + oh~my~zsh 设置教程

前言 mac自带的terminal终端没有文件名高亮等功能,而且界面不是很好看,故今晚学舍友折腾了终端,可以让自己使用起来更加方便,看起来更加舒服. 下面直接说配置方法吧.关于这三个名词的介绍可以看文末. 配置方法 1. 下载安装iterm2 官网:https://www.iterm2.com 打开官网下载安装包,打开安装就好. 2. 切换shell为zsh chsh -s /bin/zsh 查看是否切换成功 echo $SHELL 3. 安装oh~my~zsh sh -c "$(curl -f

再次配置iterm2+zsh替代terminal

最近macOS又折腾了一次,手贱把系统升级到最新到macOS Catalina,结果大部分32位的APP都不能用了,首先是LD的同步助手,直接挂了TAT,后面直接承受LD的河东嘶吼(此次省略几百万个动作特效..) 最后LD下了死命令:必须给装回同步助手(用来把电影同步到苹果手机里),不然日子没法过了. 接下来开启了系统降级之路(本来计划降级到macOS High Sierra的,结果不太顺利,就只能弄到macOS Mojave,凑合着也能用),正好又遇上了过年到重大疫情,电脑算是直接报废了,宅在

macOS用iTerm2打造超高B格终端

一.什么是iTerm2? iTerm2是Terminal的替代品,是iTerm的后继产品.它适用于MacOS 10.12或更高版本的Mac.iTerm2将终端带入了您从未想过一直想要的功能,使其进入了现代时代. 二.最终美化结果 三.美化步骤 (1)General (1.1)Startup (1.2)Closing (1.3)Magic (1.4)Services (1.5)Selection (1.6)Window (1.7)Preferences (1.8)tmux (2)Apperaran

iTerm2和Alfr的安装和使用

iTerm2的安装和使用 首先是安装终端相关的装逼神器 先把archey拷贝到bin目录下,补充图示: 如果要用终端命令去复制粘贴的话,命令就是:sudo cp -r 源文件目录/源文件 /usr/local/bin 然后随便打开终端,输入命令archey:就OK了. 然后设置它的style和快捷键: Find Cursor查找光标  快捷键command+/ 配色: 然后以下就是MJ给的笔记:===================================================