14 ms·
Closh – Bash-like shell based on Clojure
- setzer22 9y agoI've been meaning to implement something like this for a while, but couldn't find the time to do it. It is nice to know that it's already done! I'm going to check it out.
- kloud 9y agoAuthor here, thanks for posting. The project is still very early in the development and there is a lot of work to be done to make it ready for daily use. I would appreciate any feedback. What are the less known features of existing shells you really like? What things would you change about existing shells if you could?
- wolfgang42 9y agoYou may also be interested in looking at https://www.oilshell.org/ https://www.oilshell.org/ . Like yours, it's an effort to make a 'better bash', and he has a lot of posts discussing various aspects of Bash syntax and shells in general, and how to improve them.
- kloud 9y agoYeah, Oil shell is great. I got a lot of inspiration and learn how things work by reading those posts. I try to tackle it by a different approch by leveraging Clojure syntax for the programming bits but keeping things compatible for the command execution uses.
- dahart 9y agoAwesome project, and absolutely well motivated. I would love a shell that improves on bash with sane syntax. I'd suggest swapping stage 3 and stage 2 -- environment vars and signal and job control are more important (IMO) than everything in stage 2, and may affect the syntax more as well.
- setzer22 9y agoIs there a way I can automatically import libraries? Also, what's the current status on autocompletion features? By the way, very nice work!
- kloud 9y agoYou can use node libraries by requiring them with (js/require). ClojureScript libraries are in theory possible too, but I need to figure out how to specify classpath options for them. Check out the example: https://github.com/dundalek/closh/blob/master/doc/guide.md#custom-prompt https://github.com/dundalek/closh/blob/master/doc/guide.md#c...
- encloser 9y agoI really like this idea and I really like Clojure. Though I'm curious about performance. And do you know if anyone is doing something similar with Racket? (Looks like there is a Common Lisp shell http://www.cliki.net/CLISP-Shell http://www.cliki.net/CLISP-Shell)
- fiddlerwoaroof 9y agoThere is also the scheme shell: https://scsh.net https://scsh.net
- patrickmay 9y agoThe shell with the best acknowledgements section in any technical manual: https://scsh.net/docu/html/man.html https://scsh.net/docu/html/man.html
- peatmoss 9y agoAt RacketCon this year, there was a presentation on something called “Rash”: http://docs.racket-lang.org/rash/index.html http://docs.racket-lang.org/rash/index.html
- lvh 9y agoeshell is another lispy shell that's been in Emacs for a very long time. Elisp is probably my least favorite lisp that's commonly available, but eshell probably has the largest user base and is certainly the most mature out of all of these contenders. You can reasonably use eshell as your primary shell.
- anonacct37 9y agoI use eshell daily. It's nice to have a shell that also integrates with with list, but there's also a ton of value-add with integration with the emacs ecosystem. For example in eshell you can do: cd /ssh:some-server:/ top cd /docker:container:/ find-file etc/hosts
- rrix2 9y ago
- robto 9y agoOne thing that would be killer in a cljs shell is some sort of paredit capability. I've been writing clojure long enough with good tools that when I have to use it in an environment without paredit it slows me down a ton. This looks great, though, and I can't wait to try it out.
- contingencies 9y agoThe roadmap seems well thought out. Perhaps linking each unfinished item to a summary Github issue explaining how you see it being approached would assist with gaining contributors. You could then keep a list of "where to jump in" by assigning that sort of issue a tag ("start-hacking-here" or some such).
- doxos 9y agoA reader macro for embedding shell commands within clojure forms would be interesting. Something like: (let [x #sh ls] (pprint x)) Or some kind of way to embed shell execution directly in the form...
- sandover 9y agoI think this kind of shell has the best features of something like PowerShell -- the ability to work with real data structures -- but combined with Clojure's opinionated minimalism about those data structures, the result seems more useful. One other thing that Clojure has, however, which may be a problem here, is a strong emphasis on precise namespacing. That seems a like a serious problem for day to day use of this kind of shell. Pedantically namespacing all the interesting library functions I want to use would get old fast.
- hssay 9y agoThanks for the amazing work! This is a project that many would look forward too. Shell is a place where Clojure's program to abstractions and data oriented programming philosophy can do wonders. Ability to browse documentation of Clojure functions at the shell might help. Currently, man pages can be accessed for utilities. But quickly browsing doc of, say, Clojure re-find will add value, although features from stage 2 and 3 of roadmap are more important/show-stoppers.
- nailer 9y ago> Why try to reinvent bash? > ... > It treats everything as text while we mostly need to manipulate structured information. Looking at the examples given, it's more like Powershell, but with better compatibility with existing Unix text-based tools. Which is awesome.
- pandalicious 9y agoIt seems like the concepts are orthogonal though. The reason powershell works is that it replaced the entire shell toolchain with object-oriented equivalents. Without that you're fundamentally limited because your inputs are still plain text, so you're still doing the equivalent of awk/sed scripts to transform text into structured data.
- nailer 9y agoAgreed, you're still scraping, but being familiar to people used to scraping is a decent way to convert those people into using structured data.
- zokier 9y agoThat aligns pretty much with my conclusion that to make an useful object shell, I'd be essentially rewriting the whole userland and probably some kernel bits too (/proc and /sys etc). So basically building a completely new OS on top of Linux kernel. I wouldn't expect such project to be very popular..
- amyjess 9y agoFor quite a while now, I've fantasized about creating an object-oriented toy OS with an OO shell and something akin to Classic Mac OS's resource forks. As much information as possible would be stored as OO data structures in alternate file streams with native tooling to query them. It would need to be based on Illumos and not Linux, though... IIRC, the only existing open-source filesystem that supports anything akin to a resource fork is ZFS, and the Linux kernel doesn't have the syscalls readily access it (ZFS implements extended attributes as forks, but the kernel has really tight limitations on what can be done with xattrs, much tighter than what ZFS can do). It's just a fantasy, though, and not something I have the skills or the time to do.
- spot 9y agoanother lisp shell: https://scsh.net/ https://scsh.net/
- deleted 9y ago[deleted]
- zeveb 9y agoscsh is awesome, although I don't believe it was intended to be used interactively. eshell[0] is another one. Has a few warts, but is generally pretty cool. Someday I'd like to write one in Common Lisp. Just haven't gotten a round tuit yet. [0] https://www.gnu.org/software/emacs/manual/html_mono/eshell.html https://www.gnu.org/software/emacs/manual/html_mono/eshell.h...
- cat199 9y agoScsh runs in a modified scheme48 repl - no problems with interactive use, though I've not run it as an actual login shell, though perportedly that works
- zeveb 9y agoI mean more that it's not ergonomic for interactive use. Typing: (run/string (| (ps aux) (grep foo) (grep -v grep)) is quite a bit more of a pain than: ps aux | grep foo | grep -v grep Or at least I think so. It's really meant for providing a nice Lispy interface to POSIX, and at that I believe it succeeds.
- cat199 9y agoAh sure. But for those cases you can always drop to a normal session with: (run sh) again.. haven't ever used as login shell though :)
- LesZedCB 9y ago> npm install -g lumo-cljs closh why? seriously, is this the point that modern tooling has gotten to where for no apparent reason it has a node dependency?
- mbrock 9y agoNode is the runtime for ClojureScript. The whole shell runs in Node.
- LesZedCB 9y agowhat's the tradeoff of clojurescript over native clojure? wouldn't the java clojure runtime be much faster?
- lvh 9y agoSteady-state performance tends to be better on the JVM but startup performance is always much better on top of JavaScript. That makes it an enticing trade off for shells which is a process that you start new ones of constantly and where the performance of the shell itself is often not very important. (Performance-critical or hard-to-duplicate code like, say, line editing code, can be done equally well on either platform via FFI.)
- earenndil 9y agoWhy not just make a server that starts up once in the background and then a lightweight c frontend to the server that essentially just pipes every keystroke to the server?
- cben 9y agoShells are supposed to inherit a ton of state from their parent — [e]uid, groups, working dir, env vars, nice, umask, chroot, ... This takes zero effort in unix, but would all have to be (securely!) re-implemented to be able to send code to a shared execution daemon... And I expect the right implementation for many of these params will be running separate daemons anyway (eg. you clearly want one per user).
- justinhj 9y agoThere is also a Scala repl and scripting tool http://ammonite.io/ http://ammonite.io/
- alvatar 9y agoVery cool! I use Clojure on a daily basis for coding, this is a great addition to the arsenal :) Actually, my main argument against _not using it_ is that Bash has this awkward syntax that is hard to remember if you don't use it often... But anyway, I keep forgetting it after years so I might as well embrace it and take the leap to use this. Thanks for the initiative!
- kloud 9y agoThanks, exactly!
- dmix 9y agoNice, I've been waiting for a good modern shell to replace ZSH. Fish just wasn't enough of an improvement for me to abandon ZSH. This is an area where most open-source developers have avoided, as it's a "solved" problem, but it really isn't. I'm currently waiting on Elvish [1] to mature. It's written in Go [2], but they're developing a new language on top of it for shell scripting, which I tried for a week. It's a nice modernization and is incredibly fast but still very alpha. You don't realize how slow ZSH/Bash is (even without plugins) until you try a modern shell, and there are very few good modern shells around. Besides performance my primary complaint is just how awful coding in ZSH is. I've been doing it for years and I still feel like I'm running into walls constantly and struggling to write 'clean' code that isn't full of hacks and workarounds. High performance + modern scripting language = my ideal future shell [1] https://elvish.io/ https://elvish.io/ [2] https://github.com/elves/elvish https://github.com/elves/elvish
- slowmovintarget 9y agoRash? Rust Already SHell (There's already a "RuSH" made with Ruby). Oh. https://github.com/redox-os/ion https://github.com/redox-os/ion CLASH - Common Lisp Again SHell? Oh. http://www.cliki.net/CLISP-Shell http://www.cliki.net/CLISP-Shell Doh! https://docs.racket-lang.org/rash/index.html https://docs.racket-lang.org/rash/index.html Someone put OO in my Linux shell! https://virtualizationreview.com/articles/2017/06/01/how-to-install-and-use-powershell-and-powercli-on-linux.aspx https://virtualizationreview.com/articles/2017/06/01/how-to-...
- work_account 9y agoThere's also "oh shell", written in Go but exposing a Scheme-like language: https://github.com/michaelmacinnis/oh https://github.com/michaelmacinnis/oh
- masukomi 9y agoor you could go with SCSH, an actual scheme shell: https://scsh.net/ https://scsh.net/
- 9y ago
- DigitalJack 9y agoThis is fantastic. Reminds me of the apple //e days with a shell that was also a BASIC interpreter.
- cies 9y agoCall me old. But I want my shell to be a tight binary, preferably distributed (at some point) by major distros. This needs freakin' Node.js. I'm more looking in the Rust/Haskell/OCaml direction for a hip bash/zsh replacement.
- cies 9y agoLooking back, I'd like to add Go to the list. (Not that I consider it hip, probably the least hip on the list. But well suited for writing a shell I guess.)
- gigavinyl 9y agoCouldn't agree more with you on that one. Hell, even common lisp on sbcl would be better.
- baldfat 9y agoRacket's RaSH is heading there. I have to say I have been using BASH, SED and AWK less. They are great tools but in the end it is getting easier and easier to get things done with a Macro in Racket for me.
- sillysaurus3 9y agoThis needs freakin' Node.js. Yeah, that's an old sentiment. I used to echo the same thing, but it's worth coming to terms with the fact that node is a pretty good platform to build on.
- raspasov 9y agoWhat a neat idea! Good work!
- mindB 9y agoAlso worth checking out is xonsh [0]. It has a similar goal but with python as the sh alternative instead of Clojure. [0] http://xon.sh http://xon.sh
- disease 9y agoLooking forward to the day I can write backend code in clojure, frontend code in clojurescript, write all my terminal commands in clojure and use an IDE that is configurable via clojure code.
- elsurudo 9y agoWhich of these are missing right now? Is there a decent backend framework in Clojure?
- KingMob 9y agoIdeally, we want a Symbolics Clojure Machine.
- yellowapple 9y agoI suspect that a hardware JVM implementation would get you halfway there.
- pjmlp 9y agoThere are still a few chipset companies selling CPUs with support for JVM bytecode. As alternative, if one is feeling bored, why not create an FPGA for it? :)
- hssay 9y agoYup. This is the holy grail!
- ythn 9y agoIs there a bash-like shell based on Python? I would love something like that.
- floatboth 9y agoxonsh
- hssay 9y agoipython shell with its magic commands is pretty powerful, although not a bash replacement. For example, you can assign output of ls command to a variable (e.g. a = !ls) and then use that variable as a python list. Good overview of its power here: https://jakevdp.github.io/PythonDataScienceHandbook/01.00-ipython-beyond-normal-python.html https://jakevdp.github.io/PythonDataScienceHandbook/01.00-ip...
- huntie 9y agoThis is interesting, but I feel that making shell support such a first-class citizen is a mistake. Shell languages basically treat system binaries as functions, which causes you to lose a lot of power with everything being a string. Using system binaries (cat, echo, etc.) isn't really necessary for a modern command language due to the ubiquity of scripting languages and module systems. It's much more powerful to write procedures that work with structured data to perform similar actions. One of the things that Shells have gotten right is postfix function composition (the | operator). This allows you to very easily compose functions to perform complex operations, and this isn't really present in scripting languages. Haskell let's you do this with the `&` operator, and you can write a procedure for Scheme that performs similarly. I'm not sure how this would work with Python or JS. I'm hoping that in the next few years we'll see a larger break from shell syntax. The biggest thing I think holding this back is REPLs. Most scripting languages would do fine as a shell replacement with the addition of a stdlib for the purpose, but they need support for navigating the file system. Maybe tab-completion for paths like Bash does would be best, but I'm still thinking about it.
- aaron-lebo 9y ago> I'm not sure how this would work with Python or JS. .method().method()?
- yoavm 9y agoI think the concept of piping is actually more similar to function(function()) than .method().method(), because you're not limited to the scope of your initial object's methods. And the truth is that functionB(functionA()) reads much worse than functionA | functionB , so yeah I agree that this is something that shell scripting languages got right.
- yellowapple 9y agoFor reference, various functional languages do indeed treat something like 'foo |> bar' as equivalent to 'bar(foo)' (I've used this extensively in Elixir, where it's standard practice; I'm pretty sure this is derived from F# and/or Clojure, both of which - IIRC - use the same operator for the same purpose). It's not really perfect parity with what a shell typically offers, though, since a shell's pipeline steps (usually) run in parallel and indefinitely, consuming an input stream and producing an output stream (whether those streams are text, rich objects, audio/video data, or something else entirely). Elixir/Erlang are well-suited to achieving that parity by spinning up processes and using message passing for I/O, but Elixir's pipeline operator doesn't really do that (last I checked).
- ridiculous_fish 9y agoOne of the tricky things about shells is the interaction between fork and pthreads. For example, if you fork while another thread holds a lock, you risk deadlock. node uses pthreads for certain asynchronous operations like stat(). How does Closh handle forking when there are multiple threads?
- kloud 9y agoJS is single-threaded by design and node encourages use of asynchronous operations and then runs callbacks on the event loop. Node provides higher-level non-blocking function spawn, so closh currently does not need to do forking directly. I hope this can get us far before the need to drop into lower level and start dealing with threads. I am curious, what does fish use threads for and how does it handle them?