andrewchambers / janet-sh Goto Github PK
View Code? Open in Web Editor NEWShorthand shell like functions for janet.
Shorthand shell like functions for janet.
Hi,
is it possible to ignore nil
values? Currently, it thows error: unsupported argument nil
.
Thank you.
I have two directories, full
and empty
. full
has a file in it; empty
does not. I would expect that a wildcard search inside of full
would return an array with one entry, and that a search inside of empty
would return an empty array.
Here's a session:
Janet 1.12.2-5df8ac5 linux/x64 - '(doc)' for help
repl:1:> (import sh)
nil
repl:2:> (sh/glob "full/*")
@["full/foo"]
repl:3:> (sh/glob "empty/*")
@["empty/*"]
repl:4:>
Instead of returning an empty array, a glob wildcard inside of an empty directory returns a string of the wildcard itself.
Hi,
I met exit code 127 error while running below script. Do you know what could be
the problem and how to fix it?
#!/usr/bin/env janet
(use sh)
($ echo "hello")
./hello.janet
error: command(s) (@[echo "hello"]) failed, exit code(s) @[127]
in $* [/remote/vgsource10/jianmin/opt/janet/lib/janet/sh.janet] on line 255, column 5
in _thunk [./hello.janet] (tailcall) on line 5, column 1
Regarding the env, it is a local installed janet and jpm and its setup is like
git clone https://github.com/janet-lang/janet
cd janet
export PREFIX=$HOME/opt/janet
make CC=/path/to/gcc/9.2.0
make install
make test
make install-jpm-git
export PATH=$HOME/opt/janet/bin:$PATH
jpm install sh
Hey @andrewchambers, it would be nice if running something unidentified command will return stdout or stderr instead of erroring out. In my case I tried running a command line tool that wasn't installed, I'd like to have stderr with command not found:
rather that erroring out No such file or directory
Thanks
One really good thing about this module is that it makes it easy to farm out already-implemented tasks to shell commands. There is an issue, though, which is that there is a limit on how long the argument list can be, so if you try to echo
a long string to pipe it into another command, it throws an error: spawn failed: "Argument list too long".
I think it would be a great addition to the module to allow piping input into the shell command from a string within janet. Maybe the syntax could be something like this:
(def really-long-string "...")
(sh/$< [stdin really-long-string] | cat)
$ jpm install https://github.com/andrewchambers/janet-sh.git\
...
$ janet
janet:1:> (import sh)
Results in
error: could not load native /usr/local/Cellar/janet/1.9.0/lib/janet/_jmod_posix_spawn.so: dlopen(/usr/local/Cellar/janet/1.9.0/lib/janet/_jmod_posix_spawn.so, 2): Symbol not found: _pipe2
Referenced from: /usr/local/Cellar/janet/1.9.0/lib/janet/_jmod_posix_spawn.so
Expected in: flat namespace
in /usr/local/Cellar/janet/1.9.0/lib/janet/_jmod_posix_spawn.so
in native
in <anonymous> [boot.janet] on line 2257, column 26
in require [boot.janet] on line 2279, column 18
in import* [boot.janet] on line 2291, column 15
in _thunk [/usr/local/Cellar/janet/1.9.0/lib/janet/posix-spawn.janet] (tailcall) on line 1, column 1
compile error: unknown symbol _posix-spawn/POSIX_SPAWN_SETSIGMASK on line 3, column 1 while compiling /usr/local/Cellar/janet/1.9.0/lib/janet/posix-spawn.janet
compile error: unknown symbol _posix-spawn/POSIX_SPAWN_SETSIGDEF on line 4, column 1 while compiling /usr/local/Cellar/janet/1.9.0/lib/janet/posix-spawn.janet
compile error: unknown symbol _posix-spawn/POSIX_SPAWN_RESETIDS on line 5, column 1 while compiling /usr/local/Cellar/janet/1.9.0/lib/janet/posix-spawn.janet
error: (macro) unknown symbol POSIX_SPAWN_SETSIGMASK on line 35, column 5 while compiling /usr/local/Cellar/janet/1.9.0/lib/janet/posix-spawn.janet
in eval [boot.janet] on line 2066, column 5
compile error: unknown symbol spawn2 on line 89, column 3 while compiling /usr/local/Cellar/janet/1.9.0/lib/janet/posix-spawn.janet
compile error: unknown symbol _posix-spawn/wait on line 94, column 3 while compiling /usr/local/Cellar/janet/1.9.0/lib/janet/posix-spawn.janet
compile error: unknown symbol wait on line 99, column 3 while compiling /usr/local/Cellar/janet/1.9.0/lib/janet/posix-spawn.janet
compile error: unknown symbol wait on line 104, column 3 while compiling /usr/local/Cellar/janet/1.9.0/lib/janet/posix-spawn.janet
compile error: unknown symbol _posix-spawn/close on line 109, column 3 while compiling /usr/local/Cellar/janet/1.9.0/lib/janet/posix-spawn.janet
compile error: unknown symbol _posix-spawn/pipe on line 114, column 3 while compiling /usr/local/Cellar/janet/1.9.0/lib/janet/posix-spawn.janet
compile error: unknown symbol posix-spawn/pipe on line 83, column 16 while compiling /usr/local/Cellar/janet/1.9.0/lib/janet/sh.janet
compile error: unknown symbol run* on line 202, column 3 while compiling /usr/local/Cellar/janet/1.9.0/lib/janet/sh.janet
compile error: unknown symbol run* on line 206, column 13 while compiling /usr/local/Cellar/janet/1.9.0/lib/janet/sh.janet
compile error: unknown symbol $?* on line 212, column 3 while compiling /usr/local/Cellar/janet/1.9.0/lib/janet/sh.janet
compile error: unknown symbol run* on line 218, column 13 while compiling /usr/local/Cellar/janet/1.9.0/lib/janet/sh.janet
compile error: unknown symbol $* on line 226, column 3 while compiling /usr/local/Cellar/janet/1.9.0/lib/janet/sh.janet
compile error: unknown symbol run* on line 231, column 13 while compiling /usr/local/Cellar/janet/1.9.0/lib/janet/sh.janet
compile error: unknown symbol $<* on line 239, column 3 while compiling /usr/local/Cellar/janet/1.9.0/lib/janet/sh.janet
compile error: unknown symbol run* on line 244, column 13 while compiling /usr/local/Cellar/janet/1.9.0/lib/janet/sh.janet
compile error: unknown symbol $<_* on line 262, column 3 while compiling /usr/local/Cellar/janet/1.9.0/lib/janet/sh.janet
Without documentation, it's hard to know that $$
takes extra arguments without perusing the code.
I don't know where :null
should be documented.
I would expect this to work, but it doesn't:
repl:1:> (use sh)
...
repl:2:> ($< sh -c `echo hi >&2` > [stderr stdout])
hi
""
(I know I can capture stderr by redirecting it to a buffer -- the $<
is just to demonstrate that it didn't actually do the thing.)
Is there a way to redirect stderr to stdout?
This doesn't work as expected (by me):
repl:8:> (sh/$ echo $PWD)
$PWD
It behaves like echo '$PWD'
. How can I run an echo "$PWD"
?
Hi! I'm new to both janet and janet-sh. Why doesn't the following command work?
repl:2:> (sh/$ cd /tmp)
error: spawn failed: "No such file or directory"
in posix-spawn/spawn
in spawn2 [/usr/lib/janet/posix-spawn.janet] on line 36, column 3
in spawn-spec [/usr/lib/janet/sh.janet] on line 152, column 23
in <anonymous> [/usr/lib/janet/sh.janet] on line 157, column 9
in <anonymous> [/usr/lib/janet/sh.janet] on line 155, column 5
in run* [/usr/lib/janet/sh.janet] on line 154, column 3
in $* [/usr/lib/janet/sh.janet] on line 253, column 13
in _thunk [repl] (tailcall) on line 2, column 1
Hi! I apologize if this is a really basic question or if it's been answered elsewhere, but I have so far been unable to find janet-sh documentation or any answer in Janet for Mortals. I'm in the process of learning Janet and trying to use janet-sh as an alternate to some of my more simple shell scripts. My understanding is that the
For example, running git rev-parse --is-inside-work-tree
from a normal shell will return "true" if the current directory is inside of a git worktree or repo, but it will give an error if it's not.
Within janet-sh, I'm trying this:
(use sh)
(def errput @"")
(def output ($< git rev-parse --is-inside-work-tree >, [stderr errput]))
(prin output)
(prin errput)
Running it outside of a git repo/worktree, it's giving this error:
error: command(s) (@[git rev-parse --is-inside-work-tree :> (<core/file 0x600003B7C620> @"fatal: not a git repository (or
any parent up to mount point /Volumes)\nStopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not
set).\n")]) failed, exit code(s) @[128]
in $<* [/opt/homebrew/Cellar/janet/1.27.0/lib/janet/sh.janet] on line 282, column 5
in _thunk [./devel/_git_inarepo] (tailcall) on line 57, column 13
I did see #17 but since I'm not trying to send stderr to stdout, I wasn't sure that it was applicable.
I don't want the Janet script to fail when running the shell command, but I'm not sure what I'm supposed to do. Can anyone point me in the right direction? Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.