更新所有全局激活的包
Update all global activated packages
我想出了这个命令
pub global list -v 2>/dev/null | awk '{split([=10=], a," "); printf \
"pub global activate "; if(a[8]=="") printf a[3]; else printf \
"-sgit " a[8]; print "" }' | xargs -0 bash -c
更新我所有的全局激活包。
pub global list -v
输出
FINE: Pub 1.9.0-edge.43835
MSG : dart_style 0.1.3
MSG : den 0.1.5
MSG : linter 0.0.1 from Git repository "git@github.com:dart-lang/linter.git"
MSG : polymer 0.15.5+1
MSG : stagehand 0.1.5+4
MSG : test_runner 0.2.16
以上命令从输出中生成这些命令
pub global activate dart_style
...
pub global activate -sgit "git@github.com:dart-lang/linter.git"
...
这很复杂。
有没有更简单的方法?
嗯,您不需要在 awk
中应用 split
。
另一个改进,摆脱 if
条件并使用 ternary
运算符(如 Etan 在评论中解释):
awk '{var===""?:"-sgit ";print "pub global activate "var }'
最后的内容应该接近于:
pub global list -v 2>/dev/null |\
awk '{var= ==""? : "-sgit "
print "pub global activate "var }'| bash -s
或者,可以在 awk
代码中完成 system
调用:
pub global list -v 2>/dev/null |\
awk '{var==="" ? : "-sgit "
cmd="pub global activate "var
system(cmd)
close(cmd)}'
因为我不会说 bash 也不会流利地使用 awk 并且对这样的功能很感兴趣,所以我最终编写了这个工具......在 dart 中(是的我知道它并没有真正回答问题但是是我在搜索此类功能时登陆的地方)
$ pub global activate pubglobalupdate
然后可以使用以下方式更新所有当前的全局激活包:
$ pubglobalupdate
适用于 linux、mac 和 windows! (https://github.com/tekartik/pubglobalupdate.dart)
我想出了这个命令
pub global list -v 2>/dev/null | awk '{split([=10=], a," "); printf \
"pub global activate "; if(a[8]=="") printf a[3]; else printf \
"-sgit " a[8]; print "" }' | xargs -0 bash -c
更新我所有的全局激活包。
pub global list -v
输出
FINE: Pub 1.9.0-edge.43835
MSG : dart_style 0.1.3
MSG : den 0.1.5
MSG : linter 0.0.1 from Git repository "git@github.com:dart-lang/linter.git"
MSG : polymer 0.15.5+1
MSG : stagehand 0.1.5+4
MSG : test_runner 0.2.16
以上命令从输出中生成这些命令
pub global activate dart_style
...
pub global activate -sgit "git@github.com:dart-lang/linter.git"
...
这很复杂。 有没有更简单的方法?
嗯,您不需要在 awk
中应用 split
。
另一个改进,摆脱 if
条件并使用 ternary
运算符(如 Etan 在评论中解释):
awk '{var===""?:"-sgit ";print "pub global activate "var }'
最后的内容应该接近于:
pub global list -v 2>/dev/null |\
awk '{var= ==""? : "-sgit "
print "pub global activate "var }'| bash -s
或者,可以在 awk
代码中完成 system
调用:
pub global list -v 2>/dev/null |\
awk '{var==="" ? : "-sgit "
cmd="pub global activate "var
system(cmd)
close(cmd)}'
因为我不会说 bash 也不会流利地使用 awk 并且对这样的功能很感兴趣,所以我最终编写了这个工具......在 dart 中(是的我知道它并没有真正回答问题但是是我在搜索此类功能时登陆的地方)
$ pub global activate pubglobalupdate
然后可以使用以下方式更新所有当前的全局激活包:
$ pubglobalupdate
适用于 linux、mac 和 windows! (https://github.com/tekartik/pubglobalupdate.dart)