Image generated with Bing!

How to Find Your Project Folder Easily From Bash

A bash script that helps me to quickly navigate to any project from any directory.

Sabbir Mollah
3 min readOct 5, 2023

--

Most meticulous developers I’ve encountered centralize all their projects within a designated folder named workspace. Often you will find this directory residing in their $HOME/ directory. If you find yourself in the other group, I recommend you to initiate this approach to organize your projects. This is not only because, without it, you’ll constantly need to engage in mental acrobatics to recall where each project is located at, but also because this approach facilitates various automation processes. One such automation is quickly accessing a project from any directory.

Setting up the script

This script was written by keeping Linux in mind, however, you can make it work on Mac and Windows as well given that you have bash installed on your PC (Chances are that you have installed Bash along with git).

  1. Create a file named .workspace_script in your $HOME directory
  2. Copy, paste, and save the file
  3. Add the line source ~/.workspace_script at the bottom of the file ~/.bashrc (Make sure that you can view hidden files, if you still can’t find .bashrc then create it)
  4. Open a bash terminal, type work and press <enter>

DISCLAIMER: Make sure you understand this code before running it. Not understanding how this script works may result in lost of data.

Usage

work command will cd your terminal to your workspace folder, saving you the time of typing something like cd ~/Path/To/Projects/workspace/ .

work --now will help you when you have a brand new project idea, and you don’t want to waste 5 seconds of time by (1) searching your file manager, (2) search for a directory where to create your project, and (3) come up with a project name at this stage. All you need to do now is typing this command which will automatically create a new temporary folder in your workspace and change your directory (cd ) to that folder. All you have to do now, is type code . and start coding in VSCode (Assuming you have it installed).

work --clear will remove all folders prefixed with random_folder in your workspace folder (Use with caution!!!). Perhaps you have executed the now command too much and want to clean up the random projects (created using the — now command), that’s when you want to run this command.

work <PROJECT_NAME> (For example: work chatgpt) will create new folder ~/workspace/<PROJECT_NAME> . The projects created this way (projects without the random_project prefix) won’t be deleted when you run work --clear .

work --list will generate you a list of all project names in the workspace folder followed by the number. Typing the number of the project will instantly take you to that folder without having to type the project name.

work --help will print the list of supported commands.

Conclusion

Picture this: your senior developer is behind your shoulder while your are desperately searching for a project buried deep within your folder labyrinth. All you will have to remember on that bad shaky hand day is work!

--

--