Shorthand shell-like functions for Janet.
- Janet 87.1%
- C 12.9%
| test | $< and $<_ dup stdout before any custom redirects | |
| .gitignore | Placed doc example code inside code blocks | |
| _sh.c | Report C errors with a nicer name. | |
| project.janet | Document package | |
| README.md | Retire fork already | |
| sh.janet | Accept > filename | |
Supereceded by sh-dsl
janet-sh
The rationale and design is partially covered in a blog post. A dedicated textbook chapter teaches how to get the most out of it.
Quick examples
(import sh)
(sh/$ touch foo.txt) # raise an error on failure
# raise an error on failure, return command output
(sh/$< echo "hello world!") # > "hello world!\n"
(when (sh/$? true) # return true or false based on success
(print "cool!"))
(sh/$ cat ,path | sort | uniq) # pipelines
(match (sh/run yes | head -n5) # pipeline matching
[0 0] :ok)
Can pass > etc. allow a string or file object:
($ "gpg" "--export-secret-keys" "--armor" > "private-keys.asc")
# same as:
(with [out (file/open "private-keys.asc" :w)]
(sh/$ "gpg" "--export-secret-keys" "--armor" > ,out))
Note how sh/$'s contents are quasiquoted, allowing direct or string arguments, so you need to unquote (,) variables.
sh/$ can't expand ~ so you must build it:
# (def key "D8E4DB18BF87FLEW7402BBE3AA91B16F4A65C4C9") # use your gpg key ID
(defn copy-and-encrypt-password-store [key-id]
(with [out (file/open "pass-backup.tar.gz.gpg" :w)]
(sh/$ tar -czf - ,(string (os/getenv "HOME") "/.password-store")
| gpg --encrypt --recipient ,key-id > ,out)))
# tar -cz ~/.password-store/ | gpg --encrypt --recipient YOUR_KEY_ID > pass-backup.tar.gz.gpg