Mac 技巧

SunSeekerX ... 2020-12-1 大约 5 分钟

# Mac 技巧

# hidpi

Github:https://github.com/xzhih/one-key-hidpi (opens new window)

Github 文档:https://github.com/xzhih/one-key-hidpi/blob/master/README-zh.md (opens new window)

bash -c "$(curl -fsSL https://raw.githubusercontent.com/xzhih/one-key-hidpi/master/hidpi.sh)"
1
1

分辨率

# 3440x1440
2560x1072 5120x2144 2752x1152 5504x2304
1
2
1
2

RDM - https://github.com/avibrazil/RDM (opens new window)

下载地址 - https://avi.alkalay.net/software/RDM/ (opens new window)

# 软件推荐

hyperdock (opens new window)

docker 栏窗口预览,Windows 自带,mac 没有这个功能。

magnet (opens new window)

分屏神器。

CleanMyMac

清除垃圾工具

tomenu

增强右键菜单

# 控制安卓手机 - scrcpy

记得使用代理安装!

The application is available in Homebrew (opens new window). Just install it:

brew install scrcpy
1
1

You need adb, accessible from your PATH. If you don't have it yet:

# 查看 brew 版本
brew -v

# Homebrew >= 2.6.0
brew install --cask android-platform-tools

# Homebrew < 2.6.0
brew cask install android-platform-tools
1
2
3
4
5
6
7
8
1
2
3
4
5
6
7
8

It's also available in MacPorts (opens new window), which sets up adb for you:

sudo port install scrcpy
1
1

You can also build the app manually (opens new window).

# homebrews

代理

brew 用 curl 下载,所以给 curl 挂上 socks5 的代理即可。

在~/.curlrc 文件中输入代理地址即可。

# clash
socks5 = "127.0.0.1:7890"
1
2
1
2

# 关闭/打开聚焦索引

背景:Mac 上的 Spotlight 会调用 mds、mdworker 等进程,占用 cpu 使用率,造成系统卡顿。如果电脑配置比较低的话可以将 Spotlight 关闭,如果需要使用 Spotlight 或者 Alfred 等功能时,就需要将 Spotlight 开启。

关闭 Spotlight: 方法 1: 使用 launchctl 管理 MacOS 服务。这里卸载 Spotlight 的配置. 卸载配置之后,就不会再启动 mds 等进程来扫描文件,这样后续新增 App 或者文件,在 Spotlight 和 Alfred 中也就搜索不到了。

# 方法一
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist
# 方法二
sudo mdutil -a -i off

# 重启Spotlight: 方法1:使用 launchctl 管理 MacOS 服务。这里加载Spotlight的配置,重启mds等进程扫描文件。
# 方法一
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist
# 方法2:
sudo mdutil -a -i on
# 如果方法2中的命令后抛出 Spotlight server is disabled 这样的错误,那么就要用方法1中的操作了。
1
2
3
4
5
6
7
8
9
10
11
1
2
3
4
5
6
7
8
9
10
11

# Mac 系统下的环境变量

a. /etc/profile
b. /etc/paths
c. ~/.bash_profile
d. ~/.bash_login
e. ~/.profile
f. ~/.bashrc
复制代码
1
2
3
4
5
6
7
1
2
3
4
5
6
7

其中 a 和 b 是系统级别的,系统启动就会加载,其余是用户接别的。c,d,e 按照从前往后的顺序读取,如果 c 文件存在,则后面的几个文件就会被忽略不读了,以此类推。~/.bashrc 没有上述规则,它是 bash shell 打开的时候载入的。这里建议在 c 中添加环境变量,以下也是以在 c 中添加环境变量来演示的:

# finder 显示隐藏文件

# 显示
defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder
# 重新打开

# 关闭
defaults write com.apple.finder AppleShowAllFiles FALSE
killall Finder
1
2
3
4
5
6
7
8
1
2
3
4
5
6
7
8

# 取消系统更新小红点

# 取消
defaults write com.apple.systempreferences AttentionPrefBundleIDs 0
killall Dock

# 恢复
sudo softwareupdate --reset-ignored
defaults write com.apple.systempreferences AttentionPrefBundleIDs 0
1
2
3
4
5
6
7
1
2
3
4
5
6
7

# 添加 adb 环境变量

前提已经成功安装了 Android Studio.

echo 'export ANDROID_HOME=/Users/$USER/Library/Android/sdk' >> ~/.zshrc
echo 'export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools' >> ~/.zshrc

# 刷新
source ~/.zshrc
1
2
3
4
5
1
2
3
4
5

# java 版本管理

