Live data from Hacker News

Awkward – A Node.js-based terminal emulator

github.com

11–20 of 64 posts

Re: Awkward – A Node.js-based terminal emulator

#11
Hey,

This is very cool. It does remind me of powershell in it's aims & inspiration. But agree with nailer that using json (or javascript data structures) would hopefully end up with a better, more cohesive shell in awkward. I no longer use Powershell (I got sick of the microsoft ecosystem)

I'm not sure what format Powershell uses to pipe structured data around, but it seemed to be some kind of ad-hoc 'whatever-they-came-up-with-at-the-time' mish mash, instead of using say, JSON, and leveraging the power of arrays, dictionaries et al. In fairness json was just starting when I was using Powershell, so it wouldnt have been on their radar.

One question, How are you turning output from ls into arrays? Or is ls just a javascript function that behaves like ls?

Oh, also, what strategies do you envision for wrapping arbitrary commands, or creating an ecosystem of wrappers? Perhaps some kind of plugin system?

I am currently also getting excited by hyperterm, and wonder if there is some kind of fusion there with your project (that is getting _alot_ of traction).

Cheers for the cool software!

Re: Awkward – A Node.js-based terminal emulator

#12

Uh... ps | awk 'NR>1{ print $1, $4}' I'll give that the syntax of these shell programs take some work to understand but they're hard to beat for the purpose they serve. If you're parsing plenty of JSON these days I find 'jq' indispensable. It's basically awk/sed for JSON. I would just be sure to study those programs as they took quite a bit of effort to make them fast. And there are plenty of alternatives with extend…

I understand and agree. You could see this thing as me riding the JS hype train.

Re: Awkward – A Node.js-based terminal emulator

#13

Uh... ps | awk 'NR>1{ print $1, $4}' I'll give that the syntax of these shell programs take some work to understand but they're hard to beat for the purpose they serve. If you're parsing plenty of JSON these days I find 'jq' indispensable. It's basically awk/sed for JSON. I would just be sure to study those programs as they took quite a bit of effort to make them fast. And there are plenty of alternatives with extend…

I'm sorry but that seems to be some of the least intuitive code I have ever seen. What are the practical applications of knowing AWK over knowing JS? (Besides the shell voodoo). I'm not trying to start a language war, I just want to understand why learning a completely new set of grammars with a very limited domain would be worth the effort.

Re: Awkward – A Node.js-based terminal emulator

#14
I wonder how long it will take before something like this gets implemented as a `Hyperterm` [0] plugin.

I think it could be quite useful to combine `npm` packages with shell commands and `map`, `filter`, etc, in your terminal.

The only thing I am unsure about are the underlying representations of the shell output. Arrays of arrays are not very semantic, so the code that parses them would not be very pleasant.

Given a shape like:

  [ 
    [ 'PID', 'TTY', 'TIME', 'CMD' ],
    [ '13750', 'pts/14', '00:00:00', 'bash' ],
    [ '25193', 'pts/14', '00:00:03', 'node' ],
    [ '25283', 'pts/14', '00:00:00', 'sh' ],
    [ '25284', 'pts/14', '00:00:00', 'ps' ]
  ]
I would probably like to be able to apply some kind of transforms by default so that I can work with:

  [ 
    { pid: '13750', tty: 'pts/14', time: '00:00:00', cmd: 'bash' },
    { pid: '25193', tty: 'pts/14', time: '00:00:03', cmd: 'node' },
    { pid: '25283', tty: 'pts/14', time: '00:00:00', cmd: 'sh' },
    { pid: '25284', tty: 'pts/14', time: '00:00:00', cmd: 'ps' }
  ]
Though if this was the case you would want some way of applying the right transform depending on the arguments passed into the command.

I guess the bad thing is that there is currently presumably no way of using other shell features like pipes.

Also, if you're going to start outputting different shaped data, then I think you should consider hooking this all up to `flowtype` [1] and creating type signatures to provide DX [2]

