不要问为什么非得这么干。是的,优秀的笔记软件那么多,选一个够用。
(1)跨平台,同时支持桌面电脑(Windows,Mac,Linux)
(2)随时同步,打开任何一台机器,都能接着上一次的工作继续写。
(3)自动存储
(4)支持 Markdown 格式,便于后期直接发布。
(5)支持推送到远程 Git 仓库,产生历史版本,同时作为远程备份
概述
graph TD
本地仓库 --> 同步(crontab 定时 git pull/push)
同步 --> 远程仓库
- 本地文件可以充分使用各种 vscode、xmind、wps 等优秀软件
- 同步策略可以通过修改脚本自由定制,不想推送的文件等也可以通过 git 自由忽略
- 远程仓库可以自由迁移,YX笔记的收费策略我就很不爽,果断弃了,完全可以自行搭建 Git 仓库
- 本地创建一个知识库的文件夹
note
mkdir note
- 新建一个远程的 Git 仓库,与本地知识库关联(gitlab和运效等都会有关联步骤提示)
cd /path/to/your/note
git init
git add .
git commit -m "Initial commit"
git remote add origin https://github.com/username/repo.git
git push -u origin master
- 新建仓库自动同步脚本
在脚本中使用 git 命令去检查本地仓库是否有更新、远程仓库是否有新的提交,将远程提交拉取到本地,将本地修改提交到远程仓库
#!/bin/bash
echo -e "\033[35m
,--. ,--. ,-----. ,--------.,------.
| '--' |' .-. ''--. .--'| .---'
| .--. || | | | | | | \`--,
| | | |' '-' ' | | | \`---.
\`--' \`--' \`-----' \`--' \`------'
\033[0m"
prefix="\033[33m###\033[0m $(date '+%Y-%m-%d %H:%M:%S')"
echo -e "$prefix 开始同步\033[36mHOTE\033[0m"
cd ~/Project/hoo/hote
status_output=$(git status)
echo -e "$prefix 本地仓库状态:"
echo "$status_output"
# 本地没有修改
if [[ $status_output == *"无文件要提交,干净的工作区"* ||
$status_output == *"nothing to commit, working tree clean"* ]]; then
echo -e "$prefix 没有需要同步的文件,检查远程仓库是否有变更"
# 更新本地仓库, 确认远程是否有修改
git fetch origin master
status_output=$(git status)
echo "$status_output"
# 判断 status_output 的长度,大于 0 则有变更,使用 git pull 拉取远程更新
if [[ $status_output == *"git pull"* ]]; then
echo -e "$prefix 远程仓库有变更,更新本"
git pull origin master --rebase
fi
echo -e "$prefix 同步结束\033[36mHOTE\033[0m"
exit 0
fi
echo -e "$prefix 提交修改"
git add .
git commit -m "auto sync"
echo -e "$prefix 拉取远程仓库"
git pull origin master --rebase
echo -e "$prefix 推送到远程仓库"
git push origin master
echo -e "$prefix 同步结束\033[36mHOTE\033[0m"
- 创建仓库自动同步任务
利用 crontab 创建本地定时任务,每 10 分钟执行一次更新同步作业
crontab -e
0/10 8-23 * * * /Users/username/sync.sh >> /Users/username/Project/note/.log/note_sync.log 2>&1