opcode icon indicating copy to clipboard operation
opcode copied to clipboard

Ability to create variables to use in commands

Open robwilde opened this issue 4 years ago • 6 comments

First, big thanks to awesome tool.

I have been using Alf for a while, which is also awesome, and wanted to use opcode for a project that is shared.

Would it be difficult to add similar function from Alf where you can use commands in commands? As an idea, being able to create a command that starts with $ so I can call that from another command. like...

$dbash: docker compose exec web_local bash -c

php-info: $dbash "php -i"
php-version: $dbash "php -v"
php-modules: $dbash "php -m"

thanks again :)

robwilde avatar Feb 24 '22 12:02 robwilde

Both an alf an opcode user, nice! Happy you find them useful.

How about this:

# op.conf
display1: echo "--- $@ ---"
display2: echo 

greet1: op display1 Hello World
greet2: op display2 Hello "$1", and welcome!

then we can run:

$ op greet1
--- Hello World ---

$ op greet1 Bob
--- Hello World Bob ---

$ op greet2 Bob
Hello Bob, and welcome!

So your example can be written as:

dbash: docker compose exec web_local bash -c

php-info: op dbash "php -i"
php-version: op dbash "php -v"
php-modules: op dbash "php -m"

Not sufficient?

DannyBen avatar Feb 24 '22 12:02 DannyBen

That is actually a format I tried to use, thinking along the lines of Alf. If that could work in opcode that would work very well.

I would have worked on the solution myself but bash scripting, I am sorry to say, is something on my list of languages to learn.

Thanks again :)

robwilde avatar Feb 24 '22 23:02 robwilde

I think you misunderstood me. This is already implemented in opcode right now.

DannyBen avatar Feb 25 '22 00:02 DannyBen

Oh OK I will try that again. I didn't think that was working but most likely something I did.

robwilde avatar Feb 26 '22 15:02 robwilde

Did some more testing and it does not appear to work with docker compose commands as expected.

testing using command to get php version from container php-version: docker compose exec dms_web_local bash -c "php -v"

create a command for docker compose part like so: dbshrc: docker compose exec dms_web_local bash -c

shorten command: php-version: dbshrc "php -v"

returns: /usr/local/bin/op: line 89: dbshrc: command not found -- I realised after I missed the op command

Doing this in Alf I use $* in a few places to allow for multiple inputs, seems to work pretty well their

I found that what works is dbshrc: docker compose exec dms_web_local bash -c "$*" php-v: op dbshrc php -v

when using the short-hand version I need to drop the "" and everything is great :)

thought I would share what I found. thanks again for your help

robwilde avatar Feb 27 '22 08:02 robwilde

You do not have to append "$*" to any command, it is appended by default unless you have any other "$" in the command (see here).

Anyways, happy it is working.

DannyBen avatar Feb 27 '22 08:02 DannyBen