feat: add more shell

This commit is contained in:
🐟 2023-09-13 17:10:07 +08:00
parent 08ab7704c1
commit d101fd030f
17 changed files with 226 additions and 6 deletions

6
alias.d/app.sh Executable file
View File

@ -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'

9
alias.d/code.sh Normal file
View File

@ -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'

2
alias.d/opt/clearmac.sh Executable file
View File

@ -0,0 +1,2 @@
# shellcheck shell=ksh
find . -name .DS_Store -type f -delete ; find . -type d | xargs dot_clean -m

View File

@ -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

View File

@ -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

6
alias.d/opt/keep_en0.sh Executable file
View File

@ -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"

15
alias.d/opt/mac2str.sh Executable file
View File

@ -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"

17
alias.d/opt/notion_update.sh Executable file
View File

@ -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

23
alias.d/opt/rm_repate.sh Executable file
View File

@ -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

26
alias.d/opt/sync.sh Executable file
View File

@ -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 ""

4
alias.d/opt/test_cron.sh Executable file
View File

@ -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

19
alias.d/osx.sh Executable file
View File

@ -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'

7
alias.d/path.sh Executable file
View File

@ -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'

8
alias.d/proxy.sh Executable file
View File

@ -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' "

23
alias.d/script.sh Executable file
View File

@ -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"
}

5
alias.d/tmux.sh Normal file
View File

@ -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'

View File

@ -10,25 +10,25 @@ _check() {
echo "看起来设备已经安装 alias, $rc_file 中包含 source $alias_init_file" echo "看起来设备已经安装 alias, $rc_file 中包含 source $alias_init_file"
echo -n "请输入y/n:" echo -n "请输入y/n:"
read -r _continue read -r _continue
echo "in >> $_continue"
case "$_continue" in case "$_continue" in
y | Y) # 如果输入 y 或 Y则用 sed 命令删除 source $alias_init_file 这一行 y | Y) # 如果输入 y 或 Y则用 sed 命令删除 source $alias_init_file 这一行
sed -i "/source $alias_init_file/d" $rc_file awk '!/source "$alias_init_file"/' "$rc_file" > tmpfile && mv tmpfile "$rc_file"
echo "覆盖 source $alias_init_file" echo "##### 覆盖 source $alias_init_file ######"
;; ;;
*) *)
echo "退出安装" echo "##### 退出安装 #####"
exit 3 exit 3
;; ;;
esac esac
fi fi
echo "安装 alias.d 正在自动配置环境变量... source $alias_init_file" echo "##### 安装 alias.d 正在自动配置环境变量... #####"
} }
_install() { _install() {
rsync -a --backup --suffix=.bak ./alias.d "$HOME/" rsync -a --backup --suffix=.bak ./alias.d "$HOME/"
echo "install success, enjoy it!" echo "###### install success, enjoy it! #####"
source "$alias_init_file" source "$alias_init_file"
} }