I would consider myself an expert or at least near-expert in python, but I don't see opportunities to replace my shell scripts with python popping up left and right. Do you open files manually and set up pipe chains with subprocess.Popen? I've done this, and its generally many more LOC compared to the shell original, and harder to read.
On the other hand, I'd consider myself maybe 7/10 skill level with bash, but most developers are only ever a 2/10 or 3/10 with bash/shell. I can't help but think that the average developer's lack of shell understanding is where all these suggestions to convert to python come from. If it's that easy or beneficial to convert to python, then it probably should have been written in python originally.
When you use regexes, letting python use them directly seems to be much cleaner than quoting and passing them to awk/sed/grep or other text processing tools.
Additionally, python seems to have libraries to handle all kinds of input like json and csv.
One thing that python doesn't do as naturally as bash is invoke commands. For python I usually include some functions to run commands passed as a list, and check the return code or return the output. then 'cmd -f $arg1' becomes myrun('cmd','-f', arg1)
import sh
names = sh.ls("./src")
for name in names:
sh.mv(["./src/" + name, "./dst/" + name + ".out"])The main advantage of bash is that it exists on just about every unix machine.
Before Bun, Node+V8 was just too slow to start.
IMHO all scripts should be written in TypeScript...you get typechecking and all the rest of the editing experience. Plus things like Wallaby.js for live coding/testing.
My `.bashrc` now just runs a TypeScript script with Bun. Allows you to use proper structure instead of brittle spaghetti stuff. The number of times I'm debugging silly PATH stuff was too much...
import {alias, _export, _eval} from './util.js'
export default async function config() {
git()
}
function git() {
alias({
gpsuom: 'git push --set-upstream origin master',
gpsuvm: 'git push --set-upstream vjpr master',
gpsu: 'git push --set-upstream',
gmvd: 'git merge vjpr/dev',
gmvdgp: 'git merge vjpr/dev && git push',
gprom: 'git pull --rebase origin master',
gpuohm: 'git push origin head:master',
gpom: 'git pull origin master',
grhh: 'git reset --hard HEAD',
gisquash: 'git reset --soft HEAD~$(git rev-list --count HEAD ^master)',
gacp: "git add . && git commit --message 'Update' && git push",
gacmu: "git add . && git commit --message 'Update'",
gacmup: "git add . && git commit --message 'Update' && git push",
})
}
function brew() {
alias('bbrew', 'br')
alias({
br: 'HOMEBREW_NO_AUTO_UPDATE=1 brew',
// x86_64
ibrew: 'arch -x86_64 /usr/local/bin/brew',
abrew: '/opt/homebrew/bin/brew',
})
_eval(`$(/opt/homebrew/bin/brew shellenv)`)
}This is true for a number of languages that can also be run without AOT compilation (Go, Rust, etc). This feels like some really weird, incoherent astroturf take for Bun promotion.
Rust isn't a scripting language - too strict, no optional typing, slow compilation.