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

Commit 9b93272

Browse files
committed
add STDIN to note content
This update will also users to pipe and redirect content into a note. closes #2
1 parent 05b7467 commit 9b93272

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

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)