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

Run neofetch #679

Closed
andychu opened this issue Mar 24, 2020 · 18 comments
Closed

Run neofetch #679

andychu opened this issue Mar 24, 2020 · 18 comments

Comments

@andychu
Copy link
Contributor

andychu commented Mar 24, 2020

For some reason it doesn't output anything in OSH. Maybe it's using BASH_VERSION or something?

$ time osh -c '. neofetch'

real    0m43.913s
user    0m34.671s
sys     0m9.428s

$ time bash -c '. neofetch'
            .-/+oossssoo+/-.               andy@lisa 
        `:+ssssssssssssssssss+:`           --------- 
      -+ssssssssssssssssssyyssss+-         OS: Ubuntu 16.04.2 LTS x86_64 
    .ossssssssssssssssssdMMMNysssso.       Host: XPS 8700 
   /ssssssssssshdmmNNmmyNMMMMhssssss/      Kernel: 4.15.0-88-generic 
  +ssssssssshmydMMMMMMMNddddyssssssss+     Uptime: 15 days, 19 hours, 26 mins 
 /sssssssshNMMMyhhyyyyhmNMMMNhssssssss/    Packages: 2877 (dpkg), 33 (nix-user) 
.ssssssssdMMMNhsssssssssshNMMMdssssssss.   Shell: bash 4.3.48 
+sssshhhyNMMNyssssssssssssyNMMMysssssss+   Resolution: 1920x1200 
ossyNMMMNyMMhsssssssssssssshmmmhssssssso   DE: Unity 7.4.0 
ossyNMMMNyMMhsssssssssssssshmmmhssssssso   WM: Compiz 
+sssshhhyNMMNyssssssssssssyNMMMysssssss+   WM Theme: Ambiance 
.ssssssssdMMMNhsssssssssshNMMMdssssssss.   Theme: Ambiance [GTK2/3] 
 /sssssssshNMMMyhhyyyyhdNMMMNhssssssss/    Icons: ubuntu-mono-dark [GTK2/3] 
  +sssssssssdmydMMMMMMMMddddyssssssss+     CPU: Intel i7-4790 (8) @ 4.000GHz 
   /ssssssssssshdmNNNNmyNMMMMhssssss/      GPU: NVIDIA GeForce GT 730 
    .ossssssssssssssssssdMMMNysssso.       Memory: 12614MiB / 24055MiB 
      -+sssssssssssssssssyyyssss+-
        `:+ssssssssssssssssss+:`                                   
            .-/+oossssoo+/-.                                       



real    0m0.349s
user    0m0.243s
sys     0m0.095s

@Crestwave
Copy link
Contributor

Crestwave commented Apr 6, 2020

Depends on #273

It does use BASH_VERSION although it doesn't seem to be the cause of the error (I set bash_version to 5 at the start of the script, anyway).

