我正在尝试构建我的PowerShell故障排除技巧,我希望在bash中找到类似type
的工具。
type
的使用示例:
17:07 Mac Shell: Git/>$ type -a shell_session_save
shell_session_save is a function
shell_session_save ()
{
if [ -n "$SHELL_SESSION_FILE" ]; then
echo -n 'Saving session...';
( umask 077;
echo 'echo Restored session: "$(date -r '$(date +%s)')"' >|"$SHELL_SESSION_FILE" );
declare -F shell_session_save_user_state > /dev/null && shell_session_save_user_state;
shell_session_history_allowed && shell_session_save_history;
echo 'completed.';
fi
}
17:07 Mac Shell: Git/>$
我只是想在PowerShell的CLI中查看功能代码。这本身可能吗?
感谢您的帮助。
答案 0 :(得分:1)
可以使用Get-Command
本地使用它:
Get-Command MyFunctionName -ShowCommandInfo
这是我保存的一个名为Get-OutputFilePath
的函数的输出:
Name : Get-OutputFilePath
ModuleName :
Module : @{Name=}
CommandType : Function
Definition :
[CmdletBinding()]
Param(
[String]$Filter = "All Files (*.*)|*.*",
[String]$InitialDirectory,
[Parameter(ValueFromPipelineByPropertyName,ValueFromPipeline)]
[Alias('DefaultFileName')]
[String]$FullName,
[Switch]$Force)
BEGIN{
[void][System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")
}
PROCESS{
If($FullName -match "\\.+$" -and !$InitialDirectory){$InitialDirectory = Split-Path $FullName;$FullName = Split-Path $FullName -Leaf}ElseIf(!$InitialDirectory){$InitialDirectory=[Environment]::GetFolderPath('Desktop')}
$SaveFileDialog = New-Object System.Windows.Forms.SaveFileDialog
$SaveFileDialog.initialDirectory = $InitialDirectory
Try{$SaveFileDialog.filter = $Filter}Catch{Throw $_;Break}
$SaveFileDialog.FileName = $FullName
$SaveFileDialog.OverwritePrompt = !$Force
If($SaveFileDialog.ShowDialog() -eq "OK"){$SaveFileDialog.FileName}
}
ParameterSets : {@{Name=__AllParameterSets; IsDefault=False; Parameters=System.Management.Automation.PSObject[]}}