Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script works well on macOS does not work on Windows due to the lines break by "|" #4059

Closed
hustcer opened this issue Oct 1, 2021 · 7 comments · Fixed by #4740
Closed

Script works well on macOS does not work on Windows due to the lines break by "|" #4059

hustcer opened this issue Oct 1, 2021 · 7 comments · Fixed by #4740
Labels
🐛 bug Something isn't working engine-q related to the upcoming engine update
Milestone

Comments

@hustcer
Copy link
Contributor

hustcer commented Oct 1, 2021

Describe the bug

Hi,
The following script works well on my macOS, but not work on windows:

# Creates a table listing the branches of a git repository and the day of the last commit
def 'git age' [
  repo: path # The repo path to show git age
] {

  cd $repo;
  git branch |
    lines |
    str substring 2, |
    wrap name |
    insert last_commit {
      get name |
      each {
        git show $it --no-patch --format=%ai | str to-datetime
      }
    } |
    sort-by last_commit
}

git age path-to-git-repo;

The output on windows:

> nu .\git\age.nu
  develop
* master
  #        name
──────────────────────
  0   [table 0 rows]


error: no values to work with
   ┌─ shell:22:5
   │
22 │     sort-by last_commit
   │     ^^^^^^^ no values to work with

It seems to be caused by the splitting of lines by "|", after change it to:

# Creates a table listing the branches of a git repository and the day of the last commit
def 'git age' [
  repo: path # The repo path to show git age
] {

  cd $repo;
  git branch | lines | str substring 2, | wrap name | insert last_commit {
      get name | each {
        git show $it --no-patch --format=%ai | str to-datetime
      }
    } | sort-by last_commit
}

git age path-to-git-repo;

will make it work on windows.

How to reproduce

Described as the above.

Expected behavior

The script should work both on macOS and windows, with "|" at the end of line be supported for a better readability

Screenshots

No response

Configuration

key value
version 0.37.0
short_commit f9ae882
commit_hash f9ae882
commit_date 2021-09-14 19:45:30 +00:00
build_os windows-x86_64
rust_version rustc 1.55.0 (c8dfcfe04 2021-09-06)
rust_channel stable-x86_64-pc-windows-msvc (default)
cargo_version cargo 1.55.0 (32da73ab1 2021-08-23)
pkg_version 0.37.0
build_time 2021-09-14 20:08:37 +00:00
build_rust_channel release
features clipboard-cli, ctrlc, dataframe, default, rustyline, term, trash, uuid, which, zip
installed_plugins binaryview, chart bar, chart line, fetch, from bson, from sqlite, inc, match, post, ps, query json, s3, selector, start, sys, textview, to bson, to sqlite, tree, xpath

Additional context

Thanks

@fdncred fdncred added the 🐛 bug Something isn't working label Oct 1, 2021
@sophiajt sophiajt added the engine-q related to the upcoming engine update label Oct 12, 2021
@hustcer
Copy link
Contributor Author

hustcer commented Mar 3, 2022

Still has this issue on nu v0.59.0, we have to change the pipelines in one line to make it work:

def 'git age' [
  repo: path    # The repo path to show git age
] {

  $'(ansi p)(char nl)Last commit info of local branches: (ansi reset)(char nl)(char nl)'
  cd $repo
  let branches = (git branch | lines | str substring '2,' | wrap name)
  $branches | update remote { |it| if (has-ref $'origin/($it.name)') { '   √' } else { '' } } | update author { |it| git show $it.name -s --format='%an' } | update last-commit {|it| git show $it.name --no-patch --format=%ci | into datetime } | sort-by last-commit
}

@hustcer
Copy link
Contributor Author

hustcer commented Mar 4, 2022

It's interesting that this way will make it work both on mac and Windows:

# Creates a table listing the branches of a git repository and the day of the last commit
def 'git age' [
  repo: path    # The repo path to show git age
] {

  $'(ansi p)(char nl)Last commit info of local branches: (ansi reset)(char nl)'
  cd $repo
  ( # Use `()` to wrap the pipes to make them work on windows
    git branch
      | lines
      | str substring '2,'
      | wrap name
      | update remote { |it| if (has-ref $'origin/($it.name)') { '   √' } else { '' } }
      | update author { |it| git show $it.name -s --format='%an' }
      | update last-commit {|it| git show $it.name --no-patch --format=%ci | into datetime }
      | sort-by last-commit
  )
}

@jntrnr Can you explain why? and is this a bug?

@sophiajt
Copy link
Contributor

sophiajt commented Mar 5, 2022

This is a good question for design of the parser. Currently, I think it's written so that pipeline has to be wrapped in () to go across multiple lines.

I was chatting with @kubouch a couple weeks ago, and he mentioned that he thought the first case should also work (I think? @kubouch can confirm)

I think we should be able to make the first case work if we want.

@sophiajt
Copy link
Contributor

sophiajt commented Mar 5, 2022

I just tried this on macOS, and, like you said it works okay:

echo "hello" |
str length

I'm going to boot up a Windows machine and see why it doesn't work. I think the intent is that it should work across platforms.

@hustcer
Copy link
Contributor Author

hustcer commented Mar 5, 2022

echo "hello" |
str length

@jntrnr This simple case works on windows, Try this one:

def 'git age' [
  repo: path    # The repo path to show git age
] {

    $'(ansi p)(char nl)Last commit info of local branches: (ansi reset)(char nl)'
    cd $repo
    git branch
      | lines
      | str substring '2,'
      | wrap name
      | update author { |it| git show $it.name -s --format='%an' }
      | update last-commit {|it| git show $it.name --no-patch --format=%ci | into datetime }
      | sort-by last-commit
}

@kubouch
Copy link
Contributor

kubouch commented Mar 5, 2022

Yeah, I think it should be more flexible. I'd also love to be able to line up the | at the beginning, it looks so much nicer than the trailing |s.

@hustcer hustcer added the 0.60 label Mar 5, 2022
@hustcer hustcer added this to the v0.60.0 milestone Mar 5, 2022
@hustcer
Copy link
Contributor Author

hustcer commented Mar 5, 2022

I have just tried the latest main, It's perfect now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working engine-q related to the upcoming engine update
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants