将bash函数转换为fish';s

将bash函数转换为fish';s,bash,shell,fish,Bash,Shell,Fish,有人能帮我把这个bash函数转换成fish吗?如果你能解释一下它们是什么样的,“${@%%.app}”,的/.*/g',“$@\”等等,那就太好了 bid() { local shortname location # combine all args as regex # (and remove ".app" from the end if it exists due to autocomplete) shortname=$(echo "${@%%.app}"|

有人能帮我把这个bash函数转换成fish吗?如果你能解释一下它们是什么样的,
“${@%%.app}”
的/.*/g'
“$@\”
等等,那就太好了

bid() {
    local shortname location

    # combine all args as regex
    # (and remove ".app" from the end if it exists due to autocomplete)
    shortname=$(echo "${@%%.app}"|sed 's/ /.*/g')
    # if the file is a full match in apps folder, roll with it
    if [ -d "/Applications/$shortname.app" ]; then
        location="/Applications/$shortname.app"
    else # otherwise, start searching
        location=$(mdfind -onlyin /Applications -onlyin ~/Applications -onlyin /Developer/Applications 'kMDItemKind==Application'|awk -F '/' -v re="$shortname" 'tolower($NF) ~ re {print $0}'|head -n1)
    fi
    # No results? Die.
    [[ -z $location || $location = "" ]] && echo "$1 not found, I quit" && return
    # Otherwise, find the bundleid using spotlight metadata
    bundleid=$(mdls -name kMDItemCFBundleIdentifier -r "$location")
    # return the result or an error message
    [[ -z $bundleid || $bundleid = "" ]] && echo "Error getting bundle ID for \"$@\"" || echo "$location: $bundleid”
}

非常感谢。

关于差异的一些注释:

  • 设置变量
    • bash:
      var=value
    • 鱼:
      设置变量值
  • 函数参数
    • bash:
      “$@”
    • 鱼:
      $argv
  • 函数局部变量
    • bash:
      localvar
    • 鱼:
      set-l变量
  • 条件句I
    • bash:
      […]
      […]
    • 鱼:
      测试…
  • 条件句II
    • bash:
      if cond;然后是cmds;fi
    • 鱼:
      如果条件;cmds;结束
  • 条件三
    • bash:
      cmd1和&cmd2
    • 鱼:
      cmd1;和cmd2
    • fish(从fish 3.0开始):
      cmd1和&cmd2
  • 命令替换
    • bash:
      output=$(管道)
    • 鱼:
      设置输出(管道)
  • 过程替代

    • bash:
      join您是如何尝试自己解决这个问题的?我仍然无法找到与
      ${@%%.app}
      相当的fish。我相信我知道它的作用,即返回
      $@
      中结尾包含.app的所有字符串。因此,我认为fish中应该是
      $argv[**.app]
      ,但它给出了无法展开的错误。
      ${@%%.app}
      返回所有位置参数的列表,其中删除了任何“.app”扩展名。对于arg,fish等价物为
      ,单位为$argv;设置args$args(回显“$arg”| sed's/.app$/');结束
      我想你可能在上面的评论中用$在
      sed的/.app$/'
      中打错了。否则,请您解释为什么它会出现。对于argv数组的每个元素,我们将删除文件名末尾的“.app”扩展名。
      $
      是正则表达式的“字符串结束”锚点。事实上,我应该让sed的/\.app$/'
      转义这个点。谢谢,没有转义这个点,它不会给出预期的结果。