ZSH Alias触发终端通知程序,但不触发产生它的命令

时间:2019-07-05 14:00:44

标签: function gulp sh zsh zshrc

好吧,所以几天前我问了这个问题,但是把它弄糊涂了,所以我删除了它,打算再次寻求帮助...

我的.zshrc中有一个别名;

alias gulp='gulp-notice'

这又会触发功能;

gulp-notice ()
{
  notifier-around gulp "Gulp" "gulp $*"
}

依次触发此功能

notifier-around ()
{
  GROUP_ID=$1
  TITLE=$2
  COMMAND=$3 $4 $5 $6 $7 $8 $9
  terminal-notifier -title $COMMAND -message 'Finished' -appIcon https://s-media-cache-ak0.pinimg.com/564x/b5/5a/18/b55a1805f5650495a74202279036ecd2.jpg && terminal-notifier -title $COMMAND -message 'Complete' -appIcon https://s-media-cache-ak0.pinimg.com/564x/b5/5a/18/b55a1805f5650495a74202279036ecd2.jpg || terminal-notifier -title $COMMAND -message 'Failed' -appIcon https://media3.giphy.com/media/10ECejNtM1GyRy/200_s.gif
}

因此变量的计算结果如下(使用gulp-notice函数)

GROUP_ID is gulp
TITLE is "Gulp" (without the quote marks)
COMMAND is "gulp $*" (the output without the quote marks)

现在我的问题是...当我以前在BASH中运行此脚本时,它将执行gulp命令,而终端通知程序将执行此操作(告诉我gulp失败还是成功)

gulp

根据情况将解雇gulp和必要的通知

gulp sass

根据情况将解雇gulp sass和必要的通知

现在我已移至ZSH,该脚本仅会触发终端通知,仅此而已。有人可以指出正确的方向,因为我不明白为什么两个终端应用程序之间的脚本应该如此不同

更新 我现在有工作代码,但是无法运行gulp任务,例如SASS或JS(gulp sassgulp js)。我修改后的代码如下

notifier-around ()
{
  GROUP_ID=$1
  TITLE=$2
  COMMAND="$3 $4 $5 $6 $7 $8 $9"
  COMMAND_NO_WHITE_SPACE="$(echo -e "${COMMAND}" | sed -e 's/[[:space:]]*$//')" //strips the white space from the end of the VAR
  PROGRESS="https://s-media-cache-ak0.pinimg.com/564x/b5/5a/18/b55a1805f5650495a74202279036ecd2.jpg"
  FAIL="https://media3.giphy.com/media/10ECejNtM1GyRy/200_s.gif"
  terminal-notifier -group "$GROUP_ID" -title "$TITLE" -message "Starting" -appIcon "$PROGRESS" && $COMMAND_NO_WHITE_SPACE && terminal-notifier -group "$GROUP_ID" -title "$TITLE" -message "Complete" -appIcon "$PROGRESS" || terminal-notifier -group "$GROUP_ID" -title "$TITLE" -message "Failure" -appIcon "$FAIL"
}

gulp-notice ()
{
  notifier-around gulp "Gulp Build" "gulp $*"
}

alias gulp='gulp-notice'

关于如何使其识别其他任务的任何想法,因为我也无法运行gulp --tasks ...

1 个答案:

答案 0 :(得分:0)

所以我终于将其修复;

notifier-around ()
{
  GROUP_ID="$1"
  TITLE="$2"
  COMMAND="$3"
  COMMAND_NO_WHITE_SPACE="$(echo -e "${COMMAND}" | sed -e 's/[[:space:]]*$//')" //strips the white space from the end of the VAR
  PROGRESS="https://s-media-cache-ak0.pinimg.com/564x/b5/5a/18/b55a1805f5650495a74202279036ecd2.jpg"
  FAIL="https://media3.giphy.com/media/10ECejNtM1GyRy/200_s.gif"
  terminal-notifier -group "$GROUP_ID" -title "$TITLE" -message "Starting" -appIcon "$PROGRESS" && "${=COMMAND_NO_WHITE_SPACE}" && terminal-notifier -group "$GROUP_ID" -title "$TITLE" -message "Complete" -appIcon "$PROGRESS" || terminal-notifier -group "$GROUP_ID" -title "$TITLE" -message "Failure" -appIcon "$FAIL"
}

gulp-notice ()
{
  notifier-around gulp "Gulp Build" "gulp $*"
}

alias gulp='gulp-notice'

您会看到我正在用来去除尾随空格; COMMAND_NO_WHITE_SPACE="$(echo -e "${COMMAND}" | sed -e 's/[[:space:]]*$//')"似乎引起了问题

您还将看到我将"$COMMAND_NO_WHITE_SPACE"更改为"${=COMMAND_NO_WHITE_SPACE}" ${=是用$ IFS拆分变量。这给ZSH带来了它需要识别的屁股,我正在尝试向命令中添加参数