将 bash 函数转换为鱼函数

Convert bash function to fish's

谁能帮我把这个 bash 函数转换成鱼?如果你能解释一下它们的作用就好了"${@%%.app}”'s/ /.*/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 [=11=]}'|head -n1)
    fi
    # No results? Die.
    [[ -z $location || $location = "" ]] && echo " 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
    • 鱼:set var value
  • 函数
    • bash
      funcName() {
          ...
      }
      
    • function funcName
          ...
      end
      
  • 函数参数
    • bash: "$@", "", "", ...
    • 鱼:$argv$argv[1]$argv[2]、...
  • 函数局部变量
    • bash: local var
    • 鱼:set -l var
  • 条件句我
    • bash: [[ ... ]]test ...[ ... ]
    • 鱼:test ...[ ... ],没有[[ ... ]]
  • 条件二
    • bash: if cond; then cmds; fi
    • 鱼:if cond; cmds; end
  • 条件三
    • bash: cmd1 && cmd2
    • 鱼:cmd1; and cmd2
    • 鱼(从鱼 3.0 开始):cmd1 && cmd2
  • 命令替换
    • bash: output=$(pipeline)
    • 鱼:set output (pipeline)
  • 进程替换
    • bash: join <(sort file1) <(sort file2)
    • 鱼:join (sort file1 | psub) (sort file2 | psub)

文档