Skip to content
This repository was archived by the owner on Feb 8, 2022. It is now read-only.
This repository was archived by the owner on Feb 8, 2022. It is now read-only.

can't print out like in nushell with | autoview in scripts #579

@fdncred

Description

@fdncred

kind of hard to describe so here's an example. if I source this script, which is part of a large script, and call the function, none of the echo's or string interpolated stings will print out.

This def won't work by itself but shows what I'm talking about.

It would be nice to have a print/printf/echo command that would print out something immediately. However, my requirement is to have a -n option so that you can have it print a newline or not.

Of course, I'd settle for a vec/array/list that I could add to throughout the script to build up an array of items I want to print and then just collect them at the end and print them out.

def repo_status [] {
    let branch = ($gs | get branch) # Cyan
    let ahead = ($gs | get ahead) # Cyan
    let behind = ($gs | get behind)

    let index_changed = (get_index_changes)
    let wt_changed = (get_working_tree_changes)
    let conflicted = (get_conflicted)
    let untracked = (get_untracked)

    if $ahead > 0 {
        echo "ahead > 0"
        $"($AHEAD_ICON)($ahead)" # Cyan
    }

    if $behind > 0 {
        echo "behind > 0"
        $"($BEHIND_ICON)($behind)" # Cyan
    }

    if ($index_changed == 0) && ($wt_changed == 0) && ($conflicted == 0) && ($untracked == 0) {
        echo "all clean"
        $"($NO_CHANGES_ICON)" # Green
    } else {
        if $index_changed > 0 {
            echo "index changed > 0"
            $"($INDEX_CHANGE_ICON)($index_changed)" # Green
        }

        if $conflicted > 0 {
            echo "conflicted > 0"
            $"($CONFLICTED_CHANGES_ICON)($conflicted)" # Red
        }

        if $wt_changed > 0 {
            echo "wt_changed > 0"
            $"($WT_CHANGE_ICON)($wt_changed)"
        }

        if $untracked > 0 {
            echo "untracked > 0"
            $"($UNTRACKED_CHANGES_ICON)($untracked)"
        }
    }
}

I even tried wrapping these print-out parts in variables, which also didn't work. like this.

    let ahead_part = (if $ahead > 0 {
        # echo "ahead > 0"
        $"($AHEAD_ICON)($ahead)" # Cyan
    })

    let behind_part = (if $behind > 0 {
        # echo "behind > 0"
        $"($BEHIND_ICON)($behind)" # Cyan
    })

    let changes_part = (if ($index_changed == 0) && ($wt_changed == 0) && ($conflicted == 0) && ($untracked == 0) {
        # echo "all clean"
        $"N($NO_CHANGES_ICON)" # Green
    } else {
...
    $"($ahead_part)($behind_part)($changes_part)"
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions