Skip to content

Commit

Permalink
Backup on: Wed Sep 28 09:16:00 CST 2022
Browse files Browse the repository at this point in the history
  • Loading branch information
GodD6366 committed Sep 28, 2022
1 parent 007bf94 commit 140a54f
Show file tree
Hide file tree
Showing 7 changed files with 236 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib
17 changes: 17 additions & 0 deletions _init/raycast.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

rm -rf ~/dotfiles/lib
# mkdir lib

cp -r ~/dotfiles/macos/raycast ~/dotfiles/lib

# 获取 node 地址
CURRENT_NODE_PATH=$(which node)

echo $CURRENT_NODE_PATH

sed -i "" "s?CURRENT_NODE_PATH?"$CURRENT_NODE_PATH"?" ~/dotfiles/lib/fanyi.js
sed -i "" "s?CURRENT_NODE_PATH?"$CURRENT_NODE_PATH"?" ~/dotfiles/lib/timeParser.js
sed -i "" "s?CURRENT_NODE_PATH?"$CURRENT_NODE_PATH"?" ~/dotfiles/lib/cdn.js

exit 0
24 changes: 12 additions & 12 deletions _install/macos.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ install_packages() {
jq
wget
zsh
thefuck
)

echo "==========================================================="
Expand Down Expand Up @@ -84,21 +85,20 @@ setup_omz() {
echo " - zsh-z"
echo "-----------------------------------------------------------"

export ZSH_CUSTOM_WITH_DEF=${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}

git clone https://github.com/Aloxaf/fzf-tab $ZSH_CUSTOM_WITH_DEF/plugins/fzf-tab
git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM_WITH_DEF/plugins/zsh-autosuggestions
# git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM_WITH_DEF/plugins/zsh-syntax-highlighting
git clone https://github.com/zdharma/fast-syntax-highlighting.git $ZSH_CUSTOM_WITH_DEF/plugins/F-Sy-H
git clone https://github.com/mafredri/zsh-async.git $ZSH_CUSTOM_WITH_DEF/plugins/zsh-async
git clone https://github.com/sukkaw/zsh-gitcd.git $ZSH_CUSTOM_WITH_DEF/plugins/zsh-gitcd
git clone https://github.com/agkozak/zsh-z $ZSH_CUSTOM_WITH_DEF/plugins/zsh-z
git clone https://github.com/Aloxaf/fzf-tab ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/fzf-tab
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
# git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
git clone https://github.com/zdharma/fast-syntax-highlighting.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/F-Sy-H
git clone https://github.com/mafredri/zsh-async.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-async
git clone https://github.com/sukkaw/zsh-gitcd.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-gitcd
git clone https://github.com/agkozak/zsh-z ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-z

# git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

# git clone --depth=1 https://github.com/romkatv/powerlevel10k.git $ZSH_CUSTOM_WITH_DEF/themes/powerlevel10k

echo "安装 spaceship 主题"
git clone https://github.com/spaceship-prompt/spaceship-prompt.git $ZSH_CUSTOM_WITH_DEF/themes/spaceship-prompt --depth=1
ln -s $ZSH_CUSTOM_WITH_DEF/themes/spaceship-prompt/spaceship.zsh-theme $ZSH_CUSTOM_WITH_DEF/themes/spaceship.zsh-theme
git clone https://github.com/spaceship-prompt/spaceship-prompt.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/spaceship-prompt --depth=1
ln -s ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/spaceship-prompt/spaceship.zsh-theme $ZSH_CUSTOM_WITH_DEF/themes/spaceship.zsh-theme

}

Expand Down
14 changes: 3 additions & 11 deletions brew/install_backup.sh → install_backup.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
#! /bin/bash
###
# @Description :
# @Author : jsmjsm
# @Github : https://github.com/jsmjsm
# @Date : 2021-07-13 13:43:36
# @LastEditors : jsmjsm
# @LastEditTime : 2021-07-13 19:32:59
# @FilePath : /BrewMyMac/install_backup.sh
###

