nvs 管理 node 版本
export NVS_HOME="$HOME/git/nvs"
git clone https://github.com/cnpm/nvs --depth=1 "$NVS_HOME"
sh "$NVS_HOME/nvs.sh" install
source "$NVS_HOME/nvs.sh"
配置一个脚本可以一键提交部署,如果不存在则新建分支
在本地路径 /code/shell 新增一个 test.sh 脚本,内容如下:
#!/bin/bash
CURRENT_BRANCH=$(git symbolic-ref --short HEAD)
REMOTE_BRANCH=$(git rev-parse --abbrev-ref --symbolic-full-name @{u} 2>/dev/null)
echo "开始保存代码"
git add .
git commit -m "$1"
echo "开始推送远程仓库"
if [ -z "$REMOTE_BRANCH" ]; then
echo "The current branch $CURRENT_BRANCH has no upstream branch."
echo "Pushing the current branch and setting the remote as upstream..."
git push --set-upstream origin "$CURRENT_BRANCH"
else
git push
fi
在终端输入 vim .zshrc,新加一行配置
alias hello=~/code/shell/test.sh
新增完之后需要刷新一下
命令行输入 source .zshrc
如何使用
hello "feat: first commit"
配置跨域
- mac 在以下 /Users/你的用户名/documents 目录创建 MyChromeDevUserData 文件夹
- 需要一个低版本的 chrome 应该是 90 版本左右
- 设置浏览器 sameSite
- 终端输入
同理先新建一个脚本
#!/bin/bash
echo "正在打开跨域浏览器"
open -n "/Applications/Google Chrome.app" --args --disable-web-security --user-data-dir=/Users/你的用户名/documents/MyChromeDevUserData
echo "打开成功"
定制别名和第一步类似,可以参考
给脚本权限 chmod +x /Users/你的用户名/code/shell/open.sh
92 以上 chrome 解决跨域方案,使用浏览器插件同步 cookie 就行,以下是插件的核心代码
autoSyncCookiesEvent();
function autoSyncCookiesEvent() {
console.log('start autoSyncCookiesEvent');
chrome.cookies.onChanged.addListener(async (params = {}) => {
const { cookie: { domain, name, value } = {} } = params;
const localStorage = await chrome.storage.local.get();
const { domainList = [] } = localStorage || {};
domainList.forEach(async (item = {}) => {
const { isAuto = false, source, target, cookieNameList = [] } = item;
if (!isAuto) return;
// 1. 过滤域名
if (removeProtocol(source) === domain) {
// 2. 过滤name
const flag = cookieNameList.findIndex((cookieName) => cookieName === name) !== -1;
if (!flag) return;
// 3. 更新目标地址的cookie
await chrome.cookies.set({
url: addProtocol(target),
domain: removeProtocol(target),
name,
path: '/',
value
});
}
});
});
}
const addProtocol = (uri) => {
return uri.startsWith('http') ? uri : `http://${uri}`;
};
// 移除协议头
const removeProtocol = (uri) => {
return uri.startsWith('http') ? uri.replace('http://', '').replace('https://', '') : uri;
};