Skip to content

flawiddsouza/shortcommand

Repository files navigation

shortcommand

Easily run a set of commands quickly using a yaml configuration file

Usage

Create a yaml file named shortcommand.yml or anything you want. Here's an example:

shortcommands:
  - name: Journals
    commands:
      - name: ui
        description: Pull, build and deploy Web-UI
        cwd: ~/Apps/Journals/Web-UI
        do:
          - git pull
          - npm run build
      - name: api
        description: Pull, build and deploy API
        cwd: ~/Apps/Journals/API
        do:
          - git pull
          - shards build --release
          - pm2 restart "Journals API"
          - pm2 reset "Journals API"
  - name: QuickNote
    commands:
      - name: api
        description: Pull, build and deploy API
        cwd: ~/Apps/quick-note/API
        do:
          - git pull
          - pm2 restart "Quick Note API"
          - pm2 reset "Quick Note API"
      - name: restart-api
        description: Restart API in pm2
        do:
          - pm2 restart "Quick Note API"
          - pm2 reset "Quick Note API"

Then add this in your ~/.bashrc or ~/.zshrc:

export SHORTCOMMAND_CONFIG=/path/to/shortcommand.yml

Now if you run shortcommand without any arguments, you'll see this:

Available commands
Journals
  ui    Pull, build and deploy Web-UI
  api   Pull, build and deploy API
QuickNote
  api   Pull, build and deploy API
  restart-api   Restart API in pm2

Works as a readme for your command sets in case you forget what options are available for you to use.

Now the above defined short commands will be accessible and can be used by running:

shortcommand Journals ui
shortcommand Journals api
shortcommand QuickNote api
shortcommand QuickNote restart-api

Note: Commands mentioned under do: will execute in sequence and will not continue to the next one if the one that's running fails.

This project was created mainly because I have several apps that I run on my server and finding the right set of commands for deploying an app is a hassle. So this basically documents the set of commands for each of my projects, as well as gives me quick access to them.

Installing on Linux (tested on Ubuntu)

wget https://github.com/flawiddsouza/shortcommand/releases/download/v0.0.3/shortcommand_0.0.3_Linux_x86_64.tar.gz
tar -xf shortcommand_0.0.3_Linux_x86_64.tar.gz
mv shortcommand ~/.local/bin
rm shortcommand_0.0.3_Linux_x86_64.tar.gz

You should then be able to use the shortcommand command anywhere you are.

Testing

SHORTCOMMAND_CONFIG=shortcommands-example.yml go run . Test test
SHORTCOMMAND_CONFIG=shortcommands-example.yml go run . Test test2
SHORTCOMMAND_CONFIG=shortcommands-example.yml go run . Test test3

Build Testing

goreleaser build --snapshot --rm-dist

Build for release

go tag vX.X.X
git push origin vX.X.X
goreleaser release --rm-dist

About

Easily run a set of commands quickly using a global yaml configuration file

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages