muxify 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a099c8cfe54df9755911cfb611b86c5d4ddca1d29ae2d7d97014e6e6a76f9541
4
- data.tar.gz: 328da4d2f68dc4c83a15868be3621b2c31fe7dbb5e4201e14c452916a0c8b08b
3
+ metadata.gz: 98861ef327df42548ffe35e925b221c5c16a44b5623f55a3c7384a41e55a1e3f
4
+ data.tar.gz: e8cbc88546ae7cae5610e32f1aa3349ea9b687dc682cd79c48fb9c4289024036
5
5
  SHA512:
6
- metadata.gz: 6cb676527839f166fa76fe11a66b0d0662e810b5253190522251135b41ced6ace77a329be7c88428e16a4e82a96bbbd4c554b09b221484f26682f13d26f69de6
7
- data.tar.gz: ea6b93059cfc439e9715642a0bda739c75c17509796fd7187ee89c625369fa6cf50bdc0d056bb263b6d82e71bb8125736d0189363474358e0675670877fc2fea
6
+ metadata.gz: a9bc6c4c4351d1cc2ed64d82c5de796cda9a956c42d086e05eef2077074f2228cd0ff3952eed55e2d676effcd8f52514024acb6bf3be8e9e813c6f283026cbda
7
+ data.tar.gz: ca0f1396d5cba5b0c5265d23633dc2a7ede6ce50de492f0d3141a10e9faf3c5b71c6c83a00ba2fe22809dd542b08aef9977259570bbfa54f4632b87944e705c2
data/README.md CHANGED
@@ -4,15 +4,15 @@ Sets up consistent tmux development environment for projects.
4
4
 
5
5
  Why?
6
6
 
7
- * Saves time and effort switching projects.
8
- * Ensures consistent layout which is faster to navigate via muscle memory.
9
- * Avoids visual and mental overhead of maintaining numerous tabs.
7
+ - Saves time and effort switching projects.
8
+ - Ensures consistent layout which is faster to navigate via muscle memory.
9
+ - Avoids visual and mental overhead of maintaining numerous tabs.
10
10
 
11
11
  ## Dependencies
12
12
 
13
- * MacOS (may work on Linux)
14
- * Ruby
15
- * Tmux (`which tmux || brew install tmux`)
13
+ - MacOS (may work on Linux)
14
+ - Ruby
15
+ - Tmux (`which tmux || brew install tmux`)
16
16
 
17
17
  ## Installation
18
18
 
@@ -41,25 +41,26 @@ $ mux my_app
41
41
 
42
42
  Depending on its type, this will create the following tmux windows for a project:
43
43
 
44
- * Standard (applies to all projects)
45
- * shell (performs `git fetch` when `.git` is present)
46
- * editor (invokes terminal editor, defaulting to `vim` when `$EDITOR` is unset)
47
- * logs (when present, truncates then tails `log/*.log`)
48
- * Rails (identified by presence of `bin/rails`)
49
- * db (`rails db`)
50
- * console (`rails console`)
51
- * NodeJS (identified by presence of `package.json` when non-Rails)
52
- * console (`node`)
53
- * Elixir (identified by presence of `mix.exs` when non-Phoenix)
54
- * console (`iex -S mix`)
55
- * server (`mix`)
56
- * Elixir/Phoenix (identified by presence of `deps/phoenix`)
57
- * console (`iex -S mix phoenix.server`)
58
- * server (`mix phoenix.server`)
59
- * Django (identified by `requirements.txt` containing `django`)
60
- * db (`python manage.py dbshell`)
61
- * console (`python manage.py shell`)
62
- * server (`python manage.py runserver`)
44
+ - Standard (applies to all projects)
45
+ - shell (performs `git fetch` when `.git` is present)
46
+ - editor (invokes terminal editor, defaulting to `vim` when `$EDITOR` is unset)
47
+ - logs (when present, truncates then tails `log/*.log`)
48
+ - Rails (identified by presence of `bin/rails`)
49
+ - db (`rails db`)
50
+ - console (`rails console`)
51
+ - server (configures puma-dev then `rails server`; see [code](./bin/rails_server_with_puma_dev))
52
+ - NodeJS (identified by presence of `package.json` when non-Rails)
53
+ - console (`node`)
54
+ - Elixir (identified by presence of `mix.exs` when non-Phoenix)
55
+ - console (`iex -S mix`)
56
+ - server (`mix`)
57
+ - Elixir/Phoenix (identified by presence of `deps/phoenix`)
58
+ - console (`iex -S mix phoenix.server`)
59
+ - server (`mix phoenix.server`)
60
+ - Django (identified by `requirements.txt` containing `django`)
61
+ - db (`python manage.py dbshell`)
62
+ - console (`python manage.py shell`)
63
+ - server (`python manage.py runserver`)
63
64
 
64
65
  ## Customising projects
65
66
 
@@ -67,6 +68,7 @@ To add a custom tmux window for a project:
67
68
 
68
69
  1. Create a file called `~/.muxifyrc`.
69
70
  1. Edit it in YAML format; eg to add a tmux window to `my_app` project which is named `server` and invokes `yarn dev`:
