有人可以帮我把这个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”
}
首先十分感谢。
关于差异的一些注意事项:
var=value
鱼:set var value
"$@"
鱼:$argv
local var
鱼:set -l var
[[ ... ]]
和[ ... ]
鱼:test ...
if cond; then cmds; fi
鱼:if cond; cmds; end
cmd1 && cmd2
鱼:cmd1; and cmd2
鱼(鱼类3.0):cmd1 && cmd2
output=$(pipeline)
鱼:set output (pipeline)
join <(sort file1) <(sort file2)
鱼:join (sort file1 | psub) (sort file2 | psub)
文档