6 ms·
Tangential: I would love to see more interpreted languages offer shells with native constructs for operating as daily drivers shells (not just REPLs). When I f
by saysjonathan 4mo ago
Tangential:
I would love to see more interpreted languages offer shells with native constructs for operating as daily drivers shells (not just REPLs). When I first started learning Ruby I used `rush`[0] as my main shell. Being immersed in the language, even if there were a few helpers for shell operations, really helped me reason better about Ruby and think in the language. `scsh`[1] was enlightening as well. Ultimately the ergonomics of both pushed me back to more conventional variant but they were really helpful learning mechanisms.
0: https://github.com/adamwiggins/rush https://github.com/adamwiggins/rush
1: https://github.com/scheme/scsh https://github.com/scheme/scsh
- twic 4mo agoNot sure if this is related, but i'd love to see more scripting languages (mostly Python) offer facilities which let them take over from shell script for more scripts and one-liners. Think about what it would take to write this in Python right now: for wmv_file in $(find $1 -name '*.wmv'); do echo -n "${wmv_file} " ffmpeg -i $wmv_file ${wmv_file%.wmv}.mpg 2>&1 | grep kb/s: || echo "ERROR $?" done With a few handy variables and functions predefined, this could be something like: for wmv_file in find(argv[1], glob="\*.wmv"): print(wmv_file, end=" ") result = do("ffmpeg", "-i", wmv_file, basename(wmv_file, ".wmv") + ".mpg") if result: print(grep(str(result), "kb/s:")) else: print("ERROR", result.status)
- dmd 4mo agohave you seen https://sh.readthedocs.io/en/latest/ https://sh.readthedocs.io/en/latest/
- yesbabyyes 4mo agoI think Perl is what you're looking for!
- twic 4mo agoPerl is what I've spent the last thirty years running away from.
- MarsIronPI 4mo agoRuby does a pretty good job, with `system` and backticks. The FileUtils module actually defines some nice helpers like `mv`, `cp` and `ln_s`. So you can do `cp "/tmp/a.txt", filename`. And you can get a list of files matching a glob with `Dir["/tmp/*.txt"]`.
- deleted 4mo ago[deleted]
- empthought 4mo agoHow about for wmv in Path(sys.argv[1]).rglob("\*.wmv"): print(wmv, end=" ") r = subprocess.run( ["ffmpeg", "-i", wmv, wmv.with_suffix(".mpg")], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, ) lines = [l for l in r.stdout.decode().splitlines() if "kb/s:" in l] print("\n".join(lines) if lines else f"ERROR {r.returncode}") ? If you go outside stdlib you can use the sh library instead of subprocess.run.
- twic 4mo agoNot bad, but the subprocess invocation is too verbose given this is a staple of shell script type work, and the string mangling is a bit painful.