Skip to content

Commit 63d613b

Browse files
committed
Merge branch 'develop'
2 parents f9207b4 + e9b9855 commit 63d613b

20 files changed

+981
-14
lines changed

.circleci/config.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
version: 2
2+
jobs:
3+
test:
4+
docker:
5+
- image: debian
6+
steps:
7+
- checkout
8+
- run:
9+
name: Install zsh
10+
command: |
11+
apt-get update
12+
apt-get install -y --no-install-recommends zsh curl ca-certificates
13+
- run:
14+
name: Install zunit
15+
command: |
16+
curl -L https://github.com/zunit-zsh/zunit/releases/download/v0.8.2/zunit > /usr/local/bin/zunit
17+
curl -L https://raw.githubusercontent.com/molovo/revolver/master/revolver > /usr/local/bin/revolver
18+
curl -L https://raw.githubusercontent.com/molovo/color/master/color.zsh > /usr/local/bin/color
19+
chmod +x /usr/local/bin/{color,revolver,zunit}
20+
chmod +x tests/_support/bin/*
21+
- run:
22+
name: Run tests
23+
command: zunit
24+
25+
workflows:
26+
version: 2
27+
test:
28+
jobs:
29+
- test

.zunit.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
tap: false
2+
directories:
3+
tests: tests
4+
output: tests/_output
5+
support: tests/_support
6+
time_limit: 30
7+
fail_fast: false
8+
allow_risky: false

README.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
> The command that can save you typing 15 characters or more, each time!
44
5-
This plugins adds `start`, `restart`, `stop`, `up` and `down` commands when it detects a docker-compose or Vagrant file in the current directory (e.g. your application). Just run `up` and get coding!
5+
[![CircleCI](https://circleci.com/gh/Cloudstek/zsh-plugin-appup.svg?style=svg)](https://circleci.com/gh/Cloudstek/zsh-plugin-appup)
6+
7+
This plugins adds `start`, `restart`, `stop`, `up` and `down` commands when it detects a docker-compose or Vagrant file in the current directory (e.g. your application). Just run `up` and get coding! This saves you typing `docker-compose` or `vagrant` every time or aliasing them. Also gives you one set of commands that work for both environments.
68

79
### Docker
810

@@ -12,7 +14,7 @@ Aside from simply running `up`, you can also extend your configuration by runnin
1214

1315
Vagrant doesn't have a `down`, `restart`, `start` or `stop` commands natively but don't worry, that's been taken care of and running those commands will actually run vagrant's equivalent commands. Additional arguments will be directly supplied to vagrant.
1416

15-
## Command mapping
17+
### Command mapping
1618

1719
| Command | Vagrant command | Docker command |
1820
| ------- | ---------------------------------------------------------- | ------------------------------------------------------------ |
@@ -22,3 +24,28 @@ Vagrant doesn't have a `down`, `restart`, `start` or `stop` commands natively bu
2224
| restart | [reload](https://www.vagrantup.com/docs/cli/reload.html) | [restart](https://docs.docker.com/compose/reference/restart/) |
2325
| stop | [halt](https://www.vagrantup.com/docs/cli/halt.html) | [stop](https://docs.docker.com/compose/reference/stop/) |
2426

27+
## Installation
28+
29+
### oh-my-zsh
30+
31+
1. Clone this repository in `$ZSH_CUSTOM/plugins/appup`:
32+
33+
```bash
34+
git clone https://github.com/Cloudstek/zsh-plugin-appup.git "$ZSH_CUSTOM/plugins/appup"
35+
```
36+
2. Edit `~/.zshrc` and add `appup` to the list of plugins
37+
38+
### Plain ZSH
39+
40+
1. Clone this repository somewhere
41+
42+
2. Edit your `~/.zshrc` and add this line near the bottom of the file:
43+
44+
```bash
45+
source path/to/the/repository/appup.plugin.zsh
46+
```
47+
48+
## Updating
49+
50+
1. Go to the directory where you cloned the plugin repository
51+
2. Run `git pull origin master`

appup.plugin.zsh

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,38 @@ _appup_docker () {
1616
fi
1717
fi
1818

19+
# Check YAML extension
20+
compose_file=''
21+
compose_project_file=''
22+
23+
if [ -e "docker-compose.yml" ]; then
24+
compose_file='docker-compose.yml'
25+
elif [ -e "docker-compose.yaml" ]; then
26+
compose_file='docker-compose.yaml'
27+
fi
28+
1929
# <cmd> <project name> will look for docker-compose.<project name>.yml
20-
if [ -n "$2" -a -e "docker-compose.$2.yml" ]; then
21-
project=$(source ".env.$2"; echo $COMPOSE_PROJECT_NAME)
30+
if [ -n "$2" ]; then
31+
if [ -e "docker-compose.$2.yml" ]; then
32+
compose_project_file="docker-compose.$2.yml"
33+
elif [ -e "docker-compose.$2.yaml" ]; then
34+
compose_project_file="docker-compose.$2.yaml"
35+
fi
36+
37+
if [ -n "$compose_project_file" ]; then
38+
# Override project name from custom env
39+
if [ -e ".env.$2" ]; then
40+
project=$(source ".env.$2"; echo $COMPOSE_PROJECT_NAME)
2241

23-
if [ -n $project ]; then
24-
docker-compose -p "${project}" -f docker-compose.yml -f "docker-compose.${2}.yml" $1 "${@:3}"
42+
if [ -n $project ]; then
43+
docker-compose -p "${project}" -f "$compose_file" -f "$compose_project_file" $1 "${@:3}"
44+
return
45+
fi
46+
fi
47+
48+
docker-compose -f "$compose_file" -f "$compose_project_file" $1 "${@:3}"
2549
return
2650
fi
27-
28-
docker-compose -f docker-compose.yml -f "docker-compose.${2}.yml" $1 "${@:3}"
29-
return
3051
fi
3152

3253
docker-compose $1 "${@:2}"
@@ -45,7 +66,7 @@ _appup_vagrant () {
4566
}
4667

4768
up () {
48-
if [ -e "docker-compose.yml" ]; then
69+
if [ -e "docker-compose.yml" ] || [ -e "docker-compose.yaml" ]; then
4970
_appup_docker up "$@"
5071
elif [ -e "Vagrantfile" ]; then
5172
_appup_vagrant up "$@"
@@ -55,7 +76,7 @@ up () {
5576
}
5677

5778
down () {
58-
if [ -e "docker-compose.yml" ]; then
79+
if [ -e "docker-compose.yml" ] || [ -e "docker-compose.yaml" ]; then
5980
_appup_docker down "$@"
6081
elif [ -e "Vagrantfile" ]; then
6182
_appup_vagrant destroy "$@"
@@ -65,7 +86,7 @@ down () {
6586
}
6687

6788
start () {
68-
if [ -e "docker-compose.yml" ]; then
89+
if [ -e "docker-compose.yml" ] || [ -e "docker-compose.yaml" ]; then
6990
_appup_docker start "$@"
7091
elif [ -e "Vagrantfile" ]; then
7192
_appup_vagrant up "$@"
@@ -75,7 +96,7 @@ start () {
7596
}
7697

7798
restart () {
78-
if [ -e "docker-compose.yml" ]; then
99+
if [ -e "docker-compose.yml" ] || [ -e "docker-compose.yaml" ]; then
79100
_appup_docker restart "$@"
80101
elif [ -e "Vagrantfile" ]; then
81102
_appup_vagrant reload "$@"
@@ -85,7 +106,7 @@ restart () {
85106
}
86107

87108
stop () {
88-
if [ -e "docker-compose.yml" ]; then
109+
if [ -e "docker-compose.yml" ] || [ -e "docker-compose.yaml" ]; then
89110
_appup_docker stop "$@"
90111
elif [ -e "Vagrantfile" ]; then
91112
_appup_vagrant halt "$@"

tests/_output/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

tests/_support/bin/docker-compose

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env zsh
2+
3+
echo docker-compose "$@"

tests/_support/bin/vagrant

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env zsh
2+
3+
echo vagrant "$@"

tests/_support/bootstrap

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env zsh
2+
3+
if [ -z "$TERM" ]; then
4+
export TERM=xterm
5+
fi
6+
7+
export APPUP_TMP=/tmp/appup_test
8+
export PATH="${PWD}/tests/_support/bin:${PATH}"
9+
10+
_tmp_setup () {
11+
rm -Rf $APPUP_TMP
12+
mkdir $APPUP_TMP
13+
}
14+
15+
_tmp_teardown () {
16+
rm -Rf $APPUP_TMP
17+
}

tests/_support/docker.zsh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env zsh
2+
3+
_setup_simple_env () {
4+
ext='yml'
5+
if [ -n "$1" ]; then
6+
ext=$1
7+
fi
8+
9+
cd $APPUP_TMP
10+
11+
touch docker-compose.$ext
12+
}
13+
14+
_setup_project_env () {
15+
project=$1
16+
17+
if [ -z "$1" ]; then
18+
>&2 echo "Empty project name."
19+
exit 2
20+
fi
21+
22+
ext='yml'
23+
if [ -n "$2" ]; then
24+
ext=$2
25+
fi
26+
27+
cd $APPUP_TMP
28+
29+
touch {docker-compose,docker-compose.$project}.$ext
30+
}

tests/_support/vagrant.zsh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env zsh
2+
3+
_setup_simple_env () {
4+
cd $APPUP_TMP
5+
6+
touch Vagrantfile
7+
}

0 commit comments

Comments
 (0)