oh-my-fish / oh-my-fish-legacy

Oh My Fish!
MIT License
13 stars 2 forks source link

Sparklines for your Fish #295

Closed ghost closed 9 years ago

ghost commented 9 years ago

shark

A fish port of spark.

Install

git clone https://github.com/bucaran/shark
cd shark
cp shark /your/bin/shark # e.g /usr/local/bin/shark
fish -c "for i in (seq 127); random; end" | shark

Summary

Parse a string or stream of characters and generate sparklines for any real positive numbers in a dataset.

$ shark 1 5 22 13 53
   ▁▁▃▂█
$ shark 0,30,55,80,33,150
   ▁▂▃▄▂█
$ echo 1/2/3/5/6/7/5/8/2 | shark
   ▁▂▃▅▆▇▅█▂
$ echo 9 13 5 17 1 | shark
   ▄▆▂█▁

I would like to adapt shark for Oh-My-Fish.

What do you think?

bpinto commented 9 years ago

I like the port. I don't know what you mean about adapting it for oh-my-fish though.

My feeling is that it would be better to add fish support for the spark tool. If they deny it, then I think adding it to oh-my-fish would be the next step.

ghost commented 9 years ago

While still essentially a port, as I have adapted the original formula, it ended up diverging from the original in implementation and other details so as to add support for more separators, garbled up input, etc.

My feeling is that it would be better to add fish support for the spark tool.

I understand what you mean, but if you inspect Spark's source you will quickly discover it's quite verbose in bashisms. In other words, there is no way to add support to the original spark for Fish without spawning bash itself from within a Fish wrapper and that would be slow.

Shark on the other hand was completely built using Fish, while still passing the same tests.

Another thing, anyone feel free to correct if I am missing something, but in order to handle piped input (echo 1 2 3 | shark), shark must have its own process and it can not be a function.

So, in order to add shark to OMF, the plugin should basically install / uninstall the script. What do you think?

I simply keep my binaries under /usr/local/bin/, but I need to research what are the best practices for installing shell scripts.

bpinto commented 9 years ago

I'm unsure, not sure if it's on oh-my-fish scope to be a package manager.

ghost commented 9 years ago

I see this could be useful to theme authors wanting to add sparklines to their prompt, the possibilities are endless.

bpinto commented 9 years ago

I am open to suggestions. Probably something alike import package/shark

ghost commented 9 years ago

What's inside package/? Would it be like directory with install scripts for packages?

bpinto commented 9 years ago

This is what I was thinking (could be a very bad thought):

require_package shark would execute a function that would check whether shark is in your $PATH, if not, would give you a message telling you to run install_package shark.

Update: install_package might be too much, but it could echo a package install instructions url, in this case, github's readme.

ghost commented 9 years ago

I like this. Perhaps someone will say this approach it's a bit too naive, but I really can't think what's so bad about it.

In the meantime, a trivial, but risk-free solution would be not adding anything to the $PATH and simply keep binaries in $fish_path/packages and have a global variable $pkg set to this path so as to allow echo 1 2 3 | $pkg/shark

EDIT: This would require eval $pkg/shark 1 2 3. So, no.

bpinto commented 9 years ago

I think it's a simple way to make sure we have the package installed, and I can see this being used for more packages (we already have themes that requires some). And if the packages are not included we can do two things:

  1. Show a better error message.
  2. Mock the real package (not sure about the implications here) call when it's not available.
ghost commented 9 years ago

I caught this on your test/helper.fish. Error message like this?

set -l fish_tank /usr/local/share/fish-tank/tank.fish
if not test -e $fish_tank
  echo 'error: fish-tank is required to run these tests (https://github.com/terlar/fish-tank)'
  exit 1
end

source $fish_tank
bpinto commented 9 years ago

I think an error message like that would be great.

ghost commented 9 years ago

Thoughts? It would make a nice plugin maybe?

$ shark 0,30,55,80,33,150
   ▁▂▃▄▂█
bpinto commented 9 years ago

I was thinking about it, and I don't know what would the plugin contain. As you said we need it to be a binary file, basically to use shark, we just need to download the binary and add it to the path.

Should we handle it? What would be the plugin responsabilities?

ghost commented 9 years ago

Right. A plugin for shark does not make much sense, but a plugin to handle binaries / packages does.

Oh-my-fish is the fish framework. It's what should come next after installing fish.

How should oh-my-fish handle binaries? get or fetch: a plugin to search a central registry sea or ocean; download and install fish binaries nuggets. Just thinking out loud here.

get shark
→ Connecting to ocean registry...
Downloading `bucaran/shark`
`shark` installed to `usr/local/bin` ✓
bpinto commented 9 years ago

What about brew? apt-get? They handle it so nicely, plus, they are shell agnostic. I don't think it's worth redoing what other established tools already do.

The solution I see for this is to create an external plugin and embedding shark inside of the plugin, see https://github.com/bpinto/oh-my-fish/issues/259

ghost commented 9 years ago

:+1: