A VSCode extension to execute terminal command in multiple directories.

Overview

SiteFlex

๐Ÿ˜ผ Introduction

The emergence of microservices and microfrontends posed a real threat on lazy programmers. Consider this scenario, you have multiple directories in your workspace folder, which can all be executed with a single command yarn start but on a different terminal.

image

image

I got you covered! All of these boring tasks can now be done easily with SiteFlex.

๐Ÿ˜ผ Storytelling

๐Ÿ˜ธ The kickoff

First off, why does this section even exist? Also, why does it has to be prior to Installation? It's simple, people tend to seek jealousy around others' Github profiles but never actually clone, run and appreciate any of their works. I started to accept this truth, so I decided to entertain you with a story in README.md, so you can enjoy my story instead.

Without further ado...

I've just been assigned to a new project with a gigantic architecture design. More precisely, it's implemented microfontend for the client side and microservice for server side. let's just focus on the client side.

Just in case you didn't know what is microfrontend, the main idea of the concept is to distribute your frontend application into multiple processes, each is responsible a specific service, or feature. Therefore, to successfully run the application as a whole, I'd have to start every project individually.

"Yay, a new coding day, I'm gonna be dead productive today" - said myself.

"Oh damn, I have to cd api-service; yarn start, cd style-service; yarn start, cd love-รญ-i-iservice; yarn start, and the same to the rest 69 folders before even getting my hands dirty on the code!" - said myself with a frown.

I don't know about you but repeating the same thing over and over again, day by day, has got my motivation heavily devastated. Like, come on! I'm a software developer, NOT a yarn starter.

Anyway, as a software developer, I've got a lazy mindset. If you code long enough, you'll recognize the pattern:

"If a task is long, repetitive and tedious, there's a high chance someone has automated it." - CuteTN

In fact, I was not the only one who has thought of this. My co-workers loved it, my leader wished for it, yet nobody had made any changes except for one of my best friends in the team (I highly appreciate your inspiration, Hแบญu). I decided to give him a hand on the idea.

Our original approach was pretty straightforward: using Shell Script. That wasn't too bad! In fact, we have created many different versions of the script but none of them is perfect for our use-case. I'd skip the details here, but our main pain points were to interact with the OS through Shell.

This is the point where I came across with a wild idea. How about building my own VSCode extension?

My choice on VSCode actually made sense. My whole team are working with VSCode. I myself love it, especially when combined with vim extension. If there's any better code editor than VSCode, then it must be vim, or notepad. I have met a friend who preferred Visual Studio, and his coding skill is nothing but garbage (I'm not making any assumption here, I'm talking about a guy, if you try to generalize it, then your logic skill is nothing but Windows 11). In addition, VSCode offers a range of different built-in toolsets with friendly interfaces. Its capacity to manipulate terminals and customize views was gems!

I've had great experience on working with VSCode before, mostly from configuring my favorite key bindings and commands. But building a full, complete extension has never been on my menu. However, I love "weird" stuffs, I love the feeling of discovery along with any of my journeys, not its end result. With that in mind, I gave it a shot!

So I defined a goal, as a user story:

As a coder, I want an extension that lets me select multiple folders in the my project's directory. Once the folders are selected, I can create a terminal instance for each, and send yarn start to that instance.

