官网:fish shell
官网教程:Tutorial — fish-shell 3.7.0 documentation

基本特点

  1. 自动补全
  2. 支持自定义高亮
  3. 支持脚本

基本使用

终端输入“fish”,即可进入新的终端。

4paradigm@4paradigmdeMacBook-Pro Projects % fish
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish
4paradigm@4paradigmdeMacBook-Pro ~/Projects >

自定义内置函数

Commands — fish-shell 3.7.0 documentation

4paradigm@4paradigmdeMacBook-Pro ~/P/j/copilot_operation (master)> pwd
/Users/4paradigm/Projects/judgeflow/copilot_operation

前面前面的显示内容有点长,因此打算缩减下最前面的 user & hostname。

修改方式如下:

在命令行中输入 funced prompt_login,即可进入内置函数编辑状态。

> funced prompt_login
prompt_login> function prompt_login --description 'display user name for the prompt'
                  if not set -q __fish_machine
                      set -g __fish_machine
                      set -l debian_chroot $debian_chroot
 
                      if test -r /etc/debian_chroot
                          set debian_chroot (cat /etc/debian_chroot)
                      end
 
                      if set -q debian_chroot[1]
                          and test -n "$debian_chroot"
                          set -g __fish_machine "(chroot:$debian_chroot)"
                      end
                  end
 
                  # Prepend the chroot environment if present
                  if set -q __fish_machine[1]
                      echo -n -s (set_color yellow) "$__fish_machine" (set_color normal) ' '
                  end
 
                  # If we're running via SSH, change the host color.
                  set -l color_host $fish_color_host
                  if set -q SSH_TTY; and set -q fish_color_host_remote
                      set color_host $fish_color_host_remote
                  end
 
                  echo -n -s (set_color $fish_color_user) "$USER" (set_color normal) @ (set_color $color_host) (prompt_hostname) (set_color normal)
              end

将倒数第二行进行修改,修改后如下:

echo -n -s (set_color $fish_color_user) wangsc (set_color normal) @ (set_color $color_host) MacBook-Pro (set_color normal)

最后输入 funcsave prompt_login 来保存脚本。

fish mac shell-1.png

最后的效果如下:

fish mac shell-2.png