# 全局变量
WD=`pwd`
# > 安装自动备份脚本到 contab
Expand All @@ -22,7 +14,7 @@ install_to_crontab() {
echo
echo SHELL=$SHELL > crontab_conf
echo PATH=$PATH >> crontab_conf
echo "00 12 * * * $script > /tmp/BrewMyMac_Backup.log && osascript -e 'display notification \"$WD/backup\" with title \"程序列表备份成功, 已上传至 GitHub\" '" >> crontab_conf
echo "00 12 * * * $script > /tmp/dotfiles_Backup.log && osascript -e 'display notification \"$WD/brew/backup\" with title \"dotfiles 备份成功, 已上传至 GitHub\" '" >> crontab_conf
echo "运行 \$ crontab -e"

echo "插入以下内容: "
Expand All @@ -34,7 +26,7 @@ install_to_crontab() {
crontab -l > crontab_conf
echo SHELL=$SHELL >> crontab_conf
echo PATH=$PATH >> crontab_conf
echo "00 12 * * * $script > /tmp/BrewMyMac_Backup.log && osascript -e 'display notification \"$WD/backup\" with title \"程序列表备份成功, 已上传至 GitHub\" '" >> crontab_conf
echo "00 12 * * * $script > /tmp/dotfiles_Backup.log && osascript -e 'display notification \"$WD/backup\" with title \"dotfiles 备份成功, 已上传至 GitHub\" '" >> crontab_conf
crontab crontab_conf && rm -f crontab_conf

echo "🎉 自动化备份脚本安装完成"
Expand Down
50 changes: 50 additions & 0 deletions macos/raycast/cdn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!CURRENT_NODE_PATH

// Raycast Script Command Template
// https://github.com/raycast/script-commands
//
// Required parameters:
// @raycast.schemaVersion 1
// @raycast.title cdn
// @raycast.mode fullOutput
//
// Optional parameters:
// @raycast.icon ✈️
// @raycast.packageName cdn
// @raycast.argument1 { "type": "text", "placeholder": "输入 github 地址", "optional": true }

const execa = require('execa');

const REG = /.*\/gh\/([^\/]+)\/([^\/]+)\/([^\/]+).*/;

let [link = ''] = process.argv.slice(2);

if (!link) {
const { stdout } = execa.sync('pbpaste');
link = stdout;
}

console.log(`${fnGetCDNUrl(link)}`);

// https://github.com/lhie1/Rules/blob/master/Clash/Provider/Media/Disney%20Plus.yaml
// https://raw.githubusercontent.com/lhie1/Rules/master/Clash/Provider/Media/Disney%20Plus.yaml

// https://cdn.jsdelivr.net/gh/lhie1/Rules@master/Clash/Provider/Media/Disney%20Plus.yaml

function fnGetCDNUrl(url) {
const arrMap = [
['https://github.com/', 'https://cdn.jsdelivr.net/gh/'],
['https://raw.githubusercontent.com/', 'https://cdn.jsdelivr.net/gh/'],
['/blob', ''],
];
let cdnUrl = url;
arrMap.forEach((line) => {
cdnUrl = cdnUrl.replace(line[0], line[1]);
});

const [_, githubName, projectName, br] = REG.exec(cdnUrl);
return cdnUrl.replace(
`${githubName}/${projectName}/${br}`,
`${githubName}/${projectName}@${br}`,
);
}
132 changes: 132 additions & 0 deletions macos/raycast/fanyi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#!CURRENT_NODE_PATH

// Raycast Script Command Template
// https://github.com/raycast/script-commands
//
// Required parameters:
// @raycast.schemaVersion 1
// @raycast.title fanyi
// @raycast.mode fullOutput
//
// Optional parameters:
// @raycast.icon 📖
// @raycast.packageName fy
// @raycast.argument1 { "type": "text", "placeholder": "请输入要翻译的单词", "optional": true }

const execa = require('execa');
const axios = require('axios');

let [word = ''] = process.argv.slice(2);

if (!word) {
const { stdout } = execa.sync('pbpaste');
word = stdout;
}

const isEnglish = new RegExp('[A-Za-z]+');

/**
* ZH_CN2EN 中文 » 英语
* EN2ZH_CN 英语 » 中文
*/
const YOUDAO_EN2ZH_CN =
'http://fanyi.youdao.com/translate?&doctype=json&type=EN2ZH_CN&i=';

const YOUDAO_ZH_CN2EN =
'http://fanyi.youdao.com/translate?&doctype=json&type=ZH_CN2EN&i=';

const YOUDAO_API =
'http://fanyi.youdao.com/openapi.do?keyfrom=imgxqb&key=1185055258&type=data&doctype=json&version=1.1&q=';

const GOOGLE_API =
'http://translate.google.cn/translate_a/single?client=gtx&dt=t&dj=1&ie=UTF-8&sl=auto&tl=zh_ch&q=';

const GOOGLE_API_CH2EN =
'http://translate.google.cn/translate_a/single?client=gtx&dt=t&dj=1&ie=UTF-8&sl=zh_ch&tl=en&q=';

const errorList = [];

Promise.all([
translateWithYoudao(),
translateWithNewYoudao(),
translateWithGoogle(),
])
.then((values) => {
const data = values.find((value) => value.success);
console.log(`
翻译结果:${data.result.map((str) => `\n - ${str}`)}
${
data.explains
? `单词解释:${data.explains.map((str) => `\n - ${str}`)}`
: ''
}`);
})
.catch(() => {
console.log(errorList.map((e) => `\n${e}`).join(''));
});

function translateWithYoudao() {
return axios
.get(`${YOUDAO_API}${encodeURIComponent(word)}`)
.then(function (response) {
const { data } = response;
return {
success: true,
name: '有道翻译',
result: data.translation.map((tr) => tr),
explains: data.basic.explains.map((tr) => tr),
};
})
.catch(function (error) {
errorList.push(`使用有道 API 翻译失败!报错信息如下:
${error.message}`);
return { success: false };
});
}

function translateWithNewYoudao() {
let api = YOUDAO_EN2ZH_CN;
if (!isEnglish.test(word)) {
api = YOUDAO_ZH_CN2EN;
}

return axios
.get(`${api}${encodeURIComponent(word)}`)
.then(function (response) {
const { data } = response;
return {
success: true,
name: '有道翻译 v2',
result: data.translateResult.map((tr) => tr[0].tgt),
};
})
.catch(function (error) {
errorList.push(`使用有道 NEWAPI 翻译失败!报错信息如下:
${error.message}`);
return { success: false };
});
}

function translateWithGoogle() {
let api = GOOGLE_API;
if (!isEnglish.test(word)) {
api = GOOGLE_API_CH2EN;
}

return axios
.get(`${api}${encodeURIComponent(word)}`)
.then(function (response) {
const { data } = response;
return {
success: true,
name: '谷歌翻译',
result: data.sentences.map((tr) => tr.trans),
};
})
.catch(function (error) {
errorList.push(`使用 Google API 翻译失败!报错信息如下:
${error.message}`);
return { success: false };
});
}
21 changes: 21 additions & 0 deletions macos/raycast/timeParser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!CURRENT_NODE_PATH

// Raycast Script Command Template
// https://github.com/raycast/script-commands
//
// Required parameters:
// @raycast.schemaVersion 1
// @raycast.title timeParser
// @raycast.mode fullOutput
//
// Optional parameters:
// @raycast.icon ⌚️
// @raycast.packageName time
// @raycast.argument1 { "type": "text", "placeholder": "时间戳" }

const dayjs = require('dayjs');
let [dateStr = ''] = process.argv.slice(2);

console.log(
`当前时间:${dayjs(Number(dateStr)).format('YYYY-MM-DD HH:mm:ss')}`
);

0 comments on commit 140a54f

Please sign in to comment.