71
+
70
72
  ```yaml
71
73
  my_app:
72
74
  windows:
@@ -75,7 +77,7 @@ my_app:
75
77
 
76
78
  ## Thanks
77
79
 
78
- * https://github.com/tmuxinator/tmuxinator
80
+ - https://github.com/tmuxinator/tmuxinator
79
81
 
80
82
  ## Contributing
81
83
 
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # Starts rails server with a random port and configures puma-dev
4
+ # Usage:
5
+ # rails_server_with_puma_dev [HOSTNAME]
6
+ # HOSTNAME should not include the `.test` extension.
7
+ # If HOSTNAME isn't supplied, it defaults to current directory name
8
+ # (underscores are converted to dashes).
9
+
10
+ set -euo pipefail
11
+
12
+ min_port=3000
13
+ max_port=4000
14
+ puma_dev_config_path="$HOME/.puma-dev"
15
+
16
+ find_available_port() {
17
+ netstat -aln | awk -v min_port="$min_port" -v max_port="$max_port" '
18
+ $6 == "LISTEN" {
19
+ if ($4 ~ "[.:][0-9]+$") {
20
+ split($4, a, /[:.]/);
21
+ port = a[length(a)];
22
+ p[port] = 1
23
+ }
24
+ }
25
+ END {
26
+ for (i = min_port; i < max_port && p[i]; i++) {};
27
+ if (i == max_port) { exit 1 };
28
+ print i
29
+ }
30
+ '
31
+ }
32
+
33
+ get_target_hostname() {
34
+ if (( $# == 0 )); then
35
+ echo "$(basename "$(pwd)" | tr '_' '-')"
36
+ else
37
+ echo $1
38
+ fi
39
+ }
40
+
41
+ configure_puma_dev() {
42
+ target_config_path="$puma_dev_config_path/$host"
43
+ echo "Configuring puma-dev: $host.test:$port ($target_config_path)"
44
+ echo "$port" > "$target_config_path"
45
+ puma-dev -stop
46
+ pkill -USR1 puma-dev
47
+ }
48
+
49
+ target_port="$(find_available_port)"
50
+ target_host="$(get_target_hostname "$@")"
51
+
52
+ host="$target_host" port="$target_port" configure_puma_dev
53
+ bundle exec rails server -p "$target_port"
@@ -91,6 +91,7 @@ module Muxify
91
91
 
92
92
  def logs
93
93
  return [] if logfiles.empty?
94
+
94
95
  logfiles.each(&method(:truncate_file))
95
96
  [{'logs' => 'tail -f log/*.log'}]
96
97
  end
@@ -105,6 +106,7 @@ module Muxify
105
106
 
106
107
  def foreman
107
108
  return [] unless foreman?
109
+
108
110
  [{'foreman' => <<-SH.strip}]
109
111
  ps aux | grep 'unicorn_rails master' | awk '{print $2}' | xargs kill; foreman start
110
112
  SH
@@ -116,9 +118,11 @@ module Muxify
116
118
 
117
119
  def rails
118
120
  return [] unless rails?
121
+
119
122
  [
120
123
  {'db' => 'rails db'},
121
124
  {'console' => 'rails console'},
125
+ {'server' => File.expand_path('../../bin/rails_server_with_puma_dev', __dir__)},
122
126
  ]
123
127
  end
124
128
 
@@ -128,6 +132,7 @@ module Muxify
128
132
 
129
133
  def elixir_non_phoenix
130
134
  return [] unless elixir_non_phoenix?
135
+
131
136
  [
132
137
  {'console' => 'iex -S mix'},
133
138
  {'server' => 'mix'},
@@ -140,6 +145,7 @@ module Muxify
140
145
 
141
146
  def phoenix
142
147
  return [] unless phoenix?
148
+
143
149
  [
144
150
  {'console' => 'iex -S mix phoenix.server'},
145
151
  {'server' => 'mix phoenix.server'},
@@ -152,6 +158,7 @@ module Muxify
152
158
 
153
159
  def nodejs
154
160
  return [] unless nodejs?
161
+
155
162
  [
156
163
  {'console' => 'node'},
157
164
  ]
@@ -163,6 +170,7 @@ module Muxify
163
170
 
164
171
  def django
165
172
  return [] unless django?
173
+
166
174
  [
167
175
  {'db' => 'python manage.py dbshell'},
168
176
  {'console' => 'python manage.py shell'},
@@ -172,7 +180,7 @@ module Muxify
172
180
 
173
181
  def django?
174
182
  python_requirements = File.join(root, 'requirements.txt')
175
- File.exists?(python_requirements) && File.read(python_requirements).include?('django')
183
+ File.exist?(python_requirements) && File.read(python_requirements).include?('django')
176
184
  end
177
185
 
178
186
  def directory?(relative_path)
@@ -180,7 +188,7 @@ module Muxify
180
188
  end
181
189
 
182
190
  def exists?(relative_path)
183
- File.exists?(File.join(root, relative_path))
191
+ File.exist?(File.join(root, relative_path))
184
192
  end
185
193
  end
186
194
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Muxify
4
- VERSION = '0.1.6'
4
+ VERSION = '0.1.7'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: muxify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zubin Henner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-02 00:00:00.000000000 Z
11
+ date: 2020-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -96,6 +96,7 @@ files:
96
96
  - Rakefile
97
97
  - bin/console
98
98
  - bin/muxify
99
+ - bin/rails_server_with_puma_dev
99
100
  - bin/setup
100
101
  - lib/muxify.rb
101
102
  - lib/muxify/builder.rb