1
2
Fork
You've already forked janet-sh
0
Shorthand shell-like functions for Janet.
  • Janet 87.1%
  • C 12.9%
Find a file
2026年01月23日 23:09:02 +01:00
test $< and $<_ dup stdout before any custom redirects 2023年04月24日 17:14:41 -07:00
.gitignore Placed doc example code inside code blocks 2022年07月07日 15:13:08 +01:00
_sh.c Report C errors with a nicer name. 2020年05月13日 13:13:54 +12:00
project.janet Document package 2026年01月09日 20:18:11 -07:00
README.md Retire fork already 2026年01月23日 23:09:02 +01:00
sh.janet Accept > filename 2026年01月09日 18:32:56 -07:00

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