diff --git a/alias.d/app.sh b/alias.d/app.sh new file mode 100755 index 0000000..b854e4b --- /dev/null +++ b/alias.d/app.sh @@ -0,0 +1,6 @@ +# shellcheck shell=ksh +alias typora="open -a typora" +alias goland='open -na "GoLand.app"' + +alias ngxt='dcrun ngx nginx -t' +alias ngxr='dcrun ngx nginx -s reload' \ No newline at end of file diff --git a/alias.d/code.sh b/alias.d/code.sh new file mode 100644 index 0000000..9e58cc7 --- /dev/null +++ b/alias.d/code.sh @@ -0,0 +1,9 @@ +# shellcheck shell=ksh + +# 快捷更改 配置文件 +alias va='code "$HOME"/.alias.d' +alias vssh='code "$HOME"/.ssh' +alias vdocker='code "$HOME"/docker.data' +alias vngx='code "$HOME"/.config/nginx' +alias vz='code "$HOME"/.zshrc' +alias rez='source "$HOME"/.zshrc' \ No newline at end of file diff --git a/alias.d/opt/clearmac.sh b/alias.d/opt/clearmac.sh new file mode 100755 index 0000000..91539a7 --- /dev/null +++ b/alias.d/opt/clearmac.sh @@ -0,0 +1,2 @@ +# shellcheck shell=ksh +find . -name .DS_Store -type f -delete ; find . -type d | xargs dot_clean -m \ No newline at end of file diff --git a/alias.d/opt/iterm2-recv-zmodem.sh b/alias.d/opt/iterm2-recv-zmodem.sh new file mode 100755 index 0000000..5d05308 --- /dev/null +++ b/alias.d/opt/iterm2-recv-zmodem.sh @@ -0,0 +1,25 @@ +#!/bin/bash +# Author: Matt Mastracci (matthew@mastracci.com) +# AppleScript from http://stackoverflow.com/questions/4309087/cancel-button-on-osascript-in-a-bash-script +# licensed under cc-wiki with attribution required +# Remainder of script public domain + +osascript -e 'tell application "iTerm2" to version' > /dev/null 2>&1 && NAME=iTerm2 || NAME=iTerm +if [[ $NAME = "iTerm" ]]; then + FILE=`osascript -e 'tell application "iTerm" to activate' -e 'tell application "iTerm" to set thefile to choose file with prompt "Choose a file to send"' -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Unicode text)&\"\")"` +else + FILE=`osascript -e 'tell application "iTerm2" to activate' -e 'tell application "iTerm2" to set thefile to choose file with prompt "Choose a file to send"' -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Unicode text)&\"\")"` +fi +if [[ $FILE = "" ]]; then + echo Cancelled. + # Send ZModem cancel + echo -e \\x18\\x18\\x18\\x18\\x18 + sleep 1 + echo + echo \# Cancelled transfer +else + /usr/local/bin/sz "$FILE" -e -b + sleep 1 + echo + echo \# Received $FILE +fi \ No newline at end of file diff --git a/alias.d/opt/iterm2-send-zmode.sh b/alias.d/opt/iterm2-send-zmode.sh new file mode 100755 index 0000000..5d05308 --- /dev/null +++ b/alias.d/opt/iterm2-send-zmode.sh @@ -0,0 +1,25 @@ +#!/bin/bash +# Author: Matt Mastracci (matthew@mastracci.com) +# AppleScript from http://stackoverflow.com/questions/4309087/cancel-button-on-osascript-in-a-bash-script +# licensed under cc-wiki with attribution required +# Remainder of script public domain + +osascript -e 'tell application "iTerm2" to version' > /dev/null 2>&1 && NAME=iTerm2 || NAME=iTerm +if [[ $NAME = "iTerm" ]]; then + FILE=`osascript -e 'tell application "iTerm" to activate' -e 'tell application "iTerm" to set thefile to choose file with prompt "Choose a file to send"' -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Unicode text)&\"\")"` +else + FILE=`osascript -e 'tell application "iTerm2" to activate' -e 'tell application "iTerm2" to set thefile to choose file with prompt "Choose a file to send"' -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Unicode text)&\"\")"` +fi +if [[ $FILE = "" ]]; then + echo Cancelled. + # Send ZModem cancel + echo -e \\x18\\x18\\x18\\x18\\x18 + sleep 1 + echo + echo \# Cancelled transfer +else + /usr/local/bin/sz "$FILE" -e -b + sleep 1 + echo + echo \# Received $FILE +fi \ No newline at end of file diff --git a/alias.d/opt/keep_en0.sh b/alias.d/opt/keep_en0.sh new file mode 100755 index 0000000..18687ca --- /dev/null +++ b/alias.d/opt/keep_en0.sh @@ -0,0 +1,6 @@ +# shellcheck shell=ksh +# Ethernet Address: 54:8d:5a:84:1b:15 (Device: en0) +hack_mac="0b:b7:f6:21:bd:0c" +/sbin/ifconfig en0 up +/sbin/ifconfig en0 ether "$hack_mac" +echo "$(date "+%Y-%m-%d %H:%M:%S")" write en0 "$hack_mac" \ No newline at end of file diff --git a/alias.d/opt/mac2str.sh b/alias.d/opt/mac2str.sh new file mode 100755 index 0000000..2e9d5fa --- /dev/null +++ b/alias.d/opt/mac2str.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# 读取用户输入的 MAC 地址 +if [ $# -eq 0 ]; then + read -p "请输入 MAC 地址:" mac_address +else + mac_address="$1" + echo "输入的 MAC 地址:" "$mac_address" +fi + +# 将 MAC 地址转为大写并去掉其中的分隔符 +formatted_mac=$(echo $mac_address | tr -d ':' | tr '[:lower:]' '[:upper:]') + +# 输出处理后的 MAC 地址 +echo "处理后的 MAC 地址为:$formatted_mac" \ No newline at end of file diff --git a/alias.d/opt/notion_update.sh b/alias.d/opt/notion_update.sh new file mode 100755 index 0000000..32b4766 --- /dev/null +++ b/alias.d/opt/notion_update.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +folder="/Applications/Notion.app/Contents/Resources/app/renderer" +preloadJs="/Applications/Notion.app/Contents/Resources/app/renderer/preload.js" +remoteUrl="https://github.com/Reamd7/notion-zh_CN/raw/main/notion-zh_CN.js" + +name="notion-zh_CN" +dst="$name.js" +if [ -w "$preloadJs" ]; then +# curl -L -o "/Applications/Notion.app/Contents/Resources/app/renderer/notion-zh_CN.js" https://github.com/Reamd7/notion-zh_CN/raw/main/notion-zh_CN.js + curl -L -o "$folder/$dst" "$remoteUrl" + + listLine=$(tail -n 1 $preloadJs) + if [ "$listLine" != "require('./$name')" ]; then + echo "require('./$name')" >> $preloadJs + fi +fi \ No newline at end of file diff --git a/alias.d/opt/rm_repate.sh b/alias.d/opt/rm_repate.sh new file mode 100755 index 0000000..66e1f82 --- /dev/null +++ b/alias.d/opt/rm_repate.sh @@ -0,0 +1,23 @@ +#!/bin/bash +dir="$HOME/Documents/SyncDir/Profile" +name=$(scutil --get ComputerName) + +dst="$dir/$name/" + +if [ "$#" -eq 0 ]; then + dir="$dst" +else + dir="$1" +fi + + +echo "scan in $dir" + +for file in "$dir"/*; do # 遍历目录下的所有文件和子目录 + if [ -f "$file" ] && [[ "$file" == *" "*[0-9]* ]]; then # 如果是普通文件且以数字结尾 + rm "$file" # 删除文件 + echo "Deleted $file" # 输出删除文件的信息 + elif [[ -d "$file" ]]; then # 如果是子目录 + "$0" "$file" # 递归调用脚本处理子目录 + fi +done \ No newline at end of file diff --git a/alias.d/opt/sync.sh b/alias.d/opt/sync.sh new file mode 100755 index 0000000..24d47b9 --- /dev/null +++ b/alias.d/opt/sync.sh @@ -0,0 +1,26 @@ +# shellcheck shell=ksh +# 00 */2 * * * $HOME/.alias.d/opt/sync.sh >> $HOME/.alias.d/log/sync.log + +dir="$HOME/Documents/SyncDir/Profile" +# name=$(scutil --get LocalHostName) +name="evlicn" + +dst="$dir/$name/" + +if [ ! -d "$dst" ]; then + mkdir -p "$dst" + echo "$(date "+%Y-%m-%d %H:%M:%S")" make work dir + echo -e "\t" mkdir -p "$dst" +else + echo "$(date "+%Y-%m-%d %H:%M:%S")" work in "$dst" +fi +echo sync dist is "\"$dst\"" +sync_dirs=("$HOME/.alias.d" "$HOME/.ssh" "$HOME/docker.data") +echo "$(date "+%Y-%m-%d %H:%M:%S")" sync_dirs: "${sync_dirs[@]}" + # sudo chmod -R +x "$dir" +for dir in "${sync_dirs[@]}" +do + sudo rsync -av --exclude="*.log" "$dir" "$dst" +done +echo "$(date "+%Y-%m-%d %H:%M:%S")" sync finsh save in "$dst" +echo "" \ No newline at end of file diff --git a/alias.d/opt/test_cron.sh b/alias.d/opt/test_cron.sh new file mode 100755 index 0000000..6eeec86 --- /dev/null +++ b/alias.d/opt/test_cron.sh @@ -0,0 +1,4 @@ +# shellcheck shell=ksh +source "$HOME/.zshrc" +echo "$(date "+%Y-%m-%d %H:%M:%S")" LocalHostName "$(scutil --get LocalHostName)" HostName "$(scutil --get HostName)" ComputerName "$(scutil --get ComputerName)" +env \ No newline at end of file diff --git a/alias.d/osx.sh b/alias.d/osx.sh new file mode 100755 index 0000000..70c6932 --- /dev/null +++ b/alias.d/osx.sh @@ -0,0 +1,19 @@ +# shellcheck shell=ksh +# osx 专属快捷 shell +fn="Wi-Fi" +alias netls="networksetup -listallnetworkservices" +alias dns_get='networksetup -getdnsservers ${fn}' + +dns_rst() { + t_dns="$1" + if [ $# -eq 0 ] + then + t_dns="8.8.8.8" + fi + networksetup -setdnsservers "$fn" "$t_dns" +} + +shell_dir="$HOME/.alias.d/opt" + +alias clearmac="zsh '$shell_dir/clearmac.sh'" +alias PBE='open /Applications/League\ of\ Legends\ \(PBE\).app --args --locale=zh_CN' \ No newline at end of file diff --git a/alias.d/path.sh b/alias.d/path.sh new file mode 100755 index 0000000..a9c8cc0 --- /dev/null +++ b/alias.d/path.sh @@ -0,0 +1,7 @@ +# shellcheck shell=ksh + +# WorkSpace +alias atcode='cd ~/AtCode' +alias atgo='cd ~/AtCode/go' +alias atdocker='cd ~/docker.data' +alias hugowf='cd ~/AtCode/HugoWorkFlow' diff --git a/alias.d/proxy.sh b/alias.d/proxy.sh new file mode 100755 index 0000000..e2f2261 --- /dev/null +++ b/alias.d/proxy.sh @@ -0,0 +1,8 @@ +# shellcheck shell=ksh + +# 代理 +export PROXY_END="$(hostname):7890" +alias enproxy="export https_proxy=http://$PROXY_END:7890 http_proxy=http://$PROXY_END:7890 all_proxy=socks5://$PROXY_END:7890" +alias unproxy="unset https_proxy http_proxy all_proxy && git config --global --unset http.proxy && git config --global --unset https.proxy" +alias isproxy="env|grep -i proxy" +alias gitp="git clone -c http.proxy='http://$PROXY_END:7890' " diff --git a/alias.d/script.sh b/alias.d/script.sh new file mode 100755 index 0000000..c557129 --- /dev/null +++ b/alias.d/script.sh @@ -0,0 +1,23 @@ +# shellcheck shell=ksh + +# sync 同步脚本 +alias syncggok="curl -o /Users/evlic/Library/Mobile\ Documents/iCloud~com~west2online~ClashX/Documents/ggok.self.yaml 'https://sub.evlic.cn/sub?target=clashr&new_name=true&url=https%3A%2F%2Fd.evlic.cn%2Fpublic%2Fconfig%2Fv2ray%2Fggok.ini&insert=false&config=config%2FACL4SSR.ini';scp /Users/evlic/Library/Mobile\ Documents/iCloud~com~west2online~ClashX/Documents/ggok* cloud:/home/d/public/config/clash/" +alias syncv2="ssh cloud 'source ~/.zshrc; curl -o /home/d/public/config/v2ray/ggok.ini https://rss.okggrss.buzz/link/07fnJG5GZQpc9KzD?mu=2'" + +shell_dir="$HOME/.alias.d/opt" + +up_notion() { + zsh "$shell_dir/notion_update.sh" +} + +giff() { + fd=$(mktemp) + commit_id="$1" + if [ "$commit_id" == '' ]; then + commit_id="HEAD~1" + fi + + git diff --stat "$commit_id" >> "$fd" + tail -n 1 "$fd" + rm "$fd" +} \ No newline at end of file diff --git a/alias.d/tmux.sh b/alias.d/tmux.sh new file mode 100644 index 0000000..de68dad --- /dev/null +++ b/alias.d/tmux.sh @@ -0,0 +1,5 @@ +# shellcheck shell=ksh + +export TMUX_WORK_NAME="local" +alias work_tmux='tmux -CC attach -t $TMUX_WORK_NAME' +alias new_tmux='tmux -CC new -s $TMUX_WORK_NAME' diff --git a/install-alias.sh b/install-alias.sh index 5e9df41..5d827cd 100755 --- a/install-alias.sh +++ b/install-alias.sh @@ -10,25 +10,25 @@ _check() { echo "看起来设备已经安装 alias, $rc_file 中包含 source $alias_init_file" echo -n "请输入(y/n):" read -r _continue - echo "in >> $_continue" + case "$_continue" in y | Y) # 如果输入 y 或 Y,则用 sed 命令删除 source $alias_init_file 这一行 - sed -i "/source $alias_init_file/d" $rc_file - echo "覆盖 source $alias_init_file" + awk '!/source "$alias_init_file"/' "$rc_file" > tmpfile && mv tmpfile "$rc_file" + echo "##### 覆盖 source $alias_init_file ######" ;; *) - echo "退出安装" + echo "##### 退出安装 #####" exit 3 ;; esac fi - echo "安装 alias.d 正在自动配置环境变量... source $alias_init_file" + echo "##### 安装 alias.d 正在自动配置环境变量... #####" } _install() { rsync -a --backup --suffix=.bak ./alias.d "$HOME/" - echo "install success, enjoy it!" + echo "###### install success, enjoy it! #####" source "$alias_init_file" }