I tried running it (with $(< replaced with $(cat as a workaround), and got the error FATAL: RuntimeError('maximum recursion depth exceeded',). It looks like OSH can only handle a certain amount of nesting, and Neofetch separates everything to functions and such so it can go pretty deep. I'm using the minimal build, though; not sure if the full build is any different, as I forgot how I built it before.

EDIT: Okay, I remembered how to build it, but there doesn't seem to be any difference

Also, regarding the "May also do something interesting with images (?)" in the wiki, yeah, there's image displaying support using backends such as w3m-img, caca, sixel, etc.

@andychu
Copy link
Contributor Author

andychu commented Apr 6, 2020

Thanks for testing it -- Can you share the patch that leads to RuntimeError? Either on the web, as a gist, upload on zulip, etc.

I think it could be an infinite recursion bug perhaps caused by badly executing something in neofetch. A normal shell program shouldn't blow the stack unless it's doing something really weird.

@Crestwave
Copy link
Contributor

Crestwave commented Apr 7, 2020

Actually, I think I remember a function executing multiple times and forgot it until you mentioned that... anyway, stock Neofetch actually already triggers it on my desktop, but it doesn't reach there on my laptop because of #694

EDIT: The recursing function is print_ascii and could also be because of #694

@andychu
Copy link
Contributor Author

andychu commented Apr 7, 2020

OK I fixed #694 and #273. It does something now, but not the right thing!

$ time ~/git/oilshell/oil/bin/osh neofetch
e[24C--------- 
e[24COS: /home/andy/git/oilshell/oil/bin/osh (Unknown) x86_64 
e[24CKernel: 4.15.0-88-generic 
e[24CUptime: secs 
e[24CShell: bash 
e[24CResolution: 1920x1200 
   ###############
real####0m3.285s###
user####0m2.801s###
sys#####0m0.508s#####

@Crestwave
Copy link
Contributor

One issue is that OSH interprets backslashes in quoted + parameter expansion (i.e., "${#:+\$}"). Another issue is that Neofetch uses $uptime instead of ${uptime[0]}, which is probably unintentional; I'll send a PR later if we need numerous changes or just tell dylan in IRC when he gets his new laptop. With these fixed, all the sections are printed (though with missing numbers and such) and formatted correctly, but it also still can't detect some stuff.

What would be the preferred way for getting OSH's version?

@Crestwave
Copy link
Contributor

Also, Neofetch uses $_ to refer to the previous argument, but OSH doesn't seem to implement that part.

@Crestwave
Copy link
Contributor

:)

(patched for the mentioned issues and for BASH_VERSION)

@Crestwave
Copy link
Contributor

Oh, forgot about the title portion. One issue is that ${!1:-foo} where there are no positional parameters fails in OSH but substitutes for foo in Bash. Another issue is that the trim function fails on the title with AssertionError: Unexpected escaped character 'e' but I can't seem to reproduce it outside of neofetch.

@Crestwave
Copy link
Contributor

Crestwave commented Apr 7, 2020

Strangely, the error happens on executing set -f. And setting the positional parameter manually in the function works. Curious.

Also, I forgot the GPU; it uses nocasematch and it doesn't seem to work in OSH. Also, I haven't triggered it, but it seems that it uses unset -v "gpus[0]" in a certain situation, which requires eval_unsafe_arith, right?

@Crestwave
Copy link
Contributor

OSH also doesn't seem to execute EXIT traps on INT, so my cursor keeps disappearing.

@Crestwave
Copy link
Contributor

Okay, I finally figured out the assertion error; I was confused because the output in OSH's xtrace escapes backslashes, i.e.:

osh$ set -x
osh$ echo '\'
+ echo '\\'
\

Not sure if this is intended. Anyway, I also got confused with some other stuff due to some mistakes, but after I figured that out, I found out that the issue is with backslashes in unquoted variables when globbing is off. For example:

osh$ var='\e'
osh$ set -f
osh$ echo $var
Traceback (most recent call last):
  File "/home/usr/oil/bin/oil.py", line 996, in <module>
    sys.exit(main(sys.argv))
  File "/home/usr/oil/bin/oil.py", line 942, in main
    return AppBundleMain(argv)
  File "/home/usr/oil/bin/oil.py", line 915, in AppBundleMain
    status = ShellMain('osh', argv0, main_argv, login_shell)
  File "/home/usr/oil/bin/oil.py", line 717, in ShellMain
    prompt_plugin, errfmt)
  File "/home/usr/oil/core/main_loop.py", line 98, in Interactive
    is_return, _ = cmd_ev.ExecuteAndCatch(node)
  File "/home/usr/oil/osh/cmd_eval.py", line 1439, in ExecuteAndCatch
    status = self._Execute(node)
  File "/home/usr/oil/osh/cmd_eval.py", line 1323, in _Execute
    status, check_errexit = self._Dispatch(node)
  File "/home/usr/oil/osh/cmd_eval.py", line 535, in _Dispatch
    cmd_val = self.word_ev.EvalWordSequence2(words, allow_assign=True)
  File "/home/usr/oil/osh/word_eval.py", line 1850, in EvalWordSequence2
    self._EvalWordFrame(frame, strs)
  File "/home/usr/oil/osh/word_eval.py", line 1611, in _EvalWordFrame
    self.globber.Expand(a, argv)
  File "/home/usr/oil/osh/glob_.py", line 373, in Expand
    out.append(GlobUnescape(arg))
  File "/home/usr/oil/osh/glob_.py", line 135, in GlobUnescape
    raise AssertionError("Unexpected escaped character %r" % c2)
AssertionError: Unexpected escaped character 'e'

@andychu
Copy link
Contributor Author

andychu commented Apr 8, 2020

Let's discuss this patch here, very interesting!

https://github.com/Crestwave/snippets/blob/master/neofetch.patch

  • It looks like provide a way to query the version #683 to query the version is inevitable. I will add $OIL_VERSION as a start.
  • nocasematch seems very doable
  • I want to fix everything in ${} (presumably other shells agree with bash), but I'm not sure how yet. I need some time to concentrate on that area, like I did recently with a good lvalue refactoring related to arithmetic and unset -v, etc.

@andychu
Copy link
Contributor Author

andychu commented Apr 16, 2020

Based on https://github.com/dylanaraps/neofetch/pull/1442/files it looks like #701 is one of the more significant patches, but if it gets upstreamed, awesome :)

Also I'm curious if we can generate coverage to see how many of the 10K lines of neofetch are actually being run. #687

@Crestwave
Copy link
Contributor

It's been merged! :)

@andychu
Copy link
Contributor Author

andychu commented Apr 16, 2020

Awesome!! Thanks you for working on this and debugging it -- I know first-hand how hard that can be.

This is a big milestone: neofetch seems to be one of

https://github.com/oilshell/oil/wiki/The-Biggest-Shell-Programs-in-the-World

I think it will also be useful for some parsing benchmarks since it's such a big file :) And execution benchmarks when the C++ translation is ready.

Probably time to make a release soon ...


If there are any debugging features that would help get more scripts running, feel free to discuss on Zulip or file a new issue. I fixed the xtrace argv format, although I seem to recall that assignments are not printed very well right now.

@andychu
Copy link
Contributor Author

andychu commented Apr 16, 2020

@Crestwave
Copy link
Contributor

This is a big milestone

Definitely! This is probably the first non-trivial Bash program I've tried that works on OSH.

Note that Dylan went ahead and implemented two patches before my PR, though:

dylanaraps/neofetch@23c445d
dylanaraps/neofetch@23c445d

The first is a good thing since it was a mistake that OSH caught. As for the second, he's not a fan of dropping $_ and mentioned that he was going to make a comment on it, although he seems to be busy so far.

@andychu
Copy link
Contributor Author

andychu commented Apr 16, 2020

I think by now more bash programs should work. I had to fork bash-completion to get it to work, but I would categorize it as "very long and complex" like neofetch:

https://github.com/oilshell/bash-completion/

I mean there are plenty of bash programs in the 500 line range?

Although it does appear that more programs rely on shopt -s eval_unsafe_arith than I thought. I think @danyspin97 said that starship.rs does

More ideas here: https://github.com/oilshell/oil/labels/should-run-this

I will try to improve tracing support as mentioned; I think that will help, as I know it's painful now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants