Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save stormslowly/203cab8b621c249cdeb9e4724e4455af to your computer and use it in GitHub Desktop.

Select an option

Save stormslowly/203cab8b621c249cdeb9e4724e4455af to your computer and use it in GitHub Desktop.
r cmd
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