Created
June 21, 2025 08:07
-
-
Save Fatpandac/ab2d8b0d7b9ca4afeec74b73d7797c19 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| COMMAND_NOTIFY_TABLE=( | |
| "git pull" | |
| "git fetch" | |
| "git push" | |
| "npm install" | |
| "yarn install" | |
| "pnpm install" | |
| "ni" | |
| ) | |
| function resolve_alias() { | |
| local cmd="$1" | |
| local resolved=$(alias "$cmd" 2>/dev/null | sed -E "s/^$cmd='(.*)'/\1/") | |
| echo "${resolved:-$cmd}" | |
| } | |
| function preexec() { | |
| local full_command="$1" | |
| local first_word="${full_command%% *}" | |
| local resolved_command=$(resolve_alias "$first_word") | |
| if [[ "$resolved_command" != "$first_word" ]]; then | |
| LAST_COMMAND="${full_command/#$first_word/$resolved_command}" | |
| else | |
| LAST_COMMAND="$full_command" | |
| fi | |
| } | |
| function escape_command() { | |
| echo "$1" | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' | |
| } | |
| function is_command_in_table() { | |
| local cmd="$1" | |
| for pattern in "${COMMAND_NOTIFY_TABLE[@]}"; do | |
| if [[ "$cmd" == "$pattern"* ]]; then | |
| return 0 | |
| fi | |
| done | |
| return 1 | |
| } | |
| # 命令执行完毕后触发 | |
| function precmd() { | |
| local escaped_cmd=$(escape_command "$LAST_COMMAND") | |
| if is_command_in_table "$LAST_COMMAND"; then | |
| osascript -e "display notification \"$escaped_cmd 运行结束\" with title \"Command\"" | |
| fi | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment