Image for the Tutorial on The File Watchers Tool

The File Watchers Tool in PHPStorm: Tutorial

30/06/2023

What is File Watchers and How Can it Help You?

Once upon a time, in the vast universe of programming, repetitive tasks were a common source of headaches. Then, along came the "File Watchers" tool, built into the PHPStorm IDE. It swept onto the scene, promising a solution for those tiresome tasks that seemed to eat up so much of a developer's day.

Have you also found yourself looking for a tool that could automate some tasks in your programming routine? Something that would take over mundane actions, freeing up your time for more complex coding tasks? If yes, then you're in good company!

The Advantages of using File Watchers

You might be wondering, "But what about built-in observers in many modern frameworks and tools?" True, they're useful, but "File Watchers" has its own charm. While developing a module for PrestaShop, I found myself yearning for a solution that would allow me to automatically create a compressed module, ready for verification and installation. In particular, I wanted this process to be triggered each time I saved the file I was working on. This desire led me down the rabbit hole, and I discovered the "File Watchers" tool available by default in the PHPStorm IDE.

What sets "File Watchers" apart is its high degree of configurability. It offers the opportunity to connect various programs to be set in motion each time a file is saved. It's like having a digital genie, waiting to fulfil your command at the click of a save button.

To summon this genie, you only need to follow the magical pathway: “Preferences -> Tools -> File Watchers”.

Image showing where to find file watchers category in preferences on macos

How to use File Watchers: Tutorial

When the window pops up, you have the power to add a new watcher, adjust existing ones, or banish those that no longer serve your needs. To initiate a new watcher, all you need to do is click on the little "+" icon. From there, you can select from a suite of pre-existing templates (like those tailored for the SASS preprocessor), or if you're feeling adventurous, you can craft a fresh setting. For the purposes of this post, and perhaps your own explorations, choosing "<custom>" could be just the right amount of spice you need to add to your coding recipe.

Screenshot illustrating how new file watcher window looks like

The "File Watchers" tool boasts a plethora of options. PHPStorm allows you to select the file type that triggers an action upon modification. The "scope" option provides a nifty advantage, as it can be restricted to only VCS-committed files, which I believe makes the workflow a lot smoother. Other key options include "Program" and "Arguments", where you can choose the appropriate executable file and its parameters, respectively.

Additional settings let you decide where the tool's output and logs should be written, set environment variables, and specify the folder where the watcher will operate. Advanced options, such as tracking files after automatic save or tracking external changes, are available at your disposal, along with the possibility to control what appears in the terminal and filter the output.

To meet my specific needs, I created a Bash file. Imagine the scenario in PrestaShop module development: a Bash file is created that, upon triggering the rsync and zip commands, copies all required module files into a separate folder, then creates a compressed file ready for deployment and verification. It's like having an automated assembly line, taking care of the monotonous production while the developer focuses on the design and quality control.

Try it Yourself

So, next time when the tedium of repetition starts to creep into your coding routine, let "File Watchers" be your escape hatch. Think of it as a magical tool within PHPStorm IDE, ready to take away the monotony of your programming journey, helping you reach new pinnacles of creativity and productivity. In its wide range of capabilities, "File Watchers" not only helps streamline complex projects but also guides you efficiently through the intricacies of the coding process, serving as a reliable guide.

Pa
Zdjęcie autora artykułu - back-end developera w Primotly. Na zdjęciu profesjonalny młody mężczyzna z krótkimi włosami i okularami patrzy bezpośrednio w kamerę.
Paweł Turek
Back-end Developer

Najnowsze artykuły

Ilustracja do artykułu o zwiększeniu sprzedaży w sklepie ecommerce

Development | 13/09/2024

Rozwiązania IT dla branży eCommerce - jak poprawić sprzedaż w sklepie internetowym?

Łukasz Kopaczewski

W świecie eCommerce, gdzie konkurencja stale rośnie, właściciele sklepów internetowych muszą sięgać po innowacyjne narzędzia, aby zwiększyć sprzedaż i zbudować lojalność klientów. Kluczem do sukcesu są odpowiednie rozwiązania IT, które automatyzują procesy sprzedażowe, personalizują doświadczenia zakupowe i integrują się z różnymi systemami. W tym artykule przedstawiamy najskuteczniejsze metody zwiększenia efektywności działania sklepu internetowego, które pozwolą Ci wyprzedzić konkurencję.

Szczegóły
Ilustracja z ikonami reprezentującymi różne działy edukacji oraz nowoczesne technologie

Innovations | 11/09/2024

Jak nowe technologie w nauczaniu niwelują przepaść edukacyjną?

Agata Pater

Bariery, które kiedyś definiowały dostęp do edukacji - położenie geograficzne, status ekonomiczny i dostępność zasobów - są stopniowo usuwane. Wraz z ciągłym wprowadzaniem innowacji i wdrażaniem nowych technologii, luki, które tradycyjnie dzieliły uczniów na całym świecie, zmniejszają się, przybliżając nas do ery prawdziwie sprawiedliwej edukacji.

Szczegóły
Ilustracja obrazująca powiązanie pomiędzy AI a odnawialną energią

Innovations | 05/09/2024

Rewolucja w sektorze energetycznym: AI w transformacji energetycznej

Bernhard Huber

Ponieważ globalna społeczność zmaga się z wyzwaniami związanymi ze zmianami klimatycznymi, przejście na odnawialne źródła energii nigdy nie było bardziej istotnym zagadnieniem. Przejście na czystą energię jest nie tylko niezbędne do zmniejszenia emisji dwutlenku węgla, ale także do zapewnienia odpowiedzialnej przyszłości przyszłym pokoleniom. Na czele tej rewolucji stoi sztuczna inteligencja - potężne narzędzie, które zmienia sposób, w jaki produkujemy, dystrybuujemy i zużywamy energię. Technologie sztucznej inteligencji są coraz częściej integrowane z systemem energetycznym, optymalizując wszystko, od wytwarzania energii po jej magazynowanie.

Szczegóły