Skip to content

Instantly share code, notes, and snippets.

@1v
Last active December 15, 2022 23:17
Show Gist options
  • Save 1v/cf0a74bf10fbe7a8c2fbb04337f6cf45 to your computer and use it in GitHub Desktop.
Save 1v/cf0a74bf10fbe7a8c2fbb04337f6cf45 to your computer and use it in GitHub Desktop.
Start Rails server with WSL and Windows Terminal on launch

Add this to Windows Terminal settings (Settings -> Open JSON file) after launchMode for example:

"startupActions": "new-tab -p Ubuntu wsl -- source ~/.bash_profile \\; cd ~/www/rails-project \\; bin/rails s \\; $SHELL; new-tab -p Ubuntu wsl -- source ~/.bash_profile \\; cd ~/www/rails-project \\; bin/webpack-dev-server \\; $SHELL; new-tab -p Ubuntu wsl -- source ~/.bash_profile \\; cd ~/www/rails-project \\; $SHELL"

Explanation:

Start rails server. Tab will not be closed if server stopped by user, because of $SHELL. Using source ~/.bash_profile because rvm not loaded without it

new-tab -p Ubuntu wsl -- source ~/.bash_profile \\; cd ~/www/rails-project \\; bin/rails s \\; $SHELL

Start webpack

new-tab -p Ubuntu wsl -- source ~/.bash_profile \\; cd ~/www/rails-project \\; bin/webpack-dev-server \\; $SHELL

Just open tab in project folder

new-tab -p Ubuntu wsl -- source ~/.bash_profile \\; cd ~/www/rails-project \\; $SHELL

Alternatively combine rails server tab and webpack tab in single tab by changing new-tab to split-pane:

"startupActions": "new-tab -p Ubuntu wsl -- source ~/.bash_profile \\; cd ~/www/rails-project \\; bin/rails s \\; $SHELL; split-pane -p Ubuntu wsl -- source ~/.bash_profile \\; cd ~/www/rails-project \\; bin/webpack-dev-server \\; $SHELL; new-tab -p Ubuntu wsl -- source ~/.bash_profile \\; cd ~/www/rails-project \\; $SHELL"

To start apache2 and postgres create /etc/wsl.conf and add:

[boot]
command = "service apache2 start && service postgresql start"

Links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment