Mac下 使用 HomeBrew 管理第三方軟件包, 與哪些好用的第三方軟件包


什么是HomeBrew

使用Homebrew安裝 Apple(或您的 Linux 系統)沒有預裝但 你需要的東西

安裝HomeBrew

1.1將brew的install文件下載本地

cd ~ && curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install >> brew_install

1.2修改install文件的鏡像源

# BREW_REPO = "https://github.com/Homebrew/brew".freeze
BREW_REPO = "git://mirrors.ustc.edu.cn/brew.git".freeze

1.3安裝brew

/usr/bin/ruby ~/brew_install

 1.4驗證是否安裝成功

$ brew doctor

如果沒成功先卸載brew一下,再試

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

如何使用 HomeBrew 安裝軟件

安裝完 HomeBrew 后可使用以下命令進行軟件包安裝:

brew install 軟件名稱

HomeBrew 常用命令

$ brew --help    # 查看簡潔幫助
$ man brew     # 完整命令幫助
$ brew install [name]    # 安裝軟件包
$ brew uninstall [name]    # 卸載軟件包
$ brew search [name]    # 搜索軟件包
$ brew list    # 顯示已經安裝的所有軟件包
$ brew update    # 同步遠程最新更新情況,對本機已經安裝並有更新的軟件用*標明
$ brew outdated    # 查看已安裝的哪些軟件包需要更新
$ brew upgrade [name]    # 更新單個軟件包
$ brew info [name]    # 查看軟件包信息
$ brew home [name]    # 訪問軟件包官方站
$ brew cleanup    # 清理所有已安裝軟件包的歷史老版本
$ brew cleanup [name]    # 清理單個已安裝軟件包的歷史版本

 

HomeBrew中安裝的好用的三方軟件

wget

1、安裝wget

安裝命令:brew install wget

檢驗是否安裝成功:

wget http://www.arefly.com/

安裝成功后結果如下:

MacBook-Pro:~ home$ wget http://www.arefly.com/
--2020-06-02 14:46:12--  http://www.arefly.com/
正在解析主機 www.arefly.com (www.arefly.com)... 115.29.198.97 正在連接 www.arefly.com (www.arefly.com)|115.29.198.97|:80... 已連接。 已發出 HTTP 請求,正在等待回應... 301 Moved Permanently 位置:https://www.arefly.com/ [跟隨至新的 URL]
--2020-06-02 14:46:12--  https://www.arefly.com/
正在連接 www.arefly.com (www.arefly.com)|115.29.198.97|:443... 已連接。 已發出 HTTP 請求,正在等待回應... 200 OK 長度:75961 (74K) [text/html] 正在保存至: “index.html” index.html 100%[===================>]  74.18K  --.-KB/s  用時 0.01s 2020-06-02 14:46:13 (5.38 MB/s) - 已保存 “index.html” [75961/75961])

 

Zsh 入門(安裝及使用)

先看下你的 CentOS 支持哪些 shell:cat /etc/shells,正常結果應該是這樣的:

MacBook-Pro:~ dunk$ cat /etc/shells # List of acceptable shells for chpass(1). # Ftpd will not allow users to connect who are not using # one of these shells. /bin/bash /bin/csh /bin/dash /bin/ksh /bin/sh /bin/tcsh /bin/zsh

默認 CentOS / Ubuntu / Mac 系統用的是 Bash,倒也不是說 Bash 不好,而是說我們有更好的選擇。

Zsh 安裝

  • CentOS 安裝:sudo yum install -y zsh
  • Ubuntu 安裝:sudo apt-get install -y zsh
  • 在檢查下系統的 shell:cat /etc/shells,你會發現多了一個:/bin/zsh

使用 Zsh 擴展集合:oh-my-zsh

什么是Oh My Zsh

Oh My Zsh是一款社區驅動的命令行工具,正如它的主頁上說的,Oh My Zsh 是一種生活方式。它基於zsh命令行,提供了主題配置,插件機制,已經內置的便捷操作。給我們一種全新的方式使用命令行。

Oh My Zsh這個名字聽起來就很有意思,它是基於zsh命令行的一個擴展工具集,提供了豐富的擴展功能。

