Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion plugins/docker-compose/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This plugin provides completion for [docker-compose](https://docs.docker.com/compose/) as well as some
aliases for frequent docker-compose commands.
This plugin chooses automatically between the legacy `docker-compose` command and the modern
This plugin chooses automatically between the legacy `docker-compose` command and the modern
`docker compose` subcommand, preferring `docker-compose` when both are available.

To use it, add docker-compose to the plugins array of your zshrc file:
Expand All @@ -17,6 +17,7 @@ plugins=(... docker-compose)
|-----------|----------------------------------|----------------------------------------------------------------------------------|
| dco | `docker-compose` | Docker-compose main command |
| dcb | `docker-compose build` | Build containers |
| dcc | `docker-compose config` | Parse, resolve and render compose file in canonical format |
| dce | `docker-compose exec` | Execute command inside a container |
| dcps | `docker-compose ps` | List containers |
| dcrestart | `docker-compose restart` | Restart container |
Expand Down
1 change: 1 addition & 0 deletions plugins/docker-compose/docker-compose.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

alias dco="$dccmd"
alias dcb="$dccmd build"
alias dcc="$dccmd config"
alias dce="$dccmd exec"
alias dcps="$dccmd ps"
alias dcrestart="$dccmd restart"
Expand Down
9 changes: 7 additions & 2 deletions plugins/eza/eza.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,13 @@ function _configure_eza() {
if [[ $_val ]]; then
_EZA_TAIL+=("--time-style='$_val'")
fi
if zstyle -t ":omz:plugins:eza" "hyperlink"; then
_EZA_TAIL+=("--hyperlink")
if zstyle -t ':omz:plugins:eza' 'hyperlink'; then
# eza >= 0.23 needs an explicit WHEN value
if command eza --hyperlink=auto --version &>/dev/null; then
_EZA_TAIL+=("--hyperlink=auto")
else
_EZA_TAIL+=("--hyperlink")
fi
fi
}

Expand Down
27 changes: 27 additions & 0 deletions plugins/rails/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,33 @@ plugins=(... rails)
| `rta` | `rails test:all` | Runs all Rails tests, including system tests |
| `ru` | `rails runner` | Run Ruby code in the context of Rails |

### Multiple databases

Rails applications can define more than one database (`primary`, `cache`, `cable`,
`queue`, ...), and each one gets its own namespaced task. These commands accept an
optional database name as the first argument:

`rdc`, `rdd`, `rdm`, `rdmd`, `rdmr`, `rdms`, `rdmu`, `rdr`, `rdrs`, `rdsl`

```zsh
rdm # rails db:migrate
rdm cache # rails db:migrate:cache
rdm VERSION=20231225 # rails db:migrate VERSION=20231225
rdm cache STEP=2 # rails db:migrate:cache STEP=2
rdm --trace # rails db:migrate --trace
```

The first argument is read as a database name only when it is a bare word. Flags
(`--trace`), variables (`STEP=2`) and other tasks (`db:seed`) are passed through to
`rails` unchanged, so previous usage keeps working. When a database name is given,
the resolved command is printed so it is clear which database is being used.

`rdmrs` is not in the list above because Rails does not define a per-database
`db:migrate:reset` task.

Note that these are implemented as shell functions rather than aliases, so they will
not appear in the output of `alias`.

### Foreman

| Alias | Command | Description |
Expand Down
51 changes: 41 additions & 10 deletions plugins/rails/rails.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,9 @@ alias rc='rails console'
alias rcs='rails console --sandbox'
alias rd='rails destroy'
alias rdb='rails dbconsole'
alias rdc='rails db:create'
alias rdd='rails db:drop'
alias rdm='rails db:migrate'
alias rdmd='rails db:migrate:down'
alias rdmr='rails db:migrate:redo'
alias rdmrs='rails db:migrate:reset'
alias rdms='rails db:migrate:status'
alias rdmtc='rails db:migrate db:test:clone'
alias rdmu='rails db:migrate:up'
alias rdr='rails db:rollback'
alias rdrs='rails db:reset'
alias rds='rails db:seed'
alias rdsl='rails db:schema:load'
alias rdtc='rails db:test:clone'
alias rdtp='rails db:test:prepare'
alias rgen='rails generate'
Expand Down Expand Up @@ -106,6 +96,47 @@ alias rkn='rake notes'
alias rksts='rake stats'
alias rkt='rake test'

# Database tasks
#
# Rails applications can define more than one database (primary, cache, cable,
# queue, ...). Each one gets its own namespaced task, e.g. `db:migrate:cache`.
# The functions below take an optional database name as the first argument:
#
# rdm -> rails db:migrate
# rdm cache -> rails db:migrate:cache
# rdm VERSION=20231225 -> rails db:migrate VERSION=20231225
# rdm cache STEP=2 -> rails db:migrate:cache STEP=2
# rdm --trace -> rails db:migrate --trace
#
# The first argument is read as a database name only when it is a bare word.
# Flags (--trace), variables (STEP=2) and other tasks (db:seed) are passed
# through to rails untouched, so the previous alias behavior still works.
function _rails_db_command() {
local task="$1"
shift

if [[ $# -gt 0 && "$1" != -* && "$1" != *=* && "$1" != *:* ]]; then
task="$task:$1"
shift
# Echo the resolved task so it is clear which database is being used
local -a cmd=(rails "$task" "$@")
print -u2 -r -- "Running: ${cmd[*]}"
fi

rails "$task" "$@"
}

function rdc() { _rails_db_command db:create "$@" }
function rdd() { _rails_db_command db:drop "$@" }
function rdm() { _rails_db_command db:migrate "$@" }
function rdmd() { _rails_db_command db:migrate:down "$@" }
function rdmr() { _rails_db_command db:migrate:redo "$@" }
function rdms() { _rails_db_command db:migrate:status "$@" }
function rdmu() { _rails_db_command db:migrate:up "$@" }
function rdr() { _rails_db_command db:rollback "$@" }
function rdrs() { _rails_db_command db:reset "$@" }
function rdsl() { _rails_db_command db:schema:load "$@" }

# legacy stuff
alias sc='ruby script/console'
alias sd='ruby script/destroy'
Expand Down