Git Product home page Git Product logo

Comments (8)

i-am-shodan avatar i-am-shodan commented on September 26, 2024 1

Latest release will fix the issue

from shell.

i-am-shodan avatar i-am-shodan commented on September 26, 2024

Done a quick test and replacing the existing prompt handler with this seems to work fine.

Shell.Prompt = () =>
    var prompt = `starship prompt --status=$Shell.LastExitCode$ --jobs=$Shell.BackgroundProcesses.Count()$`;
    return ColorString.FromRawANSI(prompt);
};

from shell.

MostHated avatar MostHated commented on September 26, 2024

I appreciate you taking the time to look into this. I tried swapping out the default for your example, but for some reason, I keep getting the following:

zsh > dotnet-shell
An error occured loading core.nsh
StartIndex cannot be less than zero. (Parameter 'startIndex')
# >

I tried to add a few slight checks, but I still end up getting the same result:

core.nsh snippet
// bool? powerline = null;
#region c#
Shell.Prompt = () =>
{
    var exitCode = `Shell.LastExitCode`;
    if (exitCode == null || exitCode < 0)
    {
        exitCode = 0;
    }

    var bgJobs = `Shell.BackgroundProcesses.Count()`;
    if (bgJobs == null || bgJobs < 0)
    {
        bgJobs = 0;
    }

    var prompt = `starship prompt --status=$exitCode$ --jobs=$bgJobs$`;
    return ColorString.FromRawANSI(prompt);
};

// Shell.Prompt = () =>
#endregion
// {
//       if (powerline == null && !RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
//       {
//           var powerlineHelpOut=`which powerline`;
//           powerline = !string.IsNullOrWhiteSpace(powerlineHelpOut);
//       }

//       if (powerline == true)
//       {
//           string powerLinePrompt=`powerline-render shell left --last-exit-code=$Shell.LastExitCode$`;
//           return new ColorString("!", Color.Green, Color.LightBlue) + ColorString.FromRawANSI( powerLinePrompt );
//       }
//       else
//       {
//           return new ColorString("!" + Environment.UserName + "@" + Environment.MachineName, Color.Green) + new ColorString(" " + Shell.WorkingDirectory + ">", Color.Blue) + " ";
//       }
// };

I just edited core.nsh directly. It seemed like that would be the proper way to go about it, am I mistaken on that?

Thanks,
-MH

from shell.

i-am-shodan avatar i-am-shodan commented on September 26, 2024

There are problems:
var exitCode = `Shell.LastExitCode`; should actually be var exitCode = Shell.LastExitCode;
Putting text in backticks means execute this shell command, take the stdout and put in a variable. But Shell.LastExitCode is already a piece of C# -- see LastExitCode. That means we can just assign it.

Same for the bgJobs variable assigned as well - drop those backticks.

bgJobs and exitCode will also never be null or < 0 so you can drop that check as well.

When executing the starship prompt helper you are correctly using $VARIABLE$ notation so that dotnet-shell knows to replace that text with a variable held in C#.

Make those changes and your code should work.

My guess is that you getting that error as some bash error message is being evaluated when starship is run. Personally I would stick with my code, it works and its a bit more concise.

from shell.

MostHated avatar MostHated commented on September 26, 2024

Ah yes, that definitely makes sense. Unfortunately, though, the original code you had shared is what was giving the An error occured loading core.nsh. StartIndex cannot be less than zero. (Parameter 'startIndex') message. That was the reason I tried to check to make sure one of the values weren't coming back as less than 0. The error message didn't change, though between the original code you shared and the modification I had tried.

from shell.

i-am-shodan avatar i-am-shodan commented on September 26, 2024

This is my core.nsh that i've just tested on Ubuntu and works. Could I ask that you give this a go. If there is still a bug there is a much more exciting issue.

from shell.

i-am-shodan avatar i-am-shodan commented on September 26, 2024

I have reproduced the issue. The dotnet-shell preprocess isn't taking out all the comments correctly. Removing the large comment blog (as in my paste) will fix your issue.

from shell.

MostHated avatar MostHated commented on September 26, 2024

I was just in process of typing that out, you beat me to it. 👍

from shell.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.