Oh My Zsh只是一個對zsh命令行環境的配置包裝框架,但它不提供命令行窗口,更不是一個獨立的APP。

  • oh-my-zsh 幫我們整理了一些常用的 Zsh 擴展功能和主題:https://github.com/robbyrussell/oh-my-zsh
  • 我們無需自己去搗搞 Zsh,直接用 oh-my-zsh 就足夠了,如果你想繼續深造的話那再去弄。
  • 先安裝 git:sudo yum install -y git
  • 安裝 oh-my-zsh
  • Basic Installation Oh My Zsh is installed by running one of the following commands in your terminal. You can install this via the command-line with either curl or wget. via curl sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" via wget
    // 這里使用
    wget
    sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

     

  • 在以 root 用戶為前提下,oh-my-zsh 的安裝目錄:/root/.oh-my-zsh
  • 在以 root 用戶為前提下,Zsh 的配置文件位置:/root/.zshrc
  • 為 root 用戶設置 zsh 為系統默認 shell:chsh -s /bin/zsh root  注意:這里安裝的時候會有

    Do you want to change your default shell to zsh? [Y/n] 的選擇,寫Y然后回車就可以

  • 如果你要重新恢復到 bash:chsh -s /bin/bash root
  • 現在你關掉終端或是重新連上 shell,現在開頭是一個箭頭了,如下圖:

 

  • Oh My Zsh目錄結構

    進入~/.oh-my-zsh目錄后,看看該目錄的結構

lib 提供了核心功能的腳本庫
tools 提供安裝、升級等功能的快捷工具
plugins 自帶插件的存在放位置
templates 自帶模板的存在放位置
themes  自帶主題文件的存在放位置
custom 個性化配置目錄,自安裝的插件和主題可放這里

Zsh 配置

插件

  • 啟用 oh-my-zsh 中自帶的插件。
  • oh-my-zsh 的插件列表介紹(太長了,用源碼不精准地統計下有 149 個):https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins
  • 編輯配置文件:vim /root/.zshrc,找到下圖的地方,怎么安裝,原作者注釋寫得很清楚了,別裝太多了,默認 git 是安裝的

git 自動顯示當前分支名稱和修改狀態

git 快捷鍵

https://github.com/ohmyzsh/ohmyzsh/blob/master/plugins/git/git.plugin.zsh
zsh幫我們配置了一些git的常常用命令簡寫,我常用的是幾個命令

gst 代表 git status
# 添加當前目錄的所有文件到暫存區 alias ga . ='git add .'
# 提交暫存區到倉庫區  alias gcmsg ='git commit -m'
# 提交工作區自上次commit之后的變化,直接到倉庫區 gca 代表 git commit -v -a'
# 提交  alias gp ='git push'

# 切換到指定分支,並更新工作區 gco 代表 git checkout
# 列出所有本地分支 alias gb ='git branch'
# 列出所有本地分支和遠程分支 alias gba ='git branch -a'
 

 進入 ~/.zshrc配置文件,先給看下我的配置,可以憑自己喜好更改:

  vim ~/.zshrc

# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

# Path to your oh-my-zsh installation.
export ZSH="/Users/dunkhome/.oh-my-zsh"

# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="robbyrussell"

# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in $ZSH/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )

# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"
# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"

# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"

# Uncomment the following line to automatically update without prompting.
# DISABLE_UPDATE_PROMPT="true"

# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13

# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS=true

# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"
# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"

# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for completion.
# COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"

# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"

# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder

# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git)

source $ZSH/oh-my-zsh.sh

# User configuration

# export MANPATH="/usr/local/man:$MANPATH"

# You may need to manually set your language environment
# export LANG=en_US.UTF-8

# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
#   export EDITOR='vim'
# else
#   export EDITOR='mvim'
# fi

# Compilation flags
# export ARCHFLAGS="-arch x86_64"

# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#

 

設置主題

我們默認使用的主題叫做robbyrussel

Oh My Zsh默認自帶了一些默認主題,存放在~/.oh-my-zsh/themes目錄中。我們可以查看這些主題

