Created
May 8, 2025 02:48
-
-
Save stormslowly/203cab8b621c249cdeb9e4724e4455af to your computer and use it in GitHub Desktop.
r cmd
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
| function fn_r { | |
| # $# 命令参数个数, $* 参数列表 | |
| if [ $# -eq 0 ]; then | |
| SCRIPT=$(jq -r '.scripts | keys[]' package.json | \ | |
| fzf --preview-window=down:10%:wrap \ | |
| --no-mouse \ | |
| --preview 'jq -r --arg script {} ".scripts[\$script]" package.json') | |
| if [ -n "$SCRIPT" ]; then | |
| history -s "r $SCRIPT" | |
| if command -v atuin >/dev/null 2>&1; then | |
| local id=`atuin history start "r $SCRIPT"` | |
| npm run $SCRIPT | |
| local EXIT_CODE=$? | |
| atuin history end --exit $EXIT_CODE $id | |
| return $EXIT_CODE | |
| fi | |
| npm run $SCRIPT | |
| fi | |
| else | |
| npm run $* | |
| fi | |
| } | |
| alias r="fn_r" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment