将bash函数转换为fish的函数

use*_*492 10 bash shell fish

有人可以帮我把这个bash函数转换为fish吗?这也将是很好,如果你能解释一下这些不喜欢"${@%%.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 $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”
}
Run Code Online (Sandbox Code Playgroud)

首先十分感谢.

gle*_*man 37

关于差异的一些注意事项:

  • 设置变量
    • 庆典: var=value
    • 鱼: set var value
  • 函数参数
    • 庆典: "$@"
    • 鱼: $argv
  • 函数局部变量
    • 庆典: local var
    • 鱼: set -l var
  • 条件我
    • bash:[[ ... ]][ ... ]
    • 鱼: test ...
  • 条件II
    • 庆典: if cond; then cmds; fi
    • 鱼: if cond; cmds; end
  • 条件III
    • 庆典: cmd1 && cmd2
    • 鱼: cmd1; and cmd2
  • 命令替换
    • 庆典: cmd1 && cmd2
    • 鱼: output=$(pipeline)
  • 过程替代
    • 庆典: set output (pipeline)
    • 鱼: join <(sort file1) <(sort file2)

文档