Automating Frappe Bench Start in WSL with some simple steps

frappe automate bench start

Simplify Frappe Development Automate Bench Start in WSL

WSL Python Virtual Environment Frappe Frappe development Windows Subsystem for Linux Linux Scripting Bash Script Automate Frappe Bench Start Automation WSL Scripts

Starting your Frappe Bench in Windows Subsystem for Linux (WSL) can involve a few repetitive steps. This blog post will show you how to automate this process, saving you time and effort.


The Problem

Every time you want to work on your Frappe project, you likely have to:

  1. Open your WSL distribution (e.g., Ubuntu).
  2. Navigate & Activate your virtual environment.
  3. Navigate to your Frappe Bench directory.
  4. Run bench start.

This process can be repetitive. However, we can automate it using the .bashrc file while also gaining a better understanding of how .bashrc works.


The Solution: Bash Script and PATH

We'll use a simple Bash script and leverage the PATH environment variable to streamline this process.

What is .bashrc?

The .bashrc file is a script that runs automatically whenever you start a new Bash shell session in Linux, including WSL (Windows Subsystem for Linux). It is located in your home directory:

~/.bashrc

Key Functions of .bashrc:

  • Sets Environment Variables – You can define variables like PATH to make custom scripts and programs easily accessible.
  • Defines Aliases – Create shortcuts for frequently used commands (e.g., alias ll='ls -la').
  • Runs Custom Scripts on Startup – Automate repetitive tasks by adding script execution commands.
  • Modifies Shell Behavior – Customize prompt appearance, enable autocompletion, and more.

1. Create the Script

First, create a script named frappe_start.sh (or any name you prefer) in a convenient location within your WSL filesystem. I recommend creating a dedicated directory for your scripts. In this example, we'll use ~/customScript:

mkdir ~/customScript
cd ~/customScript
nano frappe_start.sh

Now, paste the following content into frappe_start.sh, making sure to replace /mnt/c/Users/USER with your actual Windows user path as it appears in WSL:

#!/bin/bash

cd
source ./env/bin/activate
cd frappe-bench/
bench start

Save the file and make it executable:

chmod +x frappe_start.sh

Check the location using pwd command and copy the path for the next step

pwd

Example Usage:

sab@DESKTOP-KANOFJB:~/customScript$ pwd
/home/sab/customScript

2. Add the Script to Your PATH

The PATH environment variable tells your shell where to look for executable files. We need to add the directory containing our script to PATH. To make this change persistent, we will modify the .bashrc file.

Open the .bashrc file:

nano ~/.bashrc

Add the following line at the end of the .bashrc file, replacing /home/sab/customScript with the actual path to your customScript directory within WSL:

export PATH=$PATH:/home/sab/customScript  # **REPLACE THIS WITH YOUR ACTUAL PATH**

Save the .bashrc file and apply the changes:

source ~/.bashrc

3. Usage

Now, simply open your WSL terminal and type:

frappe_start.sh

Or, if you named your script frappe_start:

frappe_start

Your Frappe Bench should start automatically!


Important Considerations

WSL Paths: Remember that paths within WSL differ from Windows paths. Use the WSL path (e.g., /mnt/c/Users/USER) rather than the Windows path (e.g., C:\Users\USER).

.bashrc Persistence: The .bashrc file is crucial for making the PATH change persistent across WSL sessions.

Script Location: Choose a convenient location for your script. Keeping it in a dedicated directory like ~/customScript is a good practice.