macos安装git命令行_Mac中设置git、docker命令行自动补全

本文介绍了在Mac上安装Homebrew,然后通过brew安装bash-completion,以此实现git和docker命令行的自动补全功能。详细步骤包括添加相关指令到~/.bash_profile,下载并链接git和docker的补全脚本。
摘要由CSDN通过智能技术生成

安装Homebrew

首先需要安装Homebrew,可在官网首页找到安装方法:/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

安装bash-completion

然后使用brew安装bash-completion:brew install bash-completion

安装之后调用 brew info bash-completion 命令,根据提示将指令添加到 ~/.bash_profile 中:➜  brew info bash-completion

bash-completion: stable 1.3 (bottled)

Programmable completion for Bash 3.2

https://salsa.debian.org/debian/bash-completion

Conflicts with:

bash-completion@2 (because Differing version of same formula)

/usr/local/Cellar/bash-completion/1.3_3 (189 files, 607.9KB) *

Poured from bottle on 2020-05-04 at 01:32:28

From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/bash-completion.rb

==> Caveats

Add the following line to your ~/.bash_profile:

[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"

Bash completion has been installed to:

/usr/local/etc/bash_completion.d

==> Analytics

install: 10,733 (30 days), 36,745 (90 days), 167,689 (365 days)

install-on-request: 9,927 (30 days), 33,958 (90 days), 154,120 (365 days)

build-error: 0 (30 days)

将如下加入 ~/.bash_profile 中[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"

下载git补全脚本

添加git补全支持# 进入目录

➜  ~ cd /usr/local/etc/bash_completion.d

# 下载脚本

➜  bash_completion.d curl -L -O http://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash

% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

Dload  Upload   Total   Spent    Left  Speed

0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0

100 73053  100 73053    0     0  68465      0  0:00:01  0:00:01 --:--:--  299k

# 软连接

➜  bash_completion.d brew unlink bash-completion

Unlinking /usr/local/Cellar/bash-completion/1.3_3... 182 symlinks removed

➜  bash_completion.d brew link bash-completion

Linking /usr/local/Cellar/bash-completion/1.3_3... 182 symlinks created

docker补全脚本

本地补全脚本

安装docker后,本地补全脚本可以在/Applications/Docker.app/Contents/Resources/etc/docker.bash-completion路径下找到。

➜  ~ cd /usr/local/etc/bash_completion.d

➜  bash_completion.d ln -s /Applications/Docker.app/Contents/Resources/etc/docker.bash-completion

➜  bash_completion.d ln -s /Applications/Docker.app/Contents/Resources/etc/docker-machine.bash-completion

➜  bash_completion.d ln -s /Applications/Docker.app/Contents/Resources/etc/docker-compose.bash-completion

安装完成如下,重启终端即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值