将bash函数转换为fish的函数 [英] Convert bash function to fish's
本文介绍了将bash函数转换为fish的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以帮助我将此bash函数转换为fish吗?如果您能解释一下"${@%%.app}
,'s/ /.*/g’
,"$@\
等的含义,那也很好.
Can someone help me convert this bash function to fish? It would also be nice if you could explain what these do like "${@%%.app}"
, 's/ /.*/g’
, "$@\"
etc.
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
- setting variables
- bash:
var=value
- fish:
set var value
- 重击:
"$@"
- 鱼:
$argv
- bash:
"$@"
- fish:
$argv
- 重击:
local var
- 鱼:
set -l var
- bash:
local var
- fish:
set -l var
- 重击:
[[ ... ]]
和[ ... ]
- 鱼:
test ...
- bash:
[[ ... ]]
and[ ... ]
- fish:
test ...
- 重击:
if cond; then cmds; fi
- 鱼:
if cond; cmds; end
- bash:
if cond; then cmds; fi
- fish:
if cond; cmds; end
- 重击:
cmd1 && cmd2
- 鱼:
cmd1; and cmd2
- 鱼(自鱼3.0起):
cmd1 && cmd2
- bash:
cmd1 && cmd2
- fish:
cmd1; and cmd2
- fish (as of fish 3.0):
cmd1 && cmd2
- 重击:
output=$(pipeline)
- 鱼:
set output (pipeline)
- bash:
output=$(pipeline)
- fish:
set output (pipeline)
- 重击:
join <(sort file1) <(sort file2)
- 鱼:
join (sort file1 | psub) (sort file2 | psub)
- bash:
join <(sort file1) <(sort file2)
- fish:
join (sort file1 | psub) (sort file2 | psub)
文档
- bash: https://www.gnu.org/software/bash/manual/bashref.html
- fish: http://fishshell.com/docs/current/index.html
- bash: https://www.gnu.org/software/bash/manual/bashref.html
- fish: http://fishshell.com/docs/current/index.html
这篇关于将bash函数转换为fish的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- bash:
- 重击:
查看全文