- Notifications
You must be signed in to change notification settings - Fork3
DannyBen/opcode
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Opcode lets you define a simple configuration file in any directory.This file includes shortcuts to other commands.
For a similar project, but for globally accessible aliases, seealf.
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 theop file,place it somewhere in your path, and make it executable.
When you executeop
, Opcode will look for a file namedop.conf
(or opcode)in the current directory. See theexample/op.conf filefor reference.
The syntax ofop.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 withthis configuration:
commit: git commit -am
You can supply a commit message:
$ op commit"my commit message"
$ op --helpUsage: op CODE [ARGS] Execute a command from the config file (op.conf) Arguments will be passed to the command (use with "$@") op ?, -i, --info 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
In order to specify multiple commands for a single code, provide the commandsindented with one or more spaces immediately under the command code:
up: docker compose build docker compose up web
The commands will be joined together using a newline, as they appear in yourfile.
Any excess argument provided when runningop CODE
will be available to youas they normally would in a bash script. You can access all of them by using$@
, or the individual arguments at$1
,$2
etc.
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
You may add special usage comments in yourop.conf
file. These will bedisplayed alongside their command code when runningop ?
. The usage commentsmust start with#?
and be placed underneath their associated command.
For example, this configuration file:
# op.confdeploy: git commit -am"$1"&& git push#? perform git commit and push.#? usage: op deploy COMMIT_MESSAGEpull: git pull#? perform git pull
will result in this output:
$ op ?Usage: op COMMAND [ARGS] deploy perform git commit and push. usage: op deploy COMMIT_MESSAGE pull perform git pull
Any comment that starts with##
will be considered a section header, and willbe displayed as such when runningop ?
.
For example, this configuration file:
# op.conf## Testing Commandstest: rspec"$@"#? Run tests## Git Commandspull: git pull#? Perform git pull
will result in this output:
$ op?Usage: op COMMAND [ARGS]Testing Commandstest Run testsGit Commands pull Perform git pull
Using the keywordprivate
in a separate line anywhere in yourop.conf
filewill hide all subsequent commands fromop ?
andop --list
. The privatecommands can still be executed.
deploy: op clean&& op buildtest: docker compose runtestprivateclean: rm tmp/*build: docker build
When running a command, opcode will first try to find an exact match. If noneis found, it will try to find a command that starts with the code you typed.
In other words, if you have this in yourop.conf
file:
server:echo"Running Server"&& rackup
You can run it withop server
,op s
and anything in between. The firstmatched command will be executed.
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
$ curl -Ls get.dannyb.co/opcode/uninstall| bash
If you experience any issue, have a question or a suggestion, or if you wishto contribute, feel free toopen an issue.
About
Local Command Shortcuts