I looked for this in other questions but can't seem to find anything similar. Yet, this seems quite useful thing.
I want to set up a ZSH snippet/alias for my git add .
so that it does three jobs in a chain:
- if path
./readme.md
exists, run doctoc (globally installed CLI app from npm) on it. If it doesn't, do nothing and skip to next step. - if path
./changelog.md
exists, run a different local CLI installed script on it (let's say calledchangelogupd
). If it doesn't, do nothing and skip to next step. - no matter the previous outcomes, then run
git add .
Now currently, I have two commands chained in .zshrc
alias like this and it works:
path-exists ./readme.md && doctoc readme.md && git add . || git add .
But I want three: two path checks and conditional calls plus git add .
By the way. the path-exists
is path-exists-cli, globally installed via npm.
Three command chain seems tricky, below is a nonsensical mash to show the rough thing I'm looking for:
path-exists ./readme.md && doctoc readme.md && git add . || path-exists ./changelog.md && changelogupd changelog.md && git add . || git add .
Should I try to cover all four cases using double pipes:
(
readme
present, nochangelog
, plusgit add .
readme
not present, nochangelog
, plusgit add .
- both
readme
andchangelog
present, plusgit add .
- no
readme
butchangelog
present, plusgit add .
)
or is there an easier way (or an npm CLI library or some secret terminal command)?
This is to be ran on a Mac terminal by the way. Thank you.
A || B
is to runB
only ifA
fails, which doesn't seem to be what you're looking for here, so any construction using||
will be messy. Unless you have a really good reason to not do so, just write separate commands (with a newline or semicolon in between)