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

Read from stdin #124

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft

Read from stdin #124

wants to merge 5 commits into from

Conversation

Arxcis
Copy link
Collaborator

@Arxcis Arxcis commented Aug 3, 2019

Because UNIX programs should read from stdin...
Concatenates cmd-args and stdin-args if both are present.

Example use cases

$ goto list | goto show
spotify://artist:0du5cEVh5yTK9QJze8zA0C
~/Downloads
~/git/github/technocake/goto
http://www.giphy.com/gifs/lRuZmnyHiEoID1UxXf
https://github.com/technocake/goto
https://github.com/technocake/goto/issues
dict://catharsis
https://github.com/technocake/goto/wiki/List-of-uri-schemes-known-to-work-well-with-goto
ibooks://assetid/714158600
https://github.com/technocake/goto/issues/new
https://github.com/technocake/goto/pulls
https://github.com/technocake/goto
steam://nav/downloads
steam://friends/
steam://nav/games
ibooks://assetid/1002622538
spotify:artist:23ytwhG1pzX6DIVWRWvW1r
https://toggl.com
$ goto list | grep steam | goto show
steam://nav/downloads
steam://friends/
steam://nav/games

@Arxcis Arxcis added the feature label Aug 3, 2019
@Arxcis Arxcis changed the title Read args from stdin. Concatenate cmd-args and stdin-args Read from stdin and concatenate cmd-args and stdin-args Aug 3, 2019
@@ -37,37 +37,6 @@ function _goto_main {
fi


# Special case 1 (goto cd <magicword>)
if [ "$1" = "cd" ]; then
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need help understanding why special case 1 and 2 blocks stdin from passing to the_real_goto

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, will conduct tests. I believe we would save us self of lots of complexity if we add the explicit mark of taking input from stdin: -

I don't have my copy of the UNIX Programming Environment at hand right now, but I recall there was a mention of this convention in there :)

@Arxcis Arxcis changed the title Read from stdin and concatenate cmd-args and stdin-args Read from stdin Aug 3, 2019
@Arxcis Arxcis requested a review from technocake August 3, 2019 19:58
@technocake
Copy link
Owner

Nice idea!

We could follow the convention of marking that you take the input from stdin by using - as in goto show -
otherwise it would require quite the bit of complexity to distinguish the errorous command goto show (which has stdin, albeit not used before this implementation) and the one in the example you provide

@Arxcis
Copy link
Collaborator Author

Arxcis commented Aug 4, 2019

We could follow the convention of marking that you take the input from stdin by using - as in goto show -

Using - to signify that you read from stdin is the behaviour of grep and cat at least, and probably most other standard unix programs.

Reading from stdin is the default behaviour though, so it is not necessary to specify - in most cases.

Also stdin is more treated like a file. (I see that treating it like an array of arguments like I have done, may be the wrong approach). If the command supports reading from files, you may supply multiple filename-arguments in addition to - at the same time.
Example:

$ echo hello from echo! | cat - .gitignore | head
hello from echo!
# magic words and projects are stored in this folder
.state
# active project is stored in this file
active-project

*.sublime-workspace

Here stdin or - or 0 or /dev/stdin is just another file in a collection of files

But the --file is the default file to read from

$ echo hello from echo! | cat | head
hello from echo!

@Arxcis
Copy link
Collaborator Author

Arxcis commented Aug 4, 2019

I think the most UNIX-y thing to do here is to make the commands support filenames as arguments, and then stdin or - is just a special case of a filename, which also happens to be the default filename IF stdin is not empty.

@technocake
Copy link
Owner

technocake commented Aug 11, 2019

image

I still believe the - should be used to explicitly signal you want to read from stdin.
standard goto commands would hang, waiting for an EOF without it.
It is also visual clear that you are doing something special / magic when you add the magical - to the arguments.

Regarding adding filenames as arguments for reading, this should be handled carefully.
The auto completions would be quite contaminated if we included the current files and folders in with the magicwords. However, it is a powerful feature, and a good part of the unix swiss knife, so I suggest we follow convetions here to add an option before the actual file. Autocompletions can be tailored to only list files after this flag.

Example:

goto show --file magicwords.txt

But that example could also be implemented like this:
cat magicwords.txt | goto show -

@Arxcis
Copy link
Collaborator Author

Arxcis commented Aug 11, 2019

But that example could also be implemented like this:
cat magicwords.txt | goto show -

I like it 👍

I also found an example using - to signify stdout in the apitrace-project found on github here:
https://github.com/apitrace/apitrace/blob/master/docs/USAGE.markdown#recording-a-video-with-ffmpeglibav

apitrace dump-images -o - application.trace | ffmpeg <stuff>

Where -o or --output is the output file

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

Successfully merging this pull request may close these issues.

2 participants