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

Collection of ideas for new functions #7

Open
sharkdp opened this issue Nov 26, 2017 · 19 comments
Open

Collection of ideas for new functions #7

sharkdp opened this issue Nov 26, 2017 · 19 comments

Comments

@sharkdp
Copy link
Owner

@sharkdp sharkdp commented Nov 26, 2017

  • More string utilities (e.g. regex functions)
  • Formatting functions (echo 3.1415 | map format "{:.2f}")
@leeexyz
Copy link
Contributor

@leeexyz leeexyz commented Nov 28, 2017

String

  • search and match based on regex
  • Add regex support for replace input
  • Add function endwith a pattern

Arithmetic

  • Add mod, pow, div and log etc. functions

Filesystem

  • Add function mv to move and rename files
  • More functions to filter files based on file mode bits and ownship
@sharkdp
Copy link
Owner Author

@sharkdp sharkdp commented Nov 28, 2017

@leeleeee Sounds great. Especially the mv function, which will be really useful (we should add cp as well)

@leeexyz
Copy link
Contributor

@leeexyz leeexyz commented Nov 28, 2017

@sharkdp What do you think if we can add du or something like this?

@sharkdp
Copy link
Owner Author

@sharkdp sharkdp commented Nov 28, 2017

@sharkdp What do you think if we can add du or something like this?

In which sense? Like a filesize :: Path -> Int function?


By the way, I just realized that the coreutils du commands works very nicely with functools:

> du | filter -c1 greater_than 8000 | map -c2 abspath
8340	/tmp/demo/folder/subdirectory
8408	/tmp/demo/folder
8480	/tmp/demo
@leeexyz
Copy link
Contributor

@leeexyz leeexyz commented Nov 28, 2017

Yeah, more precisely it is filesize :: Path -> String.

$ find . | map basename | filter startswith test_ | map filesize mb 
test_file1 1MB 
test_file2 5.2MB 

It is fantastic that linux commands are work very well with these functions. 👍

@sharkdp
Copy link
Owner Author

@sharkdp sharkdp commented Apr 1, 2018

filesize is now supported.

@sharkdp
Copy link
Owner Author

@sharkdp sharkdp commented Apr 8, 2018

  • fst and snd for array-index access (alias for index 1 and index 2)
  • replicate
  • reverse
sharkdp added a commit that referenced this issue May 2, 2018
@ghost
Copy link

@ghost ghost commented May 5, 2018

Does split currently work with variable size of whitespace between words? if not, does it make sense to add it? Something like below by default if no separator is provided, then it would be a nice replacement for awk

➜  ~ echo "a b         ccc " | ~/repos/shell-functools/ft/map split | map at 2
ccc
@sharkdp
Copy link
Owner Author

@sharkdp sharkdp commented May 6, 2018

Does split currently work with variable size of whitespace between words?

It does not (yet). We could either provide a split_whitespace function which would simply call .split() without argument and/or provide a split_regex function which could be called with map split_regex '\s+'.

@vegarsti
Copy link
Contributor

@vegarsti vegarsti commented May 23, 2018

The reverse function, do you mean on array level, or on string level?

@sharkdp
Copy link
Owner Author

@sharkdp sharkdp commented May 24, 2018

I think array-reverse can be useful. Not sure if we need a string-reverse function.

@guilhermeleobas
Copy link
Contributor

@guilhermeleobas guilhermeleobas commented Oct 1, 2018

Hey @sharkdp, what about creating a max as well as min function in shell-functools? I can work on something if there is interest.

max :: Array -> Int
find . -name cnt.txt | xargs cat | max
@sharkdp
Copy link
Owner Author

@sharkdp sharkdp commented Oct 1, 2018

@guilhermeleobas Sounds great!

@Jake6329
Copy link

@Jake6329 Jake6329 commented Nov 20, 2018

These days, new unix/linux CLI tools are coming out supporting JSON outputs. Would it make sense to create a json function that can parse JSON outputs?

@sharkdp
Copy link
Owner Author

@sharkdp sharkdp commented Nov 21, 2018

These days, new unix/linux CLI tools are coming out supporting JSON outputs. Would it make sense to create a json function that can parse JSON outputs?

I've been thinking about JSON support in the past, so this sounds interesting. What would this function do, exactly?

@Jake6329
Copy link

@Jake6329 Jake6329 commented Dec 3, 2018

I can imagine there would a command named json which could be used like this:

$ curl http://echo.jsontest.com/key1/value1 | json key1

The curl command outputs {"key1": "value1"}. The whole command would output value1. The argument to json command would specify the path to the value you want. It could support the full json path spec or just a small part of it.

And then there would also a function called json which could be used like this:

$ curl <url that returns json in each line> | map json <json path>

In this case, the assumption is that the curl outputs a json-encoded string in each line, which is also a proposed standard format called jsonlines. And the map will transform each line with the json function.

$ <command that outputs json> | json <path to an array of objects> | map json <path in each object>

In the above command, the json command narrows data down to an array of objects, and then map json transforms each json into something. I think the path you specify could be some kind of template so that you can transform json into anything, which sounds a bit too ambitious.

@sharkdp
Copy link
Owner Author

@sharkdp sharkdp commented Dec 5, 2018

Do you know jq? I think this could probably play well in combination with shell-functools.

@Jake6329
Copy link

@Jake6329 Jake6329 commented Dec 5, 2018

@sharkdp jq seems to cover my use cases. Cool, thanks.

@sharkdp
Copy link
Owner Author

@sharkdp sharkdp commented May 18, 2019

More functions that should be implemented:

  • div/divide
  • sum/product (working on arrays)
  • matches => similar to starts_width/ends_with
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.