[0] https://github.com/zeit/hyperterm

[1] https://flowtype.org/

[2] https://news.ycombinator.com/item?id=12129026

Re: Awkward – A Node.js-based terminal emulator

#15

Hey, This is very cool. It does remind me of powershell in it's aims & inspiration. But agree with nailer that using json (or javascript data structures) would hopefully end up with a better, more cohesive shell in awkward. I no longer use Powershell (I got sick of the microsoft ecosystem) I'm not sure what format Powershell uses to pipe structured data around, but it seemed to be some kind of ad-hoc 'whatever-they-c…

Thank you!

Regarding how I structure the command output, this is the module which does the job https://github.com/iostreamer-X/Awkward/blob/master/terminal...

It splits on basis of '\n' and removes empty chars, then finally pushes the cleaned output in an array.

Regarding, the plugin system. Well, honestly I haven't thought about it but I do like the sound of it. Thanks for sharing the idea.

I am yet to try hyperterm but from what I have seen, it looks sooo awesome, and I think things could get 'awkward' there :p

Re: Awkward – A Node.js-based terminal emulator

#18

Uh... ps | awk 'NR>1{ print $1, $4}' I'll give that the syntax of these shell programs take some work to understand but they're hard to beat for the purpose they serve. If you're parsing plenty of JSON these days I find 'jq' indispensable. It's basically awk/sed for JSON. I would just be sure to study those programs as they took quite a bit of effort to make them fast. And there are plenty of alternatives with extend…

I'm sorry but that seems to be some of the least intuitive code I have ever seen. What are the practical applications of knowing AWK over knowing JS? (Besides the shell voodoo). I'm not trying to start a language war, I just want to understand why learning a completely new set of grammars with a very limited domain would be worth the effort.

I think of it as a poorly designed DSL. Still, a poorly designed DSL, once memorized, is way more practical on the command line than typing out javascript function calls, even with the fat arrow syntax. Maybe it's a declarative vs imperative kind of thing. I hate having to reference manpages or use trial and error every time I need to sed/awk, but I don't know if wrapping commands in JS functions and results in Array.prototype is the best solution.

Re: Awkward – A Node.js-based terminal emulator

#20

Uh... ps | awk 'NR>1{ print $1, $4}' I'll give that the syntax of these shell programs take some work to understand but they're hard to beat for the purpose they serve. If you're parsing plenty of JSON these days I find 'jq' indispensable. It's basically awk/sed for JSON. I would just be sure to study those programs as they took quite a bit of effort to make them fast. And there are plenty of alternatives with extend…

I'm sorry but that seems to be some of the least intuitive code I have ever seen. What are the practical applications of knowing AWK over knowing JS? (Besides the shell voodoo). I'm not trying to start a language war, I just want to understand why learning a completely new set of grammars with a very limited domain would be worth the effort.

Awk is actually very intuitive once you learn the basics (should take about an hour). Awk is essentially a line-oriented pattern matching language, that is, a collection of patterns -> actions that are applied to every line of input. Syntax is very similar to C, but feels much more lightweight.

To decompose the example above:

  NR > 1 {
     print $1, $4
  }
There are two parts to this, the pattern (the part outside the brackets), and the action (the part inside the brackets). Every line parsed is split into fields and stored in $1..$NR, where NR is the number of fields. The entire line is also available in the $0 variable. The default separator is the space character, though that can be changed.

So, knowing the above semantics, the meaning of the above example should be clear: If the number of fields for this line is larger than 1, print the first and fourth field of the line. It's a very powerful paradigm, and you can do crazy stuff with Awk. Examples are an x86 assembler [0] and a SASS-style CSS preprocessor [1] (plugging myself there a bit).

Unix coreutils are very powerful once you're familiar with them.

[0]: http://doc.cat-v.org/henry_spencer/amazing_awk_assembler/ [1]: https://github.com/deuill/fawkss

Post reply on HN