diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..c87f4a9 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +charset = utf-8 +end_of_line = lf +tab_width = 1 +indent_size = 4 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..69fc7c9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2023 Asim Tahir + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..7312d06 --- /dev/null +++ b/README.md @@ -0,0 +1,104 @@ + + + +### `docker-compose.fish` + +> `Docker Compose` plugin for [Oh My Fish][omf] and [Fisher][fisher], +> based loosely on the [Oh My Zsh][omz]'s [Docker Compose Plugin][omz-docker-compose-plugin] + +[![MIT License](https://img.shields.io/badge/license-MIT-007EC7.svg?style=flat-square)](/LICENSE) +[![Fish Shell v3.6.0](https://img.shields.io/badge/fish-v3.6.0-007EC7.svg?style=flat-square)](https://fishshell.com) +[![Oh My Fish Framework](https://img.shields.io/badge/Oh%20My%20Fish-Framework-007EC7.svg?style=flat-square)][omf] + +
+ +## Install + +[Oh My Fish][omf]: + +```sh +omf install https://github.com/Asim-Tahir/docker-compose.fish +``` + +[Fisher][fisher]: + +```sh +fisher install Asim-Tahir/docker-compose.fish +``` + +## Abbreviations Usage + +After installing the [`docker-compose.fish`][repo] plugin, can inspect the abbreviations with the following command: + +```sh +abbr --show | grep dcupdb +``` + +> [!NOTE] +> For all abbreviations, if the `docker compose` command is available, use `docker compose`, otherwise use `docker-compose`. + +### Up + +| Abbreviation | Command | +| ------------ | ------------------------------- | +| `dcup` | `docker compose up`  | +| `dcupb` | `docker compose up --build`  | +| `dcupd` | `docker compose up -d`  | +| `dcupdb` | `docker compose up -d --build`  | + +### Down + +| Abbreviation | Command | +| ------------ | --------------------- | +| `dcdn` | `docker compose down` | + +### Logs + +| Abbreviation | Command | +| ------------ | --------------------------------- | +| `dcl` | `docker compose logs` | +| `dclf` | `docker compose logs -f` | +| `dclF` | `docker compose logs -f --tail 0` | + +### Lifecycle + +| Abbreviation | Command | +| ------------ | ------------------------ | +| `dcstart` | `docker compose start` | +| `dcstop` | `docker compose stop` | +| `dck` | `docker compose kill` | +| `dcrestart` | `docker compose restart` | + +### Run Command + +| Abbreviation | Command | +| ------------ | --------------------- | +| `dce` | `docker compose exec` | +| `dcr` | `docker compose run` | + +### Everything Else + +| Abbreviation | Command | +| ------------ | ---------------------- | +| `dco` | `docker compose` | +| `dcb` | `docker compose build` | +| `dcps` | `docker compose ps` | +| `dcrm` | `docker compose rm` | +| `dcpull` | `docker compose pull` | + +# Credit + +Base structure heavily inspired from [`jhillyerd/plugin-git`](https://github.com/jhillyerd/plugin-git). Thanks for the amazing plugin. + +# License + +[MIT][license] © [Asim Tahir][author] + +[author]: https://github.com/Asim-Tahir +[repo]: https://github.com/Asim-Tahir/docker-compose.fish +[license]: https://opensource.org/licenses/MIT +[omz]: https://github.com/ohmyzsh/ohmyzsh +[omz-docker-compose-plugin]: https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/docker-compose/ +[omf]: https://github.com/oh-my-fish/oh-my-fish +[fisher]: https://github.com/jorgebucaran/fisher +[license-badge]: https://img.shields.io/badge/license-MIT-007EC7.svg?style=flat-square diff --git a/conf.d/docker-compose.fish b/conf.d/docker-compose.fish new file mode 100644 index 0000000..0aefa74 --- /dev/null +++ b/conf.d/docker-compose.fish @@ -0,0 +1,7 @@ +# Fisher initialization +# protected as omf also tries to run it. +set -q fisher_path; or set -l fisher_path $__fish_config_dir +if test -f $fisher_path/functions/_docker-compose.init.fish + source $fisher_path/functions/_docker-compose.init.fish + _docker-compose.init +end diff --git a/functions/_docker-compose.abbrs.fish b/functions/_docker-compose.abbrs.fish new file mode 100644 index 0000000..9954e51 --- /dev/null +++ b/functions/_docker-compose.abbrs.fish @@ -0,0 +1,37 @@ +function _docker-compose.abbrs -d "Initialize Docker Compose abbreviations" + set dccmd (docker compose version > /dev/null 2>&1 && echo 'docker compose' || echo 'docker-compose') + + abbr -a -g dco $dccmd + + # Up + abbr -a -g dcup $dccmd up + abbr -a -g dcupb $dccmd up --build + abbr -a -g dcupd $dccmd up -d + abbr -a -g dcupdb $dccmd up -d --build + + # Down + abbr -a -g dcdn $dccmd down + + # Logs + abbr -a -g dcl $dccmd logs + abbr -a -g dclf $dccmd logs -f + abbr -a -g dclF $dccmd logs -f --tail 0 + + # Lifecycle + abbr -a -g dcstart $dccmd start + abbr -a -g dcstop $dccmd stop + abbr -a -g dck $dccmd kill + abbr -a -g dcrestart $dccmd restart + + # Command + abbr -a -g dce $dccmd exec + abbr -a -g dcr $dccmd run + + # Misc + abbr -a -g dcb $dccmd build + abbr -a -g dcps $dccmd ps + abbr -a -g dcrm $dccmd rm + abbr -a -g dcpull $dccmd pull + + set -e dccmd +end diff --git a/functions/_docker-compose.init.fish b/functions/_docker-compose.init.fish new file mode 100644 index 0000000..93267a2 --- /dev/null +++ b/functions/_docker-compose.init.fish @@ -0,0 +1,4 @@ +function _docker-compose.init -d "Initialize Docker Compose plugin" + # Initialize Docker Compose abbreviations + _docker-compose.abbrs +end diff --git a/init.fish b/init.fish new file mode 100644 index 0000000..c126d99 --- /dev/null +++ b/init.fish @@ -0,0 +1,10 @@ +# Oh My Fish initialization +# $path is only defined for oh-my-fish. home-manager activates this plugin by +# adding the full path of functions/ to fish_function_path, and then sourcing +# init.fish, so let's skip sourcing _docker-compose.init.fish before calling _docker-compose.init. +set -l _docker_compose_init_path "$path/functions/_docker-compose.init.fish" +if [ -f "$_docker_compose_init_path" ]; + source "$_docker_compose_init_path" +end + +_docker-compose.init \ No newline at end of file