项目作者: DannyBen

项目描述 :
Local Command Shortcuts
高级语言: Shell
项目地址: git://github.com/DannyBen/opcode.git
创建时间: 2018-07-06T13:17:48Z
项目社区:https://github.com/DannyBen/opcode

开源协议:MIT License

下载





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

  1. $ 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:

  1. code: command to run

For example:

  1. commit: git commit -am "quick commit"

With this configuration, you can now simply run:

  1. $ op commit

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

  1. commit: git commit -am

You can supply a commit message:

  1. $ op commit "my commit message"

Additional Usage Utilities

  1. $ op --help
  2. Usage:
  3. op CODE [ARGS]
  4. Execute a command from the config file (op.conf)
  5. Arguments will be passed to the command (use with "$@")
  6. op ?, -i, --info
  7. Show all codes and their usage comments (#?)
  8. op -l, --list
  9. List command codes
  10. op -s, --show
  11. Show the config file (op.conf)
  12. op -w, --what [CODE]
  13. Show the command for a given code
  14. op -e, --edit
  15. Open the config file for editing
  16. op -a, --add CODE COMMAND...
  17. Append a command to the config file
  18. op -h, --help
  19. Show this message
  20. op -v, --version
  21. Show version number

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:

  1. up:
  2. docker compose build
  3. docker compose up web

The commands will be joined together using a newline, as they appear in your
file.

Positional Arguments

Any excess argument provided when running op CODE will be available to you
as 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:

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

You can now run:

  1. $ op deploy "version 1.1.1"

and it will be translated to this command

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

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:

  1. # op.conf
  2. deploy: git commit -am "$1" && git push
  3. #? perform git commit and push.
  4. #? usage: op deploy COMMIT_MESSAGE
  5. pull: git pull
  6. #? perform git pull

will result in this output:

  1. $ op ?
  2. Usage: op COMMAND [ARGS]
  3. deploy
  4. perform git commit and push.
  5. usage: op deploy COMMIT_MESSAGE
  6. pull
  7. perform git pull

Section Comments

Any comment that starts with ## will be considered a section header, and will
be displayed as such when running op ?.

For example, this configuration file:

  1. # op.conf
  2. ## Testing Commands
  3. test: rspec "$@"
  4. #? Run tests
  5. ## Git Commands
  6. pull: git pull
  7. #? Perform git pull

will result in this output:

  1. $ op ?
  2. Usage: op COMMAND [ARGS]
  3. Testing Commands
  4. test
  5. Run tests
  6. Git Commands
  7. pull
  8. Perform git pull

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.

  1. deploy: op clean && op build
  2. test: docker compose run test
  3. private
  4. clean: rm tmp/*
  5. 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:

  1. 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:

  1. complete -C 'op --completion' op

Uninstalling

  1. $ 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.