Closed vviikk closed 3 years ago
Makes sense
try xargs though
meta exec "pwd | xargs basename | xargs echo"
for venv
meta exec "pwd | xargs basename | xargs python3 -m venv .venv --prompt"
For example:
meta exec "pwd | xargs basename | xargs python3 -m venv .venv --prompt" --include-only=plugins/meta-loop
What manner of sorcery is this? And why does this work lol?!
You were having trouble with when the expression is run - the command pwd
always worked directly.
Seems that when you use in as an expression, wrapped in ` or $(), it gets evaluated before being executed in each directory.
So, in this example, pwd
returns the directory path.. then it is piped to xargs
which, as a simple explanation, basically puts it as an argument to the given command..
basename gets the directory name, and the result of that is piped to the next xargs command.
I didn't try this before, but escaping the `'s also works:
➜ meta exec "echo `pwd`" --include-only=plugins/meta-loop
plugins/meta-loop:
/Users/patrickleet/dev/mateodelnorte/meta
plugins/meta-loop ✓
➜ meta exec "echo \`pwd\`" --include-only=plugins/meta-loop
plugins/meta-loop:
/Users/patrickleet/dev/mateodelnorte/meta/plugins/meta-loop
plugins/meta-loop ✓
➜ meta exec "echo \$(pwd)" --include-only=plugins/meta-loop
plugins/meta-loop:
/Users/patrickleet/dev/mateodelnorte/meta/plugins/meta-loop
plugins/meta-loop ✓
I added a note to the README: https://github.com/mateodelnorte/meta#how-to-escape-expressions
Legend, thanks.
🚀 Feature Proposal
Have things like current folder name (just the name, not the full path) as an environment variable you can use in commands
Motivation
Take this for example. I have three repos (two python repos & one node)
And I run the following command:
The context or current working directory is still where I ran the command from. It would be good to have access to such things when running meta-exec. But I don't know if this should be in loop or meta-exec. An environment variable like
META_CWD
. See example below.Example
Say I want to create virtual environments for all my python projects with just the folder name as the venv name.
Currently there is no easy way to do this so I just manually create my virtual environments. Hope I am making sense.