jEnv (opens new window)

  1. 安装

    brew install jenv
    
    1
    1
  2. 配置环境变量

    # Bash
    echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.bash_profile
    echo 'eval "$(jenv init -)"' >> ~/.bash_profile
    
    # Zsh
    echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.zshrc
    echo 'eval "$(jenv init -)"' >> ~/.zshrc
    
    1
    2
    3
    4
    5
    6
    7
    1
    2
    3
    4
    5
    6
    7
  3. 配置文件增加的内容 ~/.zshrc

    export PATH="$HOME/.jenv/bin:$PATH"
    eval "$(jenv init -)"
    
    # To enable shims and autocompletion add to your profile:
    if which jenv > /dev/null; then eval "$(jenv init -)"; fi
    
    # To use Homebrew's directories rather than ~/.jenv add to your profile:
    export JENV_ROOT=/usr/local/opt/jenv
    
    1
    2
    3
    4
    5
    6
    7
    8
    1
    2
    3
    4
    5
    6
    7
    8
  4. To make sure JAVA_HOME is set, make sure to enable the export plugin:

    jenv enable-plugin export
    exec $SHELL -l
    
    1
    2
    1
    2
  5. jEnv 命令

    # 检查运行是否正常
    jenv doctor
    
    # 添加到 jEnv
    jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_321.jdk/Contents/Home
    
    # 显示已经添加的版本
    jenv versions
    
    # 查看版本
    jenv --version
    
    # 设置全局 jdk 版本
    jenv global oracle64-1.6.0.39
    # 设置文件夹版本 // Configure local version (per directory)
    jenv local oracle64-1.6.0.39
    # 设置当前会话版本
    jenv shell oracle64-1.6.0.39
    
    # 查看安装的 jdk 版本
    /usr/libexec/java_home -V
    
    # 输出
     ssx@ssxdeMac-mini  ~  /usr/libexec/java_home -V
    Matching Java Virtual Machines (3):
        1.8.321.07 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
        1.8.0_321 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_321.jdk/Contents/Home
        1.7.0_80 (x86_64) "Oracle Corporation" - "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28

# iterm2 配置

# 安装 iterm2

https://iterm2.com/ (opens new window)

# 检查是否安装 zsh

zsh --version
1
1

如果没有安装使用 Homebrew 安装,安装 Homebrew https://brew.idayer.com/ (opens new window)

brew install zsh
1
1

设置默认

chsh -s /usr/local/bin/zsh
1
1

# 把 iTerm2 设为默认

iTerm2 -> Make ITerm2 Default Term
1
1

# iTerm2 颜色配置

https://iterm2colorschemes.com/ (opens new window)

# oh-my-zsh

https://ohmyz.sh/ (opens new window)

选择下面其中一种脚本安装:

curl:

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

wget:

sh -c "$(wget https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"
1
1

# 配置主题

官方收集了一些主题(不再收录新主题),你可以访问 主题&&截图 (opens new window) 页面查看并选取。

这里以agnoster为例说明。

1.编辑~/.zshrc文件,修改ZSH_THEME配置:

ZSH_THEME="agnoster"
1
1

# 功能增强

# 1. zsh-autosuggestions

命令自动补全功能。

1.克隆代码到$ZSH_CUSTOM/plugins(默认位于~/.oh-my-zsh/custom/plugins

git clone https://gitee.com/imirror/zsh-autosuggestions.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
1
1

2.在Oh My Zsh配置启用插件

打开~/.zshrc,找到plugins,追加zsh-autosuggestions

git为默认配置。

plugins=(git zsh-autosuggestions)
1
1

如果有看不到自动补全的内容,确保以下两个颜色不是相近的:

iTerm > Preferences > Profiles > Colors > ANSI Colors > Bright > Black
iTerm > Preferences > Profiles > Colors > Basic Colors > Background
1
2
1
2

最后执行source ~/.zshrc生效。

# 2. zsh-syntax-highlighting

语法高亮。

1.克隆代码到$ZSH_CUSTOM/plugins(默认位于~/.oh-my-zsh/custom/plugins

git clone https://gitee.com/imirror/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
1
1

2.在Oh My Zsh配置启用插件

打开~/.zshrc,找到plugins,追加zsh-syntax-highlighting

git为默认配置。

plugins=(git zsh-autosuggestions zsh-syntax-highlighting)
1
1

最后执行source ~/.zshrc生效。

# 我启用的插件列表

plugins=(git zsh-autosuggestions zsh-syntax-highlighting bundler dotenv macos rake rbenv ruby)

1
2
1
2
上次编辑于: 2023年1月28日 11:10
贡献者: SunSeekerX , SunSeekerX , ssx