你新买的 MacBook air M1 所需的配置工作

2021-01-03  本文已影响0人  变身的大恶魔

安装brew

Homebrew官网:https://docs.brew.sh/Installation#1,M1出来之后brew也是在持续更新。期待M1环境下的软件兼容性越来越好。

1. 准备目录

M1之后,不能放到 /usr/local/bin目录下了。要放到/opt目录下 所以新建/opt目录,执行:

<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="sh" cid="n6" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; background-position: inherit inherit; background-repeat: inherit inherit;">cd /opt && sudo chmod -R 777 ./</pre>

授权给所有用户所有权限。

2. 安装

进入/opt/路径,在终端中执行:

<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="sh" cid="n10" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; background-position: inherit inherit; background-repeat: inherit inherit;">mkdir homebrew && curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew</pre>

3. 配置环境变量

<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="" cid="n12" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; background-position: inherit inherit; background-repeat: inherit inherit;">sudo vim /etc/profile </pre>

在最后一行添加export PATH=$PATH:/opt/Homebrew/bin之后终端执行source /etc/profile

这里遇到一个关键问题是,每次在重启电脑后都需要再次执行source /etc/profile 配置环境变量。原因是:

首先vim ~/.zprofile:

img

缺少$PATH部分。

系统先加载/etc/profile 然后再加载/.bash_profile,由于开始没有红圈圈那部分,最终的环境变量就只有/.zprofile部分;/etc/profile配置的环境变量均无用。加上就OK了。

oh my zsh

1. 安装oh-my-zsh

这里提供三种方法安装oh-my-zsh

<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="" cid="n25" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; background-position: inherit inherit; background-repeat: inherit inherit;">sh -c "$(wget -O- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"</pre>

<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="" cid="n29" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; background-position: inherit inherit; background-repeat: inherit inherit;">sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"</pre>

<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="" cid="n33" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; background-position: inherit inherit; background-repeat: inherit inherit;">curl -Lo install.sh https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
sh install.sh</pre>

执行脚本会有命令行交互,询问是否要启用zsh shell,回车y。开始使用

2. 设置主题

oh-my-zsh提供了很多主题,可以通过命令查看当前使用的主题:

<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="sh" cid="n37" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; background-position: inherit inherit; background-repeat: inherit inherit;">ls ~/.oh-my-zsh/themes</pre>

可以通过编辑.zshrc文件来修改你的主题

<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="sh" cid="n39" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; background-position: inherit inherit; background-repeat: inherit inherit;">vi ~/.zshrc</pre>

推荐选用ys主题,简洁并且该有的信息都有:

截屏2021-01-03 上午1.18.48

3.zsh-autosuggestions自动补全插件

  1. 下载该插件到.oh-my-zsh的插件目录

    <pre spellcheck="false" class="md-fences mock-cm md-end-block" lang="bash" cid="n47" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; background-position: inherit inherit; background-repeat: inherit inherit;">git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions</pre>

  2. 编辑.zshrc文件

    找到plugins=(git)这一行,如果没有添加。更改为如下

    <pre spellcheck="false" class="md-fences mock-cm md-end-block" lang="undefined" cid="n52" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; background-position: inherit inherit; background-repeat: inherit inherit;">plugins=(git zsh-autosuggestions)</pre>

  3. 重启命令

tmux

tmux 是一款终端复用命令行工具,一般用于 Terminal 的窗口管理。在 macOS 下,使用 iTerm2 能应付绝大多数窗口管理的需求。

img

如上图所示,iTerm2 能新建多个标签页(快捷键 ⌘T),也能在同一个窗口中分割出多个窗格(快捷键 ⌘D 或 ⌘⇧D)。

tmux 相比 iTerm2 的优势在于:

接下来我们花十分钟来掌握下 tmux 的基础用法:

安装运行

macOS 上使用 Homebrew 安装即可:

<pre spellcheck="false" class="md-fences mock-cm md-end-block" lang="" cid="n71" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; background-position: inherit inherit; background-repeat: inherit inherit;">brew install tmux</pre>

安装完成后,运行 tmux 新建一个 tmux 的会话(session),此时窗口唯一的变化是在底部会出现一个 tmux 的状态栏。我们先按下 tmux 默认的前缀快捷键 ⌃b 将其激活为快捷键接收模式,再按下 % ,即可将当前窗口切分为左右两个窗格。

[图片上传中...(image-6590eb-1609833951937-2)]

快捷键

一般情况下 tmux 中所有的快捷键都需要和前缀快捷键 ⌃b 来组合使用(注:⌃ 为 Mac 的 control 键),以下是常用的窗格(pane)快捷键列表,大家可以依次尝试下:

窗格操作

窗口操作

tmux 除了窗格以外,还有窗口(window) 的概念。依次使用以下快捷键来熟悉 tmux 的窗口操作:

img

会话操作

如果运行了多次 tmux 命令则会开启多个 tmux 会话(session)。在 tmux 会话中,使用前缀快捷键 ⌃b 配合以下快捷键可操作会话:

在 shell 主进程下运行以下命令可以操作 tmux 会话:

<pre spellcheck="false" class="md-fences mock-cm md-end-block" lang="" cid="n133" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; background-position: inherit inherit; background-repeat: inherit inherit;">tmux new -s foo # 新建名称为 foo 的会话
tmux ls # 列出所有 tmux 会话
tmux a # 恢复至上一次的会话
tmux a -t foo # 恢复名称为 foo 的会话,会话默认名称为数字
tmux kill-session -t foo # 删除名称为 foo 的会话
tmux kill-server # 删除所有的会话</pre>

除以上提到的快捷键以外,tmux 还有许多其他的快捷键和命令,使用前缀快捷键 ⌃b? 可以查看所有的快捷键列表,该列表视图为 tmux copy 模式,该模式下可使用以下快捷键(无需加 ⌃b 前缀):

常见配置与问题

1、鼠标滚屏

tmux 默认配置中最糟糕的体验就是滚屏查看和文本复制(大家可以先试试看)。你需要先使用 ⌃b [ 快捷键进入 copy 模式,然后使用翻页、字符定位来选择需要的字符,效率远没有鼠标选择来的快。

因此 tmux 提供了一些个性化配置项来优化这些配置,首先在 shell 中运行 touch ~/.tmux.conf 新建用户配置文件。在文件中增加以下内容:

<pre spellcheck="false" class="md-fences mock-cm md-end-block" lang="" cid="n151" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; background-position: inherit inherit; background-repeat: inherit inherit;"># 开启鼠标模式
set -g mode-mouse on

允许鼠标选择窗格

set -g mouse-select-pane on

如果喜欢给窗口自定义命名,那么需要关闭窗口的自动命名

set-option -g allow-rename off

如果对 vim 比较熟悉,可以将 copy mode 的快捷键换成 vi 模式

set-window-option -g mode-keys vi</pre>

配置文件修改完成后,可以 tmux kill-server 重启所有 tmux 进程,或者在 tmux 会话中使用 ⌃b : 进入控制台模式,输入 source-file ~/.tmux.conf 命令重新加载配置。

2、鼠标复制

tmux 下开启鼠标滚屏后,复制文本有两种方式:

img

3、tips

上一篇 下一篇

猜你喜欢

热点阅读