An open API service indexing awesome lists of open source software.

https://github.com/nightmachinery/possiblycat

cat with a timeout on waiting for the first byte of stdin
https://github.com/nightmachinery/possiblycat

Last synced: 11 months ago
JSON representation

cat with a timeout on waiting for the first byte of stdin

Awesome Lists containing this project

README

          

#+TITLE: possiblycat

A helper tool to optionally get the stdin if present.

* Installation
#+BEGIN_example
go get -u -v github.com/NightMachinary/possiblycat
#+END_example
* Usage
#+begin_src bsh.dash :results verbatim :exports both
possiblycat ; echo exited $?
#+end_src

#+RESULTS:
: exited 0

#+begin_src bsh.dash :results verbatim :exports both
time possiblycat
#+end_src

#+RESULTS:
: possiblycat 0.00s user 0.00s system 66% cpu 0.005 total; max RSS 1852

#+begin_src bsh.dash :results verbatim :exports both
{ xxd -l 100 -p /dev/urandom ; ec --- ; ec ok } | possiblycat ; echo exited $?
#+end_src

#+RESULTS:
: af61692667c76c5cc5235b632b43385988f473f6e4eab330a3bdf56af0c5
: 9e3d48f49cde4be7cabb7694fea8417440b59f07142e9a7a4b32680955fe
: 5c054a2ad97ec9833083647f99e8f14f223881e9d1d374c5a3f17b3d4b9e
: 0c11a163029f2ef87601
: ---
: ok
: exited 0

You can also give it the timeout duration in milliseconds:

#+begin_src bsh.dash :results verbatim :exports both
true | time possiblycat 500 ; echo exited $?
#+end_src

#+RESULTS:
: exited 0
: possiblycat 500 0.00s user 0.00s system 69% cpu 0.004 total; max RSS 1856

#+begin_src bsh.dash :results verbatim :exports both
{ sleep 1 ; echo hi } | time possiblycat 500 ; echo exited $?
#+end_src

#+RESULTS:
: exited 1
: possiblycat 500 0.00s user 0.00s system 0% cpu 0.508 total; max RSS 1868

#+begin_src bsh.dash :results verbatim :exports both
{ sleep 1 ; echo hi } | time possiblycat 1500 ; echo exited $?
#+end_src

#+RESULTS:
: hi
: exited 0
: possiblycat 1500 0.00s user 0.00s system 0% cpu 1.005 total; max RSS 1872

#+begin_src bsh.dash :results verbatim :exports both
{ echo -n a ; sleep 0.3 ; echo $'\n'ok } | possiblycat
#+end_src

#+RESULTS:
: a
: ok

#+begin_src bsh.dash :results verbatim :exports both
{ sleep 0.3 ; echo $'\n'ok } | possiblycat
#+end_src

#+RESULTS:

#+begin_src bsh.dash :results verbatim :exports none
# Buggy here:
stty cbreak ; bash -c 'echo -n a ; sleep 0.5 ; echo b' | possiblycat
#+end_src

#+RESULTS:
: ab
: stty: stdin isn't a terminal