➜  ~ git:(master) ✗ ls ~/.oh-my-zsh
CODE_OF_CONDUCT.md cache              oh-my-zsh.sh       tools
CONTRIBUTING.md    custom             plugins
LICENSE.txt        lib                templates
README.md          log                themes
➜  ~ git:(master) ✗ ls ~/.oh-my-zsh/themes
3den.zsh-theme                 kardan.zsh-theme
Soliah.zsh-theme               kennethreitz.zsh-theme
adben.zsh-theme                kiwi.zsh-theme
af-magic.zsh-theme             kolo.zsh-theme
afowler.zsh-theme              kphoen.zsh-theme
agnoster.zsh-theme             lambda.zsh-theme
alanpeabody.zsh-theme          linuxonly.zsh-theme
amuse.zsh-theme                lukerandall.zsh-theme
apple.zsh-theme                macovsky-ruby.zsh-theme
arrow.zsh-theme                macovsky.zsh-theme
aussiegeek.zsh-theme           maran.zsh-theme
avit.zsh-theme                 mgutz.zsh-theme
awesomepanda.zsh-theme         mh.zsh-theme
bira.zsh-theme                 michelebologna.zsh-theme
blinks.zsh-theme               mikeh.zsh-theme
bureau.zsh-theme               miloshadzic.zsh-theme
candy-kingdom.zsh-theme        minimal.zsh-theme
candy.zsh-theme                mira.zsh-theme
clean.zsh-theme                mortalscumbag.zsh-theme
cloud.zsh-theme                mrtazz.zsh-theme
crcandy.zsh-theme              murilasso.zsh-theme
crunch.zsh-theme               muse.zsh-theme
cypher.zsh-theme               nanotech.zsh-theme
dallas.zsh-theme               nebirhos.zsh-theme
darkblood.zsh-theme            nicoulaj.zsh-theme
daveverwer.zsh-theme           norm.zsh-theme
dieter.zsh-theme               obraun.zsh-theme
dogenpunk.zsh-theme            peepcode.zsh-theme
dpoggi.zsh-theme               philips.zsh-theme
dst.zsh-theme                  pmcgee.zsh-theme
dstufft.zsh-theme              pygmalion-virtualenv.zsh-theme
duellj.zsh-theme               pygmalion.zsh-theme
eastwood.zsh-theme             random.zsh-theme
edvardm.zsh-theme              re5et.zsh-theme
emotty.zsh-theme               refined.zsh-theme
essembeh.zsh-theme             rgm.zsh-theme
evan.zsh-theme                 risto.zsh-theme
fino-time.zsh-theme            rixius.zsh-theme
fino.zsh-theme                 rkj-repos.zsh-theme
fishy.zsh-theme                rkj.zsh-theme
flazz.zsh-theme                robbyrussell.zsh-theme
fletcherm.zsh-theme            sammy.zsh-theme
fox.zsh-theme                  simonoff.zsh-theme
frisk.zsh-theme                simple.zsh-theme
frontcube.zsh-theme            skaro.zsh-theme
funky.zsh-theme                smt.zsh-theme
fwalch.zsh-theme               sonicradish.zsh-theme
gallifrey.zsh-theme            sorin.zsh-theme
gallois.zsh-theme              sporty_256.zsh-theme
garyblessington.zsh-theme      steeef.zsh-theme
gentoo.zsh-theme               strug.zsh-theme
geoffgarside.zsh-theme         sunaku.zsh-theme
gianu.zsh-theme                sunrise.zsh-theme
gnzh.zsh-theme                 superjarin.zsh-theme
gozilla.zsh-theme              suvash.zsh-theme
half-life.zsh-theme            takashiyoshida.zsh-theme
humza.zsh-theme                terminalparty.zsh-theme
imajes.zsh-theme               theunraveler.zsh-theme
intheloop.zsh-theme            tjkirch.zsh-theme
itchy.zsh-theme                tjkirch_mod.zsh-theme
jaischeema.zsh-theme           tonotdo.zsh-theme
jbergantine.zsh-theme          trapd00r.zsh-theme
jispwoso.zsh-theme             wedisagree.zsh-theme
jnrowe.zsh-theme               wezm+.zsh-theme
jonathan.zsh-theme             wezm.zsh-theme
josh.zsh-theme                 wuffers.zsh-theme
jreese.zsh-theme               xiong-chiamiov-plus.zsh-theme
jtriley.zsh-theme              xiong-chiamiov.zsh-theme
juanghurtado.zsh-theme         ys.zsh-theme
junkfood.zsh-theme             zhann.zsh-theme
kafeitu.zsh-theme
➜  ~ git:(master) ✗ 

默認插件

Oh My Zsh 默認自帶了一些默認插件,存放在~/.oh-my-zsh/plugins目錄中。我們可以查看這些插件

