forelady is from 1867 in reference to juries, 1888 of shops
cp forelady.rb /usr/local/bin/forelady
chmod u+x /usr/local/bin/foreladycd my-project
forelady| #!/usr/bin/env ruby | |
| require "tempfile" | |
| class Tab | |
| attr_reader :title, :command | |
| def initialize(title, command) | |
| @title = title.strip.chomp | |
| @command = command.strip.chomp | |
| end | |
| def template(project_dir) | |
| <<~OSA | |
| set #{tab} to (create tab with default profile) | |
| tell sessions[1] of #{tab} to write text "echo -ne '\\\\033]0;#{title}\\\\007'" | |
| tell sessions[1] of #{tab} to write text "cd #{project_dir}; #{command}" | |
| OSA | |
| end | |
| def tab | |
| object_id.to_s.chars.map { |c| (65 + c.to_i).chr }.join | |
| end | |
| def self.try_files(*file_names) | |
| file = file_names.detect { |f| File.exist?(f) } | |
| if file.nil? | |
| puts "Could not find #{file_names.join(" or ")}" | |
| exit(1) | |
| end | |
| file | |
| end | |
| def self.generate_osascript | |
| project_dir = Dir.pwd | |
| filename = try_files("./Procfile.dev", "./Procfile") | |
| tabs = File.readlines(filename).map { |l| Tab.new(*l.split(":", 2)) } | |
| <<~OSA | |
| tell application "iTerm2" | |
| tell current window | |
| #{tabs.map { |t| t.template(project_dir) }.join("\n ")} | |
| select first tab | |
| end tell | |
| end tell | |
| OSA | |
| end | |
| end | |
| file = Tempfile.new("osascript") | |
| begin | |
| file.write(Tab.generate_osascript) | |
| file.close | |
| command = "/usr/bin/osascript <#{file.path}" | |
| system(command) | |
| ensure | |
| file.close | |
| file.unlink | |
| end |
| 🍄: bin/rails server | |
| 💨: bin/rails tailwindcss:watch | |
| 🔥: firebase emulators:start --project firebase-project-id --import=./emulator-data | |
| ☕️: yarn build --watch |