Code Monkey home page Code Monkey logo

opcode's Introduction

Opcode - Local Command Shortcuts

Version Test


Opcode lets you define a simple configuration file in any directory. This file includes shortcuts to other commands.

Demo

For a similar project, but for globally accessible aliases, see alf.

Install

The simplest way to install, is to run the installation script:

$ curl -Ls get.dannyb.co/opcode/setup | bash

If you prefer to install manually, simply download the op file, place it somewhere in your path, and make it executable.

Usage

When you execute op, Opcode will look for a file named op.conf (or opcode) in the current directory. See the example/op.conf file for reference.

The syntax of op.conf is simple:

Each line should contain a code and the command to run:

code: command to run

For example:

commit: git commit -am "quick commit"

With this configuration, you can now simply run:

$ op commit

Any argument provided to the CLI will be forwarded to the command, so with this configuration:

commit: git commit -am

You can supply a commit message:

$ op commit "my commit message"

Additional Usage Utilities

$ op --help

Usage:
  op CODE [ARGS]
    Execute a command from the config file (op.conf)
    Arguments will be passed to the command

  op ?
    Show all codes and their usage comments (#?)

  op -l, --list
    List command codes

  op -s, --show
    Show the config file (op.conf)

  op -w, --what CODE
    Show the command for a given code

  op -e, --edit
    Open the config file for editing

  op -a, --add CODE COMMAND...
    Append a command to the config file

  op -h, --help
    Show this message

  op -v, --version
    Show version number

Positional Arguments

In some cases, you may want to use the command line arguments in different positions in your command. Given this configuration:

deploy: git commit -am "$1" && git push

You can now run:

$ op deploy "version 1.1.1"

and it will be translated to this command

git commit -am "version 1.1.1" && git push

This is made possible due to the fact that any command that contains a $ character, will not have the command line arguments ($@) appended to it.

Usage Comments

You may add special usage comments in your op.conf file. These will be displayed alongside their command code when running op ?. The usage comments must start with #? and be placed underneath their associated command.

For example, this configuration file:

# op.conf
deploy: git commit -am "$1" && git push
#? perform git commit and push.
#? usage: op deploy COMMIT_MESSAGE

pull: git pull
#? perform git pull

will result in this output:

$ op ?
deploy
  perform git commit and push.
  usage: op deploy COMMIT_MESSAGE

pull
  perform git pull

Multiline Commands

In order to specify multiple commands for a single code, provide the commands indented with one or more spaces immediately under the command code:

up:
  docker compose build
  docker compose up web

Note that these commands will be joined together with && - so the above will be converted to:

docker compose build && docker compose up web

Concatenated Lines

In case you wish to split your command to multiple lines without joining the lines with &&, you can add escape the newline by using \ (backslash):

concat: echo who \
  ordered \
  this \
  pizza

Using this syntax will generate this command:

echo who ordered this pizza

Private Commands

Using the keyword private in a separate line anywhere in your op.conf file will hide all subsequent commands from op ? and op --list. The private commands can still be executed.

deploy: op clean && op build
test: docker compose run test

private

clean: rm tmp/*
build: docker build

Partial Command Matching

When running a command, opcode will first try to find an exact match. If none is found, it will try to find a command that starts with the code you typed.

In other words, if you have this in your op.conf file:

server: echo "Running Server" && rackup

You can run it with op server, op s and anything in between. The first matched command will be executed.

Bash Completion

Opcode comes with bash completion. If you install opcode using the setup script, bash completion will be installed automatically.

If you install opcode manually, and would like to enable bash completion, simply add this to your ~/.bashrc:

complete -C 'op --completion' op

Uninstalling

$ curl -Ls get.dannyb.co/opcode/uninstall | bash

Contributing / Support

If you experience any issue, have a question or a suggestion, or if you wish to contribute, feel free to open an issue.


opcode's People

Contributors

dannyben avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

opcode's Issues

issue passing in docker compose options

currently have the following command for running in containers

dbashr: docker compose exec web_local bash -c

the default user in container is root
attempting to run commands in containers as the www-data user

dbash: docker compose exec --user www-data web_local bash -c
but this still runs as root. it appears the --user www-data is ignored or not added

also tried:
dbash: docker compose exec -u www-data dms_web_local bash -c
dbash: docker compose exec --user=www-data dms_web_local bash -c

all 3 of these commands do work in the same terminal on there own. Any ideas on how to make this work.
Thanks for any and all assistance.

Improve opcode help?

I wonder is it possible todo:

1.hide duplicate commands that i choose from
op ?
I put commands with aliases in op.conf

debug: ..
deb: op debug
deploy: ..
dep: op deploy

and I want to see only choosen commands with description #? .... - for example aliases to unclutter log commands list

2.Is there a way to remove from
op -s
comments
#? ....

I think op -s should contain full command list without help contrary to op ?

regards

howto set variables with commands?

I try to setup
debug: BASH_ENV=debug.sh ./app
and it not working
howto set variables with commands?

regards

I use bashly,opcode,rush keep up good work!

Allow private codes

Consider adding an ability to mark an opcode "private", so that it is not shown in any of the listing commands.

Possible use cases:

  1. Aliases (brought up in #24)
  2. Internal opcodes

Ability to create variables to use in commands

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 :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.