Skip to content
This repository was archived by the owner on Jan 31, 2024. It is now read-only.

Commit cc57e2a

Browse files
authored
Merge pull request #20 from ajmichels/stdin
add STDIN to note content
2 parents 2f18839 + a2808ab commit cc57e2a

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "ajmichels/note-script",
33
"description": "A utility for note taking.",
44
"keywords": ["utility", "notes", "productivity", "markdown"],
5-
"version": "0.1.0",
5+
"version": "0.2.0",
66
"license": "GPL-2.0",
77
"type": "project",
88
"authors": [

src/main/Main.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function process()
8282
$header = self::generateNoteHeader($date, $title);
8383
$fileName = self::generateFileName($date, $title);
8484
$filePath = sprintf('%s/%s.md', $this->config[Config::NOTE_DIR], $fileName);
85-
$this->fileUtil->writeFile($filePath, $header);
85+
$this->fileUtil->writeFile($filePath, $header . self::readStdIn());
8686

8787
return $filePath;
8888
}
@@ -155,5 +155,15 @@ public static function generateNoteHeader(DateTime $date, $title = null)
155155
return $header;
156156
}
157157

158+
/**
159+
* Retrieve any standard in content that was piped into the script.
160+
* @return string
161+
*/
162+
public static function readStdIn()
163+
{
164+
// prevent the read from waiting for user input
165+
stream_set_blocking(STDIN, 0);
166+
return trim(stream_get_contents(STDIN));
167+
}
158168

159169
}

0 commit comments

Comments
 (0)