在 Powershell 2.0 中管理配置文件
据我了解,powershell 每个用户都有一个配置文件。我想为我可以戴在头上的不同“帽子”准备多个环境。就像启动我的“数据库工作外壳”一样,它提供了一组用于处理特殊数据库的快捷方式。稍后我将启动一个可能是我的“数据处理外壳”的环境,它提供其他快捷方式。
管理这个问题的最佳方法是什么?
干杯, 阿希姆
as far as I understand, powershell has one profile per user. I would like to prepare multiple environments for different "hats" I could put on my head. Like start my "database worker shell" which provides a set of shortcuts for working with special databases. Later I would start an environment which might be my "data processing shell" that provides other shortcuts.
What's the best way to manage that?
cheers,
Achim
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信有很多方法,“最好的方法”取决于许多未解释的因素。以下是一种不是最好但比较直接的方法。
配置文件只是启动时在全局范围内自动点源的脚本。从某种意义上说,我们可以稍后将全局范围内的任何点源脚本称为“动态配置文件”。我们可以有几个脚本来安装全局变量、函数、别名等,它们的名称相同,但值不同。换句话说,我们可以有多个安装不同“环境”的脚本。我们随时采取行动:
并继续在新环境
SomeName
中工作。或多或少,我在实践中使用了这样的方法(顺便说一句,正是在使用数据库时)。I believe there are quite a number of ways and “the best one” depends on many not explained factors. One not best but kind of straightforward way is the following.
Profiles are just scripts automatically dot-sourced in the global scope on start-up. In some sense we can call any script that is dot-sourced in the global scope later “a dynamic profile”. We can have several scripts that install global variables, functions, aliases and etc. with the same names but different values. In other words, we can have several scripts that install different “environments”. At any moment we take one and do:
and continue work with new environment
SomeName
. More or less, I use the approach like this in practice (exactly when working with databases, BTW).