Mac 使用笔记

Mac OS 安装 Hyper 命令行工具

2019-09-26  本文已影响0人  风逝FM

Mac 系统自带的 terminal 如下图,主题、字体等不是很美观。

Mac 系统自带的 terminal
我们可以抛弃系统终端,利用Hyper 把终端变得更漂亮。

一、Hyper 安装

1,安装 Homebrew

这里利用 Homebrew 安装。如果之前没有安装过 Homebrew , 在系统 terminal 中运行

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

即可安装 Homebrew.

2,安装 Hyper

在系统 terminal 中运行

brew cask install hyper

此时系统 Applications 中即可找到 Hyper。如果下载慢可以阅读 Homebrew 和 Homebrew cask 下载更新慢解决方法

3,Hyper 主题和插件

进入 https://hyper.is,选择自己喜欢的 Themes 和 Plugins,点击 Install, 即弹出安装命令,如下图。

Hyper 安装主题和插件

打开 Hyper,运行此命令即可更换主题、添加插件。

4,.hyper.js偏好设置

在 Hyper 中选择 Hyper -> Preferences..., 打开.hyper.js偏好设置文件。找到

 plugins: ["hyper-search", "verminal"],

这行。删除某项,即可删除该主题或插件。比如删除"verminal", 就可删除此主题。

二、macOS 下,使用 Oh My Zsh

1,zsh 安装

在 Hyper 中运行

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

安装成功后,屏幕出现 zsh 庆祝页面,如下

xxxx% sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" 
Cloning Oh My Zsh...
Cloning into '/Users/xxxx/.oh-my-zsh'...
remote: Counting objects: 831, done.
remote: Compressing objects: 100% (700/700), done.
remote: Total 831 (delta 14), reused 775 (delta 10), pack-reused 0
Receiving objects: 100% (831/831), 567.67 KiB | 75.00 KiB/s, done.
Resolving deltas: 100% (14/14), done.
Looking for an existing zsh config...
Found ~/.zshrc. Backing up to ~/.zshrc.pre-oh-my-zsh
Using the Oh My Zsh template file and adding it to ~/.zshrc
             __                                     __   
      ____  / /_     ____ ___  __  __   ____  _____/ /_  
     / __ \/ __ \   / __ `__ \/ / / /  /_  / / ___/ __ \ 
    / /_/ / / / /  / / / / / / /_/ /    / /_(__  ) / / / 
    \____/_/ /_/  /_/ /_/ /_/\__, /    /___/____/_/ /_/  
                            /____/                       ....is now installed!
Please look over the ~/.zshrc file to select plugins, themes, and options.
p.s. Follow us at https://twitter.com/ohmyzsh.
p.p.s. Get stickers and t-shirts at http://shop.planetargon.com.

2,设置 Hyper 默认 shell 为 zsh

打开.hyper.js偏好设置文件。找到 shell 那一行,把它修改为

 shell: 'zsh',

保存,重启 Hyper.

3,删除首行空行

重启 Hyper 后首行有一空行,如下图。


Hyper 首行空行

该问题参考 Cannot uninstall oh-my-zsh #7081 后可按如下方式解决。

运行

open ~/.zshrc

打开 .zshrc文件,在最后一行添加

unsetopt PROMPT_SP

即可解决首行空行问题。

4,配置主题

Oh My Zsh 默认自带了一些默认主题,存放在 ~/.oh-my-zsh/themes目录中。我们可以查看这些主题。终端输入

cd ~/.oh-my-zsh/themes && ls

即可查看。在 Themes 中也列举了 zsh 常见的主题。选择其中的主题,并在.zshrc文件

ZSH_THEME="robbyrussell"

中将默认的robbyrussell更改为自己喜欢的主题名称。

1)Bullet train 主题

改主题类似agnoster基于Powerline Vim 插件,且改主题可在不同命令间换行,更方便查看。安装方法:

  1. bullet-train.zsh 中下载 bullet-train.zsh-theme 并将其复制到 ~/.oh-my-zsh/themes目录中。
  2. ~/.zshrc文件中修改主题为
ZSH_THEME="bullet-train"
  1. 终端中运行
# clone
git clone https://github.com/powerline/fonts.git --depth=1
# install
cd fonts
./install.sh
# clean-up a bit
cd ..
rm -rf fonts

安装 Powerline 字体。

  1. 按如下修改 .hyper.js 文件
module.exports = {
  config: {
    // Overrides for the verminal theme
    verminal: {
      fontFamily: '"Source Code Pro for Powerline"'
    },
    // default font size in pixels for all tabs
    fontSize: 14,
    fontFamily: '"Source Code Pro for Powerline", Menlo, "DejaVu Sans Mono", Consolas, "Lucida Console", monospace',

   // [etc...]

注意,最好在 hyper 中配合 verminal 主题使用效果最佳。最终效果如下图:

Hyper 界面
如果在mac terminal 和 vscode 中 terminal 显示不正常,可参见Mac terminal终端...解决Mac下VSCode打开zsh乱码

5,配置插件

awesome-zsh-plugins 合集中列举了 zsh常见的框架、插件和主题。

1)zsh-autosuggestions

在 macOS 下利用 Homebrew:

brew install zsh-autosuggestions

然后将

source /usr/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh

加入 .zshrc 文件最后一行。

2)zsh-syntax-highlighting

在 macOS 下利用 Homebrew:

brew install zsh-syntax-highlighting

然后将

source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

加入 .zshrc 文件最后一行。

3) zsh-vscode

  1. 进入此插件 GitHub 页面,下载zsh-vscode.plugin.zsh文件,将其放在 ~/目录下(目录可自行更改)。
  2. ~/.zshrc文件中添加一行
source ~/zsh-vscode.plugin.zsh
  1. 终端运行
source ~/.zshrc

参考资料

[1] HOW TO | 让自己的终端漂亮得不像实力派
[2] Hyper.js--命令行工具新势力
[3] Oh My Zsh,安装,主题配置方法
[4] Powerline fonts not working anymore #3343
[5] ohmyzsh

上一篇下一篇

猜你喜欢

热点阅读