安装Homebrew
终端执行代码:
- /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
或者去Homebrew官网查看安装命令
一般会自动安装Command Line Tools for Xcode(安装Homebrew必需的插件)
Homebrew常用语句
搜索: brew search<SoftwareName>
更新: brew install<SoftwareName>
卸载: brew uninstall<SoftwareName>
显示已安装软件: brew ls(list)
显示软件的信息: brew info<SoftWareName>
Homebrew其他使用命令可以参考 https://www.jianshu.com/p/de6f1d2d37bf
使用brew services管理服务开机启动
GitHub: https://github.com/Homebrew/homebrew-services
一般macOS使软件开机自启的命令一般是 launchctl命令加载开机自动运行服务,使用 brew service可以简化操作。
-
launchctl的配置方式,以MySQL为例:
- ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
- launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
-
如使用brew service可以简化为:
- brew services start mysql
常用命令
- brew services list # 查看使用brew安装的服务列表
- brew services run formula|--all # 启动服务(仅启动不注册)
- brew services start formula|--all # 启动服务,并注册开机启动
- brew services stop formula|--all # 停止服务,并取消注册开机启动
- brew services restart formula|--all # 重启服务,并注册开机启动
- brew services cleanup # 清除已卸载应用的无用的配置
.plist配置文件存放目录
-
开机自启存放目录,需要sudo
- /Library/LaunchDaemons
-
用户登录后自启存放目录
- ~/Library/LaunchAgents
可以在homebrew.mxcl.kafka.plist文件中找到服务路径、启动参数、日志路径等
安装ZSH
-
直接用Homebrew安装zsh:
- brew install zsh
-
接着使zsh生效
先使用命令
查看/etc/shells文件中有没有
如果没有就用 vim/etc/shells加上;如果有,就执行下一命令使zsh生效:
- chsh -s /usr/local/bin/zsh
- 或者
- chsh -s /bin/zsh
- /usr/local/bin/zsh
- 或者
- /bin/zsh
- cat /etc/shells
-
安装oh-my-zsh
安装oh-my-zsh需要使用git工具,先安装git:
在执行以下代码:(如果失效,可以去查看oh-my-zsh开源项目)
via curl
via wget
最终效果如图:
- sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
- sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
- brew install git
-
关于配置文件
默认Shell的~/.bashrc文件默认不再加载了,替代的是~/.zlogin和~/.zshrc。
配置Mac终端iTerm2(powerlevel9k)
经过以上配置已经很完美了
现在缺少一个很漂亮的主题
首先创建一个暂存文件夹,然后进入这个文件夹,在克隆iTerm2的配色方案,依次执行以下三行代码:
- mkdir tmp
- cd tmp
- git clone https://github.com/MartinSeeler/iterm2-material-design.git
然后在该目录双击' material-design-colors.itermcolors'文件,点确定!
然后rm -rf删库跑路(tmp)
- cd ..
- rm -rf tmp/
打开iTerm2 command+, 打开设置->Profiles->Colors->Color Presets->material-design-colors->command+W
安装powerlevel9k:
- git clone https://github.com/bhilburn/powerlevel9k.git ~/.oh-my-zsh/custom/themes/powerlevel9k
修改 ~/.zshrc 配置文件,配置该主题
- vim ~/.zshrc
在里面设置主题
- ZSH_THEME="powerlevel9k/powerlevel9k"
重启终端,会发现有些字符显示乱码这时候需要安装Nerd字体
安装可能很慢可以使用以下安装命令:
- cd ~/Library/Fonts && curl -fLo "Droid Sans Mono for Powerline Nerd Font Complete.otf" https://github.com/ryanoasis/nerd-fonts/raw/master/patched-fonts/DroidSansMono/complete/Droid%20Sans%20Mono%20Nerd%20Font%20Complete.otf
安装完字体后更改iTerm2终端字体 搜索nerd选择就行了
安装成功后就是这样的:
接下来配置powerlevel9k主题
- vim ~/.zshrc
在主题 ZSH_THEME=xxxxxxx前面加上
- POWERLEVEL9K_MODE="nerdfont-complete"
在最后添加以下内容:
- # ================= powerlevel9k Settings =================
- # Please only use this battery segment if you have material icons in your nerd font (or font)
- # Otherwise, use the font awesome one in "User Segments"
- POWERLEVEL9K_PROMPT_ON_NEWLINE=true
- POWERLEVEL9K_PROMPT_ADD_NEWLINE=true
- POWERLEVEL9K_RPROMPT_ON_NEWLINE=true
- POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
- POWERLEVEL9K_SHORTEN_STRATEGY="truncate_beginning"
- POWERLEVEL9K_RVM_BACKGROUND="black"
- POWERLEVEL9K_RVM_FOREGROUND="249"
- POWERLEVEL9K_RVM_VISUAL_IDENTIFIER_COLOR="red"
- POWERLEVEL9K_TIME_BACKGROUND="black"
- POWERLEVEL9K_TIME_FOREGROUND="249"
- POWERLEVEL9K_TIME_FORMAT="UF43A %D{%I:%M UF133 %m.%d.%y}"
- POWERLEVEL9K_RVM_BACKGROUND="black"
- POWERLEVEL9K_RVM_FOREGROUND="249"
- POWERLEVEL9K_RVM_VISUAL_IDENTIFIER_COLOR="red"
- POWERLEVEL9K_STATUS_VERBOSE=false
- POWERLEVEL9K_VCS_CLEAN_FOREGROUND='black'
- POWERLEVEL9K_VCS_CLEAN_BACKGROUND='green'
- POWERLEVEL9K_VCS_UNTRACKED_FOREGROUND='black'
- POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND='yellow'
- POWERLEVEL9K_VCS_MODIFIED_FOREGROUND='white'
- POWERLEVEL9K_VCS_MODIFIED_BACKGROUND='black'
- POWERLEVEL9K_COMMAND_EXECUTION_TIME_BACKGROUND='black'
- POWERLEVEL9K_COMMAND_EXECUTION_TIME_FOREGROUND='blue'
- POWERLEVEL9K_FOLDER_ICON=''
- POWERLEVEL9K_STATUS_OK_IN_NON_VERBOSE=true
- POWERLEVEL9K_STATUS_VERBOSE=false
- POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=0
- POWERLEVEL9K_VCS_UNTRACKED_ICON='u25CF'
- POWERLEVEL9K_VCS_UNSTAGED_ICON='u00b1'
- POWERLEVEL9K_VCS_INCOMING_CHANGES_ICON='u2193'
- POWERLEVEL9K_VCS_OUTGOING_CHANGES_ICON='u2191'
- POWERLEVEL9K_VCS_COMMIT_ICON="uf417"
- POWERLEVEL9K_MULTILINE_FIRST_PROMPT_PREFIX="%F{blue}u256Du2500%f"
- POWERLEVEL9K_MULTILINE_LAST_PROMPT_PREFIX="%F{blue}u2570uf460%f "
- POWERLEVEL9K_CUSTOM_BATTERY_STATUS="prompt_zsh_battery_level"
- POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context os_icon custom_internet_signal custom_battery_status_joined ssh root_indicator dir dir_writable vcs)
- POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(command_execution_time status time)
- HIST_STAMPS="mm/dd/yyyy"
- DISABLE_UPDATE_PROMPT=true
最终显示效果:
再安装两个插件:
安装 autosuggestions(自动提示)
- git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
安装 syntax-highlighting(动态高亮)
- git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
在配置文件里启用插件: vim~/.zshrc
- plugins=(
- git
- zsh-autosuggestions
- zsh-syntax-highlighting
- )
- # 注意:zsh-syntax-highlighting 必须放在最后面(官方推荐)
本文来源于:Mac的终端美化教程-变化吧门户
特别声明:以上文章内容仅代表作者本人观点,不代表变化吧门户观点或立场。如有关于作品内容、版权或其它问题请于作品发表后的30日内与变化吧联系。
- 赞助本站
- 微信扫一扫
-
- 加入Q群
- QQ扫一扫
-
评论