我正在尝试编写一个bash完成,它将让我完成其他shell所在的目录名称.
例如,假设我有另一个外壳打开/very/long/path/name,目前在包含子目录的目录,我foo和bar.当我输入时cd <Tab>,我想看到:
$ cd <Tab>
foo/ bar/ /very/long/path/name
Run Code Online (Sandbox Code Playgroud)
我有这个命令来生成潜在的完成列表:
ps -Cbash -opid= | xargs pwdx | cut -d" " -f2 | sort -u | while read; do echo ${REPLY#$PWD/}; done | grep -v "^$"
Run Code Online (Sandbox Code Playgroud)
为简洁起见,我将其写为...pipeline....
在我的系统上有一个_cd产生常规完成的函数:
$ complete -p cd
complete -o nospace -F _cd cd
Run Code Online (Sandbox Code Playgroud)
我想重用这个_cd函数,因为它是非常重要的(约30行代码,根据type _cd).如果解决方案重用已经定义的任何完成,则奖励点,无论它是否基于被调用的函数_cd.
我认为-C选择complete听起来很有希望,但我无法让它发挥作用:
$ complete -C '...pipeline...' cd
$ cd <Tab>grep: …Run Code Online (Sandbox Code Playgroud) 我将尽力解释这个问题.
我正在使用Parse.com并从Parse数据库类返回数据.我想把这个parse.com调用放在自定义类中的自己的函数中.我遇到的问题是完成.它去哪儿了?我已经尝试了很多不同版本的添加到我的功能,但它无法正常工作.
以下是获取类名,表名和排序描述符并返回数组的函数:
func queryDataInBackgroundWithBlock(parseClass:String, parseObject:String, sortDescriptor:NSSortDescriptor) -> [Any]
Run Code Online (Sandbox Code Playgroud)
当我添加完成时,我使用(可能不正确):
func queryDataInBackgroundWithBlock(parseClass:String, parseObject:String, sortDescriptor:NSSortDescriptor, completion: (result: Any)->Void)
Run Code Online (Sandbox Code Playgroud)
现在在函数内部,我使用Parse.com代码来获取数据
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]!, error: NSError!) -> Void in
if error == nil {
// Do something with the found objects
for object in objects {
self.arrayOfObjects.append(object[parseObject]!)
}
} else {
// Log details of the failure
println("Error: \(error) \(error.userInfo!)")
}
}
Run Code Online (Sandbox Code Playgroud)
我的目标是将参数发送到我的类函数,从parse.com获取数据,然后在异步调用之后将数据作为数组返回
我想这样称呼它:
myClass.queryDataInBackgroundWithBlock("databaseName", parseObject: "columnName", sortDescriptor: orderBy){
(result: Any) in
println(result)
}
Run Code Online (Sandbox Code Playgroud)
这几乎就像是嵌套完成.完成后如何返回数组?是交给函数然后返回它,还是需要在嵌套代码中返回,或者是什么?它检索数据,但问题是完成后返回.
更新:正如我在下面的评论中所述:
query.findObjectsInBackgroundWithBlock({
(objects: [AnyObject]!, error: NSError!) …Run Code Online (Sandbox Code Playgroud) 为什么从未调用完成?
我非常抱歉这是一个代码转储...因为我不知道为什么每个部分都有效,除了调用完成.
除了完成之外,没有调用完成的SKAction运行.就是这个:
curtain.run(fadeMoveWipeAndReveal, completion: {onDone(), print("I'm done!!!!")})
Run Code Online (Sandbox Code Playgroud)
在以下课程中:
import SpriteKit
class WipeCurtain: SKSpriteNode {
var wipeCurtainBase: SKSpriteNode?
var returnable = SKNode()
var moveRight = SKAction()
var node = SKNode()
init( color: SKColor,
size: CGSize,
time: TimeInterval,
reveal: @escaping () -> (),
onDone: @escaping () -> ())
{
super.init(texture: nil, color: color, size: size)
wipeCurtainBase = SKSpriteNode(color: color, size: size)
let show = SKAction.run(reveal)
let fadeIn = createFadeIn(duration: time)
let moveRight = createMoveRight(duration: time)
let wipeRight = createWipeRight(duration: time)
let …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Swift编写的Parse.我能够毫无困难地登录,但我正在努力告诉我的应用程序用户已登录.
我正在使用logInWithUsernameInBackground,如果登录成功,我只想返回一个布尔值.
我用的时候:
func authenticateUser() -> Bool{
PFUser.logInWithUsernameInBackground(userName.text, password: passwordField.text, block: {
(user,error) in
return error === nil
})
}
Run Code Online (Sandbox Code Playgroud)
我得到错误"Bool不能转换为Void"这是有道理的.
所以,如果我将第3行更改为:
(user,error) -> Bool in
Run Code Online (Sandbox Code Playgroud)
我最终得到错误"在调用中缺少参数选择器的参数"
但是,此方法不需要选择器参数.
那我哪里错了?如何根据登录时是否有错误返回bool?
我正在寻找一种简单的方法来将Bash完成函数从程序"继承"到脚本中.
假设有一个程序foo提供自己的Bash完成,这样就$ foo sub<TAB>完成了$ foo subcommand.现在我想写一个脚本foo-extra,它接受相同的参数foo,在调用之前做一些额外的事情foo <arguments>.使foo-extra脚本foo完成函数的最简单方法是什么?
在 emacs 中,当我输入文件名的开头,然后按Tab进行自动完成时,这就是我得到的:
可能的完成有:
dummy.cmi dummy.cmx
dummy.ml dummy.o
我想让 emacs 忽略目标文件(.o、.cmx、.cmi)并直接用dummy.ml完成
有没有办法在 emacs 中指定该行为?某种类似于git 的.emacsignore 机制?
很抱歉,如果我的谷歌功能太弱,但是:我只是想调整zsh以便我可以完成选项卡
someappname -s
Run Code Online (Sandbox Code Playgroud)
使用〜/ somedir的内容(文件名)
例如:
someapp -s f<tab>
Run Code Online (Sandbox Code Playgroud)
应该根据以〜/ somedir中的字母f开头的文件循环完成完成.所以我最终可能会得到一个命令行:"someapp -s foobar".
我正在阅读鱼壳的git.fish完成脚本(/usr/local/Cellar/fish/2.1.2/share/fish/completions),我在理解语法的含义时遇到了一些问题.
在街区,
function __fish_git_needs_command
set cmd (commandline -opc)
if [ (count $cmd) -eq 1 -a $cmd[1] = 'git' ]
return 0
end
return 1
end
Run Code Online (Sandbox Code Playgroud)
我明白这cmd是设置为commandline -opc.但在下一个声明中(count $cmd) -eq 1 -a $cmd[1] = 'git',做什么-eq和-a意味着什么?
我是fish shell的新手,我试图通过尝试为程序编写自己的完成脚本来理解语法.非常感谢帮助.
谢谢.
在我的 Windows 机器上的 MSYS2 上,我必须切换到 MSYS2 bash,因为tcsh它不稳定,并且在摆弄完成脚本、.bashrc 和 .inputrc 一个小时后,我几乎必须bash按照我习惯的方式行事。然而,还缺少一块。
在 中tcsh,我可以通过按 TAB 键(即空白命令)列出当前目录。我确信有一种方法可以bash使用该complete -E选项来执行此操作,但我找不到任何示例。
任何帮助表示赞赏!
问候
我目前正在从 csh 切换到 zsh,我正在编写一个 .zshrc 试图获取我在这个新 shell 中习惯的所有选项。
我使用 autocd (进入一个目录,只需输入其名称(无需 cd 命令),我想知道我的第一个是否可能建议当前目录中存在的所有文件(就像它在 csh 中工作一样)。
我非常习惯这种方式,在输入我的命令之前,先按一下我可以打开的文件或我可以“autocd”进入的目录的概述,而无需在命令行中编写任何内容。
现在,当我第一次按下它时,它不会触发任何完成机制,但它只是写入一个实际的表格。
我还没有找到任何解决方案,如果有人有任何神奇的选择来获得这个结果,请随时启发我!
谢谢
au FileType php call PHPFuncList()
function PHPFuncList()
set dictionary-=/etc/vim/php_funclist.txt dictionary+=/etc/vim/php_funclist.txt
set complete-=k complete+=k
endfunction
Run Code Online (Sandbox Code Playgroud)
对于上面的 PHPFunctionList,函数体中的两行让我很困惑。
set dictionary-=/etc/vim/php_funclist.txt dictionary+=/etc/vim/php_funclist.txt
set complete-=k complete+=k
Run Code Online (Sandbox Code Playgroud)
对于这两行,首先-=将其删除,然后+=再次添加。
为什么不能只+=在其中写两行?
set dictionary+=/etc/vim/php_funclist.txt
set complete+=k
Run Code Online (Sandbox Code Playgroud)
它们之间有什么区别吗?
:h set-=指出,当该选项是标志列表时,{value}必须完全在选项中显示。一一移除标志以避免出现问题。
避免哪个问题?