This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-08-17
Channels
- # announcements (7)
- # babashka (24)
- # beginners (11)
- # boot (16)
- # calva (46)
- # cider (5)
- # clara (3)
- # clj-kondo (2)
- # cljfx (5)
- # clojure (122)
- # clojure-brasil (26)
- # clojure-dev (20)
- # clojure-europe (20)
- # clojure-germany (1)
- # clojure-nl (1)
- # clojure-norway (54)
- # clojure-uk (2)
- # clojurescript (6)
- # core-matrix (23)
- # datomic (85)
- # graalvm (1)
- # honeysql (9)
- # hyperfiddle (31)
- # lsp (3)
- # malli (9)
- # nbb (2)
- # off-topic (15)
- # pathom (15)
- # pedestal (4)
- # polylith (5)
- # re-frame (5)
- # reitit (9)
- # releases (2)
- # shadow-cljs (63)
- # specter (4)
- # xtdb (7)
#!/usr/bin/env bb
# rempath
#
# Runs a command with a segment removed from PATH
#
# Usage:
#
# rempath path command [args ...]
#
# Example:
#
# rempath /usr/local/bin zsh
(let [needle (first *command-line-args*)
path (System/getenv "PATH")
segments (-> path (clojure.string/split #":"))
path (clojure.string/join ":" (remove #{needle} segments))]
(apply babashka.process/exec {:extra-env {"PATH" path}} (rest *command-line-args*)))
Nightmare to build in bash, easy as pie in bb
This hardly seems like the stuff of nightmares? :thinking_face:
(PATH=`echo $PATH | sed 's!/usr/local/bin:!!g'` zsh)
Maybe not a nightmare but also not exactly correct:
• doesn't work if /usr/local/bin
is the last segment
• will mess up /opt/usr/local/bin
• trouble afoot if PATH contains *
touch foo.txt; foo='f*'; echo $foo
foo.txt
Although the example at the start of this thread is longer, it is understandable, Although I am not sure about using path
twice in a let. Is clearly works, but looks strange to my eye.
The point is that it isn’t much work in shell either. If your argument is that you like to do all of your programming tasks in your favorite language, that’s perfectly reasonable, but let’s not exaggerate the difficulties of using other tools.
I think it's a significant amount of work and takes a lot of skill to do a task like this correctly in bash (it's easy in perl, python as well as bb)
I've used the shell for many years so it doesn't feel so terrible /alien to me. But that's less common these days and even for me, once it gets beyond 10 or so lines or there is anything non-line terminated text (eg JSON) involved, the shell starts to lose its appeal. (I think @U04V15CAJ uses something similar to these metrics when marketing bb) I think you found an example that's on the edge cos it's reasonable in the shell • at least as easy to compose / experiment than with bb • .. and yes you can use vi or emacs as a shell inline editor too, if that's needed and it's arguably more work in Clojure - but it depends on what you're most comfortable with.
I wouldn't have come up with the tr
example myself, without looking up the docs of tr and egrep, although I would have come up with the bb example without looking up any docs. 🤷
It's a matter of experience here. I guess people older than 50 are in favor of the tr solution :P