Skip to content
The Chat Archive
amazon.nova-pro-v1:0· Amazon LMArena Human Preference 140K

I'm wanting to customise NuShell. I want to remove the information on the right, I don't…

  1. User

    I'm wanting to customise NuShell. I want to remove the information on the right, I don't like that, however I do like having an execution time for how long the previous command took to run over there if that's possible. I also want a transient prompt because I don't like too much information on the line I am working on. Finally I want to have the prompt on two separate lines, with the file path above and then the command I am inputting on the second line.

  2. Assistant

    Customizing NuShell to meet your specific requirements involves modifying its configuration settings and potentially writing custom code. Here's a step-by-step guide to achieve your goals:

    1. Remove Information on the Right

    NuShell's prompt configuration allows you to control what is displayed. You can create a custom prompt that excludes the information you don't want.

    2. Display Execution Time

    You can use NuShell's scripting capabilities to capture and display the execution time of the previous command.

    3. Transient Prompt

    A transient prompt means that the prompt disappears or changes when you start typing a command. This can be achieved using NuShell's prompt configuration.

    4. Two-Line Prompt

    You can format the prompt to display the file path on the first line and the command input on the second line.

    Steps to Customize NuShell

    Step 1: Create a Custom Prompt Script

    Create a NuShell script that will serve as your custom prompt. Save this script in your NuShell configuration directory, typically ~/.config/nu/.

    # custom_prompt.nu
    use std::time;
    
    # Function to get the execution time of the last command
    def get-last-command-time () {
        let start = $env.LAST_COMMAND_START
        if $start != null {
            let end = time::now()
            let duration = $end - $start
            let seconds = $duration.total_seconds()
            if $seconds < 1 {
                "$duration.total_milliseconds() ms"
            } else {
                "$seconds s"
            }
        } else {
            "N/A"
        }
    }
    
    # Set the start time for the current command
    env LAST_COMMAND_START = time::now()
    
    # Get the execution time of the last command
    let last_command_time = get-last-command-time()
    
    # Define the custom prompt
    def custom-prompt () {
        let pwd = pwd
        let prompt = """
        $pwd
        [dim]$last_command_time[/dim] > """
        $prompt
    }
    
    # Set the prompt to the custom prompt
    config set prompt custom-prompt
    

    Step 2: Configure NuShell to Use the Custom Prompt

    Add the custom prompt script to your NuShell configuration file, typically ~/.config/nu/nushell.config.nu.

    # nushell.config.nu
    # Source the custom prompt script
    source ~/.config/nu/custom_prompt.nu
    

    Explanation

    1. Execution Time: The script captures the start time of each command in the LAST_COMMAND_START environment variable. After the command executes, it calculates the duration and displays it in the prompt.
    2. Two-Line Prompt: The custom-prompt function formats the prompt to display the current working directory on the first line and the command input on the second line.
    3. Transient Prompt: NuShell does not natively support a fully transient prompt, but the custom prompt will display the execution time and current directory, which should minimize the information on the command line.

    Final Notes

    • Ensure that the script is sourced correctly in your NuShell configuration.
    • You may need to restart NuShell or source the configuration file manually to apply the changes.

    This setup should give you a customized NuShell experience that meets your requirements.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.