As you can see, the extension was initially made for a specific use-case, which is to serve my project, which is why the name of the extension was highly inspired on the name of the project itself (I couldn't reveal it here due to the complicated copyrights rules of my organization). Anyway, we'll get to this later.

My initial plan was simple: user's selected folders should be stored in a .siteflex-config file, which was adequately good, but not quite user friendly. So I decided to take on a higher target: to create a GUI sidebar so that the user can easily filter their necessary folders.

That decision has ruined my vacation, sort of...

๐Ÿ˜ฟ The process

โ€‹ Day 1: Learning & planning

I spent most of my first day investigating the APIs of VSCode. The documentation was huge, and I, honestly, was overwhelmed by how much information I had to accumulate.

It wasn't hard to find sample codes and boilerplates online, but to gather those piece of code altogether was still too challenging. Hopefully, I managed to get my first command prototype and a render-able view right in the first day.

I have a weird interest in building standalone applications, which means I tried to use nothing other than what I was given in the template. Reinventing the wheel is always painful and this is no exception. I have to construct my view and its logic in plain html-css-js, I did not even install VanillaJS. I started to feel grateful for my 2-week experience on the skill...

โ€‹ Day 2: Building & suffering

Developing VSCode extension was fun, until you have to build a custom webview for it.

To fully understand the next part, please keep in mind that the extension and the webview are not in the same process and environment. In other words, "Think of a webview as an iframe within VS Code that your extension controls" - said the doc itself. Therefore, communication between extension and webview can only done by message passing.

There might be a way to debug custom view properly, the only problem, however, was I couldn't figure it out. Which made the whole coding experience the pain in the ass. If I wanted to debug a UI styling behavior, I had to create a prototype on browser. If I wanted to console.log some data, I had to send the log content back to extension. It was not the worst, thought, if there were compile errors, the view script would just silently disabled, just imagine you have to comment/uncomment every single line of code just to find a single compile error...

By the end of day 2, I could finally load all of the folders in the current workspace to my view. The progress was quite slow because of unexpected compile errors about function hoisting... Nevertheless, I'd gone through one of the most pivotal part: the communication between webview and extension!

โ€‹ Day 3: Finishing & enhancing

Right after getting the bridge built, I could easily implement the rest of the features, including synchronizing workspace state to webview's state, integrate with VSCode terminal, improve UI/UX.

As soon as I get here, I realized that my extension was able to serve much more general purposes by letting people customize their command to execute for each terminal. The extension then had nothing to do with my project no more. As a result, I changed the requirements to this:

As a coder, I want an extension that lets me select multiple folders in the current workspace directory. Once the folders are selected, I can create a terminal instance for each, and send a command to that instance.

โ€‹ Day 4: Releasing and bragging

You may be pissed out that I use the word "and" instead of "&" there but I would give no foot. I'm writing this README.md in my own style to celebrate my accomplishment. Writing an extension is one of my dreams ever since my first line of code. There were ups and downs, but I eventually pulled it off after all.

Ladies and gentlemen, this would unlock even more weird-ass projects on this account! So stay tuned!

๐Ÿ˜ฝ The outcome

Just clone the damn repository.

๐Ÿ˜ผ Installation

๐Ÿ˜บ Get the extension file (*.vsix)

If you're interested in installing the extension from source code yourself, then just clone it and follow the full documentation here.

Otherwise, for you, lazy people, I had it done for you. You just have to download the zip from here.

๐Ÿ˜บ Install extension to your VSCode

โ€‹ CLI:

The Sun might disappear, but nerdy guys don't. Just make sure you have code set to your VSCode's path in the environment variables of your OS.

code --install-extension <path-to-vsix-file>

โ€‹ GUI:

If you follow this, no worries, you're an ordinary person and congratulations, you'll easily fit in any parties.

In your VSCode, hit ctrl+shift+p (Show all commands) and search for ""Extensions: Install from VSIX..." command. Press enter, browse and select the *.vsix file.

image

๐Ÿ˜ผ Usage

๐Ÿ™€ Select folders and enter terminal command

Just toggle SiteFlex's view from the squirrel icon, everything else should be straightforward.

Side story, the only reason for which I opted for the squirrel, was I thought it was cute.

image

๐Ÿ˜น Send the terminal command

Besides the obvious way to trigger the command, which is to sing this song to the "Execute" button, you can also use keyboard shortcut: ctrl+i i.

๐Ÿ˜ผ License

The extension's source code was published under MIT license. Which means you are free to clone and do whatever you want to it, but I would give no damn about your mom's safety.

Ever since I started to create this extension, I've never been too serious, but if you are, feel free to contact me, I need a friend; or you can build your own from the idea (I would love to take credits if possible).

Despite my playful mindset, reliability is always highly concerned. If you find any bugs, contact me, I need a friend.

๐Ÿ˜ผ Todo

These are just ideas. I don't have any plans to implement these anytime soon. I would do, though, as asap as I need it.

  • Custom display name: Folder's name are sometimes too long, but doesn't carry as much information. It's reasonable for one to change the display name of a folder on a terminal.
  • Sending signals to terminals: Instead of raw text commands, we may wish to send SIGINT signal to terminate the terminal task. Think about that!
  • Directory's categories: You may want to group multiple directories to execute a command, while other groups require a different command.
  • Manual input: Whenever you need to execute a new command, instead of getting to the sidebar end key in the new text all the time, you can input your command in the VSCode's built-in input. We will have an option to toggle this feature.
  • Execution order: Sometimes, the order of directories to run the terminal commands matters.
  • Finishing the last todo description: It is just extremely annoying if
You might also like...

True P2P concept for your p2p powered website/app/client. MSC/MEP (Multiple Strategy Concept/Multiple Entry Points)

True P2P concept for your p2p powered website/app/client. MSC/MEP (Multiple Strategy Concept/Multiple Entry Points)

TRUE P2P CONCEPT - Lets redecentralize the web This repo is just conceptual. Active development of the endproduct (TRUE P2P) happens here https://gith

Mar 29, 2022

โšก๐Ÿš€ Call multiple view functions, from multiple Smart Contracts, in a single RPC query!

ethers-multicall โšก ๐Ÿš€ Call multiple view functions, from multiple Smart Contracts, in a single RPC query! Querying an RPC endpoint can be very costly

Dec 30, 2022

Create multiple files from your command line.

@marsidev/create Create multiple files from your command line. Installation npm install -g @marsidev/create Usage create files [options] Examples cr

Nov 25, 2022

Run a command, watch the filesystem, stop the process on file change and then run the command again...

hubmon Run a command, watch the filesystem, stop the process on file change and then run the command again... Install You can install this command lin

Jul 30, 2022

VSCode extension that creates overlay for your Broadcasting Software of choice.

VSCode extension that creates overlay for your Broadcasting Software of choice.

BSOverlay VSCode extension that creates an overlay for your Broadcasting Software of choice. Documentation Please refer to the Wiki Section. Installin

Sep 30, 2022

A vscode extension to quickly print variable, variable type, tensor shape etc by using shortcuts

A vscode extension to quickly print variable, variable type, tensor shape etc by using shortcuts

Quick Python Print This repo is inspired by "Python Quick Print". "Python Quick Print" can quickly print out variables on the console by using shortcu

Oct 28, 2022

VSCode extension for managing text selection.

Selection Manager This Visual Studio Code extension will allow you to manage selected text. The aim of this extension is to increase productivity by u

Apr 12, 2022

VSCode extension for the rickroll-lang programming language (incomplete)

Rickroll-Lang VSCode Extension The Rick Roll programming language is a rickroll based, process oriented, dynamic, strong, esoteric programming languag

Oct 10, 2022

NextJS VScode extension to visualize component tree.

NextJS VScode extension to visualize component tree.

Nexus A component tree extension for NextJS Report Bugs ยท Request Features Table of Contents About The Project Built With Installation Getting Started

Nov 24, 2022
Releases(v0.0.1-alpha)
Owner
CuteTN
I love Mathematics and Computer Science. I'm improving my programming skills by creating some joke projects. Hope you enjoy my works :)
CuteTN
Chat with GPT from the terminal, with the ability to execute shell scripts.

ChatSH Chat with GPT from the terminal, and let it execute shell scripts and perform tasks for you. What could go wrong? Example Why? The reason I'm p

Victor Taelin 47 Jun 11, 2023
Specify various templates for different directories and create them with one click. ๐Ÿคฉ

English | ็ฎ€ไฝ“ไธญๆ–‡ Gold Right Specify various templates for different directories and create them with one click. Reason Usually there is something in the

่ตตๆฑๆพ” 16 Aug 8, 2022
โœ’๏ธ A VSCode-like command palette plugin for inkdrop

inkdrop command palette A VSCode-like command palette for Inkdrop. (Invoke using Ctrl+K) https://my.inkdrop.app/plugins/command-palette ?? You may nee

Jariel Que 11 Nov 1, 2022
๐Ÿ“ธ A command-line tool to generate code images of your local code right away from the terminal

?? rayli ?? A command-line tool to generate code images of your local code right away from the terminal Usage Commands Usage $ npm install -g rayli $

buidler's hub 45 Nov 4, 2022
Execute obsidian commands with short key sequences. For example, 'tp' for 'Toggle Preview' and 'tb' for 'Toggle Sidebar'. Easier to remember.

Key Sequence Shortcut Key Sequence Shortcut is an obsidian plugin, allow binding key sequences to an obsidian command. For example If we assume "t" st

Yu Wang 26 Dec 26, 2022
This is a project that is used to execute python codes in the web page. You can install and use it in django projects, You can do any operations that can be performed in python shell with this package.

Django execute code This is a project that is used to execute python codes in the web page. You can install and use it in django projects, You can do

Shinu 5 Nov 12, 2022
The project is a To-Do list project to help plan daily, weekly or monthly activity. I used Html, CSS and JavaScript Technology to execute the project.

<<<<<<< HEAD To Do List This project is geared towards applying acguired skills for development of my porfolio through the following practices: Create

Victor Efosa Osagie 6 Dec 19, 2022
Basic Implementation of a Contract Wallet in Solidity. The owner can transfer Ether/ERC20 and execute transactions via low-level calls.

Contract Wallet Basic Implementation of a Contract Wallet in Solidity. The owner can transfer Ether/ERC20 and execute transactions via low-level calls

Junho Yeo 3 Jun 18, 2022
Tries to execute sync/async function, returns a specified default value if the function throws

good-try Tries to execute sync/async function, returns a specified default value if the function throws. Why Why not nice-try with it's 70+ million do

Antonio Stoilkov 14 Dec 8, 2022
A JavaScript Library that allows you to execute function when a certain element gets added to the document

wait-for-it.js A JavaScript Library that allows you to execute function when a certain element gets added to the document Getting Started If you want

Muhammad Tayyab Sheikh 12 Apr 26, 2022