Esempio n. 1
0
            internal static List <CompletionResult> PSv2GenerateMatchSetOfCmdlets(CompletionExecutionHelper helper, string lastWord, string quote, bool completingAtStartOfLine)
            {
                bool flag;
                List <CompletionResult> results = new List <CompletionResult>();

                if (PSv2IsCommandLikeCmdlet(lastWord, out flag))
                {
                    Exception exception;
                    helper.CurrentPowerShell.AddCommand("Get-Command").AddParameter("Name", lastWord + "*").AddCommand("Sort-Object").AddParameter("Property", "Name");
                    Collection <PSObject> collection = helper.ExecuteCurrentPowerShell(out exception, null);
                    if ((collection == null) || (collection.Count <= 0))
                    {
                        return(results);
                    }
                    CommandAndName[] cmdlets = new CommandAndName[collection.Count];
                    for (int i = 0; i < collection.Count; i++)
                    {
                        PSObject psObject = collection[i];
                        string   fullName = CmdletInfo.GetFullName(psObject);
                        cmdlets[i] = new CommandAndName(psObject, PSSnapinQualifiedName.GetInstance(fullName));
                    }
                    if (flag)
                    {
                        foreach (CommandAndName name in cmdlets)
                        {
                            AddCommandResult(name, true, completingAtStartOfLine, quote, results);
                        }
                        return(results);
                    }
                    PrependSnapInNameForSameCmdletNames(cmdlets, completingAtStartOfLine, quote, results);
                }
                return(results);
            }
Esempio n. 2
0
        private static List <CompletionResult> InvokeLegacyTabExpansion(PowerShell powershell, string input, int cursorIndex, bool remoteToWin7, out int replacementIndex, out int replacementLength)
        {
            List <CompletionResult> list = null;
            char      ch;
            Exception exception;
            string    sentence = (cursorIndex != input.Length) ? input.Substring(0, cursorIndex) : input;
            string    str2     = LastWordFinder.FindLastWord(sentence, out replacementIndex, out ch);

            replacementLength = sentence.Length - replacementIndex;
            CompletionExecutionHelper helper = new CompletionExecutionHelper(powershell);

            powershell.AddCommand("TabExpansion").AddArgument(sentence).AddArgument(str2);
            Collection <PSObject> collection = helper.ExecuteCurrentPowerShell(out exception, null);

            if (collection != null)
            {
                list = new List <CompletionResult>();
                foreach (PSObject obj2 in collection)
                {
                    CompletionResult item = PSObject.Base(obj2) as CompletionResult;
                    if (item == null)
                    {
                        string completionText = obj2.ToString();
                        if (((ch != '\0') && (completionText.Length > 2)) && (completionText[0] != ch))
                        {
                            completionText = ch + completionText + ch;
                        }
                        item = new CompletionResult(completionText);
                    }
                    list.Add(item);
                }
            }
            if (remoteToWin7 && ((list == null) || (list.Count == 0)))
            {
                string quote = (ch == '\0') ? string.Empty : ch.ToString();
                list = PSv2CompletionCompleter.PSv2GenerateMatchSetOfFiles(helper, str2, replacementIndex == 0, quote);
                List <CompletionResult> list2 = PSv2CompletionCompleter.PSv2GenerateMatchSetOfCmdlets(helper, str2, quote, replacementIndex == 0);
                if ((list2 != null) && (list2.Count > 0))
                {
                    list.AddRange(list2);
                }
            }
            return(list);
        }
Esempio n. 3
0
            private static List <PathItemAndConvertedPath> PSv2FindMatches(CompletionExecutionHelper helper, string path, bool shouldFullyQualifyPaths)
            {
                Exception exception;
                List <PathItemAndConvertedPath> list = new List <PathItemAndConvertedPath>();
                PowerShell currentPowerShell         = helper.CurrentPowerShell;

                if (!shouldFullyQualifyPaths)
                {
                    currentPowerShell.AddScript(string.Format(CultureInfo.InvariantCulture, "& {{ trap {{ continue }} ; resolve-path {0} -Relative -WarningAction SilentlyContinue | %{{,($_,(get-item $_ -WarningAction SilentlyContinue),(convert-path $_ -WarningAction SilentlyContinue))}} }}", new object[] { path }));
                }
                else
                {
                    currentPowerShell.AddScript(string.Format(CultureInfo.InvariantCulture, "& {{ trap {{ continue }} ; resolve-path {0} -WarningAction SilentlyContinue | %{{,($_,(get-item $_ -WarningAction SilentlyContinue),(convert-path $_ -WarningAction SilentlyContinue))}} }}", new object[] { path }));
                }
                Collection <PSObject> collection = helper.ExecuteCurrentPowerShell(out exception, null);

                if ((collection == null) || (collection.Count == 0))
                {
                    return(null);
                }
                foreach (PSObject obj2 in collection)
                {
                    IList baseObject = obj2.BaseObject as IList;
                    if ((baseObject != null) && (baseObject.Count == 3))
                    {
                        object   obj3 = baseObject[0];
                        PSObject item = baseObject[1] as PSObject;
                        object   obj5 = baseObject[1];
                        if (((obj3 != null) && (item != null)) && (obj5 != null))
                        {
                            list.Add(new PathItemAndConvertedPath(CompletionExecutionHelper.SafeToString(obj3), item, CompletionExecutionHelper.SafeToString(obj5)));
                        }
                    }
                }
                if (list.Count == 0)
                {
                    return(null);
                }
                list.Sort((Comparison <PathItemAndConvertedPath>)((x, y) => string.Compare(x.Path, y.Path, CultureInfo.CurrentCulture, CompareOptions.IgnoreCase)));
                return(list);
            }