➜  ~ git:(master) ✗ ls ~/.oh-my-zsh/plugins
adb                      git-extras               profiles
alias-finder             git-flow                 pyenv
ansible                  git-flow-avh             pylint
ant                      git-hubflow              python
apache2-macports         git-prompt               rails
arcanist                 gitfast                  rake
archlinux                github                   rake-fast
asdf                     gitignore                rand-quote
autoenv                  glassfish                rbenv
autojump                 globalias                rbfu
autopep8                 gnu-utils                react-native
aws                      go                       rebar
battery                  golang                   redis-cli
bazel                    gpg-agent                repo
bbedit                   gradle                   ripgrep
bgnotify                 grails                   ros
boot2docker              grunt                    rsync
bower                    gulp                     ruby
branch                   hanami                   rust
brew                     helm                     rustup
bundler                  heroku                   rvm
cabal                    history                  safe-paste
cake                     history-substring-search salt
cakephp3                 hitokoto                 sbt
capistrano               homestead                scala
cargo                    httpie                   scd
cask                     ionic                    screen
catimg                   iterm2                   scw
celery                   jake-node                sdk
chruby                   jenv                     sfdx
chucknorris              jfrog                    sfffe
cloudapp                 jhbuild                  shell-proxy
cloudfoundry             jira                     shrink-path
codeclimate              jruby                    singlechar
coffee                   jsontools                spring
colemak                  jump                     sprunge
colored-man-pages        kate                     ssh-agent
colorize                 keychain                 stack
command-not-found        kitchen                  sublime
common-aliases           knife                    sudo
compleat                 knife_ssh                supervisor
composer                 kops                     suse
copybuffer               kube-ps1                 svcat
copydir                  kubectl                  svn
copyfile                 laravel                  svn-fast-info
cp                       laravel4                 swiftpm
cpanm                    laravel5                 symfony
dash                     last-working-dir         symfony2
debian                   lein                     systemadmin
dircycle                 lighthouse               systemd
direnv                   lol                      taskwarrior
dirhistory               lxd                      terminitor
dirpersist               macports                 terraform
django                   magic-enter              textastic
dnf                      man                      textmate
dnote                    marked2                  thefuck
docker                   mercurial                themes
docker-compose           meteor                   thor
docker-machine           microk8s                 tig
doctl                    minikube                 timer
dotenv                   mix                      tmux
dotnet                   mix-fast                 tmux-cssh
droplr                   mosh                     tmuxinator
drush                    mvn                      torrent
eecms                    mysql-macports           transfer
emacs                    n98-magerun              tugboat
ember-cli                nanoc                    ubuntu
emoji                    ng                       ufw
emoji-clock              nmap                     urltools
emotty                   node                     vagrant
encode64                 nomad                    vagrant-prompt
extract                  npm                      vault
fabric                   npx                      vi-mode
fancy-ctrl-z             nvm                      vim-interaction
fasd                     oc                       virtualenv
fastfile                 osx                      virtualenvwrapper
fbterm                   otp                      vscode
fd                       pass                     vundle
fedora                   paver                    wakeonlan
firewalld                pep8                     wd
flutter                  per-directory-history    web-search
forklift                 percol                   wp-cli
fossil                   perl                     xcode
frontend-search          perms                    yarn
fzf                      phing                    yii
gas                      pip                      yii2
gatsby                   pipenv                   yum
gb                       pj                       z
gcloud                   please                   zeus
geeknote                 pod                      zsh-interactive-cd
gem                      postgres                 zsh-navigation-tools
git                      pow                      zsh_reload
git-auto-fetch           powder
git-escape-magic         powify
➜  ~ git:(master) ✗ 

 

默認是只有git

plugins=(git)

 

新增插件舉例 

  • 安裝zsh-syntax-highlighting語法高亮插件

下載插件

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git
echo "source ${(q-)PWD}/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc
 
編輯激活 ~/.zshrc配置文件
 
plugins=(git zsh-syntax-highlighting )
 
保存后 source一下,讓改變生效
 
source ~/.zshrc
 
發現再敲命令就有顏色了,比如命令有誤的時候是紅色,命令正確的時候是綠色。
 
 

軟件安裝位置:cd ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions

 

oh my zsh 手動更新,可以執行

upgrade_oh_my_zsh

卸載oh my zsh

直接在終端中,運行uninstall_oh_my_zsh既可以卸載。

備注:

 插件可以裝很多,但是裝多了之后會在每次進入命令提示符的時候明顯變慢。慎用。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM