前言
日常开发中总有一些命令记不住,每次都要去搜。本文整理了一些高频使用的实用技巧,方便随时查阅。
一、临时代理设置
国内访问某些国外资源时,经常需要使用代理。以下是几种设置方式:
1. 当前终端会话设置
1 2 3 4 5 6 7
| export https_proxy=http://127.0.0.1:7897 export http_proxy=http://127.0.0.1:7897 export all_proxy=socks5://127.0.0.1:7897
unset http_proxy https_proxy all_proxy
|
2. 一行设置(推荐)
1 2 3 4 5
| export {http,https,all}_proxy=http://127.0.0.1:7897
unset {http,https,all}_proxy
|
3. 单次命令生效
1 2 3 4 5
| http_proxy=http://127.0.0.1:7897 curl https://google.com
https_proxy=http://127.0.0.1:7897 git push
|
4. 添加快捷函数到 Shell
在 ~/.zshrc 或 ~/.bashrc 中添加:
1 2 3 4 5 6 7 8 9 10
| proxy_on() { export {http,https,all}_proxy=http://127.0.0.1:7897 echo "代理已开启" }
proxy_off() { unset {http,https,all}_proxy echo "代理已关闭" }
|
使用方式:
5. 测试代理是否生效
1 2 3 4 5 6 7 8
| env | grep -i proxy
curl -I https://google.com
curl ipinfo.io
|
二、VS Code 扩展管理
1. 命令行管理扩展
1 2 3 4 5 6 7 8
| code --list-extensions
code --install-extension <extension-id>
code --uninstall-extension <extension-id>
|
2. 临时禁用扩展
面试或考试时,可能需要禁用 AI 辅助工具:
1 2 3 4 5 6
| code --disable-extension github.copilot-chat \ --disable-extension openai.chatgpt
code --disable-extensions
|
3. 在 VS Code 中禁用扩展
- 按
Cmd+Shift+X 打开扩展面板
- 搜索
@installed 查看已安装扩展
- 找到目标扩展,点击齿轮图标 → Disable
4. 常见 AI 扩展 ID
| 扩展名称 |
ID |
| GitHub Copilot Chat |
github.copilot-chat |
| GitHub Copilot |
github.copilot |
| OpenAI ChatGPT |
openai.chatgpt |
| Codeium |
Codeium.codeium |
| Tabnine |
TabNine.tabnine-vscode |
| Continue |
Continue.continue |
三、Git 常用技巧
1. Git 代理设置
1 2 3 4 5 6 7 8 9 10
| git config --global http.proxy http://127.0.0.1:7897 git config --global https.proxy http://127.0.0.1:7897
git config --global --unset http.proxy git config --global --unset https.proxy
git config --global --list | grep proxy
|
2. 临时使用代理
1 2 3 4 5
| https_proxy=http://127.0.0.1:7897 git push origin main
https_proxy=http://127.0.0.1:7897 git clone https://github.com/user/repo.git
|
3. 常用快捷命令
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| git log --oneline -10
git reset --soft HEAD~1
git checkout -- <file>
git remote -v
git remote set-url origin <new-url>
|
四、网络调试命令
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| lsof -i :7897
netstat -an | grep LISTEN
nc -zv 127.0.0.1 7897
ps aux | grep <process-name>
kill -9 <PID>
|
五、系统代理配置
macOS 系统代理
通过命令行设置系统级代理:
1 2 3 4 5 6 7 8 9 10 11 12 13
| networksetup -setwebproxy "Wi-Fi" 127.0.0.1 7897 networksetup -setwebproxystate "Wi-Fi" on
networksetup -setwebproxystate "Wi-Fi" off
networksetup -setsecurewebproxy "Wi-Fi" 127.0.0.1 7897 networksetup -setsecurewebproxystate "Wi-Fi" on
networksetup -setsecurewebproxystate "Wi-Fi" off
|
总结
| 场景 |
命令 |
| 开启代理 |
export {http,https,all}_proxy=http://127.0.0.1:7897 |
| 关闭代理 |
unset {http,https,all}_proxy |
| 禁用 VS Code 扩展 |
code --disable-extension <id> |
| 无扩展启动 VS Code |
code --disable-extensions |
| 设置 Git 代理 |
git config --global http.proxy http://127.0.0.1:7897 |
| 查看端口占用 |
lsof -i :<port> |
建议把常用的函数加到 Shell 配置文件中,形成自己的”工具箱”。
参考资料: