<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Felipe Rocha</title>
    <description>The latest articles on Forem by Felipe Rocha (@feliperocha93).</description>
    <link>https://forem.com/feliperocha93</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1927884%2F91305ef2-0ac2-4200-813b-67112e259330.jpeg</url>
      <title>Forem: Felipe Rocha</title>
      <link>https://forem.com/feliperocha93</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/feliperocha93"/>
    <language>en</language>
    <item>
      <title>Ensuring Consistent Node.js Versions Across Your Team</title>
      <dc:creator>Felipe Rocha</dc:creator>
      <pubDate>Mon, 28 Oct 2024 21:55:17 +0000</pubDate>
      <link>https://forem.com/feliperocha93/ensuring-consistent-nodejs-versions-across-your-team-364d</link>
      <guid>https://forem.com/feliperocha93/ensuring-consistent-nodejs-versions-across-your-team-364d</guid>
      <description>&lt;p&gt;&lt;em&gt;A Comprehensive Guide to &lt;code&gt;.nvmrc&lt;/code&gt; and &lt;code&gt;package.json&lt;/code&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In today's dynamic development landscape, managing multiple Node.js versions across various projects can often be a complex and error-prone task. Inconsistent Node.js versions can lead to many issues, from unexpected behavior to complete application failures.&lt;/p&gt;

&lt;h2&gt;
  
  
  Leveraging &lt;code&gt;.nvmrc&lt;/code&gt; Files for Version Control
&lt;/h2&gt;

&lt;p&gt;One highly effective method to maintain consistent Node.js versions within a project is by utilizing &lt;code&gt;.nvmrc&lt;/code&gt; files. These simple text files, strategically placed at the root of your project directory, specify the precise Node.js version required.&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating a &lt;code&gt;.nvmrc&lt;/code&gt; File:
&lt;/h3&gt;

&lt;p&gt;Navigate to your project's root directory and create a new file named &lt;code&gt;.nvmrc&lt;/code&gt; witn the desired Node.js version:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo &lt;/span&gt;18.16.10 &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; .nvmrc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Switching to the Correct Version with nvm use
&lt;/h2&gt;

&lt;p&gt;Once the &lt;code&gt;.nvmrc&lt;/code&gt; file is in place, you can effortlessly switch to the specified Node.js version using the &lt;code&gt;nvm use&lt;/code&gt; command. This command triggers NVM (Node Version Manager) to activate the designated version.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using the &lt;code&gt;nvm use&lt;/code&gt; Command:
&lt;/h3&gt;

&lt;p&gt;Navigate to your project's root directory in your terminal and execute the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nvm use

Found &lt;span class="s1"&gt;'/Users/**/.nvmrc'&lt;/span&gt; with version &amp;lt;v18.16.10&amp;gt;
Now using node v18.16.10 &lt;span class="o"&gt;(&lt;/span&gt;npm v10.8.3&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;NVM will automatically detect the &lt;code&gt;.nvmrc&lt;/code&gt; file and switch to the specified version.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting the Engine Version in &lt;code&gt;package.json&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;While &lt;code&gt;.nvmrc&lt;/code&gt; files are incredibly effective, it's also advisable to explicitly declare the required Node.js version in your &lt;code&gt;package.json&lt;/code&gt; file. This provides an additional layer of clarity and can be leveraged by various tools and services that rely on the &lt;code&gt;package.json&lt;/code&gt; file for essential information.&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting the Engine Version in package.json:
&lt;/h3&gt;

&lt;p&gt;Open your &lt;code&gt;package.json&lt;/code&gt; file in a text editor.&lt;br&gt;
Add or modify the engines field to specify the Node.js version:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"your-project-name"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"1.0.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"engines"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"node"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"18.16.0"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Best Practices for Node.js Version Management:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Centralized Version Control&lt;/strong&gt;: Utilize a robust version control system like Git to manage &lt;code&gt;.nvmrc&lt;/code&gt; files and ensure consistency across your entire team.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Regular Updates&lt;/strong&gt;: Keep NVM and Node.js updated to the latest stable versions to benefit from security patches and performance enhancements.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Clear Documentation&lt;/strong&gt;: Provide comprehensive instructions on how to set up the development environment, including Node.js version management.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;The clearest instructions for installation can be found in the &lt;a href="https://github.com/nvm-sh/nvm?tab=readme-ov-file#installing-and-updating" rel="noopener noreferrer"&gt;official nvm documentation&lt;/a&gt;. Let me know if you encounter any difficulties.&lt;/p&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;By adhering to these best practices and effectively utilizing &lt;code&gt;.nvmrc&lt;/code&gt; files and &lt;code&gt;package.json&lt;/code&gt; configuration, you can significantly enhance the consistency of your Node.js projects and save a precious time that would be spent.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>node</category>
      <category>npm</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Mastering Version Management in Node.js</title>
      <dc:creator>Felipe Rocha</dc:creator>
      <pubDate>Sun, 20 Oct 2024 14:20:31 +0000</pubDate>
      <link>https://forem.com/feliperocha93/mastering-version-management-in-nodejs-b4e</link>
      <guid>https://forem.com/feliperocha93/mastering-version-management-in-nodejs-b4e</guid>
      <description>&lt;p&gt;As developers, we frequently encounter projects that demand different Node.js versions. This scenario is a pitfall for both fresh and experienced developers who may not be regularly involved in Node.js projects: ensuring the correct Node.js version is used for each project.&lt;/p&gt;

&lt;p&gt;Before installing dependencies and running a project, it's crucial to verify that your Node.js version matches or is at least compatible with the project's requirements. Failure to do so can result in a barrage of errors and warnings in your terminal, consuming valuable time in troubleshooting. Fortunately, there's a solution: version managers.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a Version Manager?
&lt;/h2&gt;

&lt;p&gt;A version manager is a software tool that allows you to effortlessly install, switch between, and remove different versions of programming languages. Here are some popular examples for various languages:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Node.js&lt;/strong&gt;: nvm&lt;br&gt;
&lt;strong&gt;Ruby&lt;/strong&gt;: rbenv, rvm, chruby&lt;br&gt;
&lt;strong&gt;Java&lt;/strong&gt;: jabba&lt;br&gt;
&lt;strong&gt;PHP&lt;/strong&gt;: phpenv, phpbrew&lt;br&gt;
&lt;strong&gt;Python&lt;/strong&gt;: pyenv&lt;br&gt;
&lt;strong&gt;Multi-language&lt;/strong&gt;: asdf (command-line tool)&lt;/p&gt;
&lt;h2&gt;
  
  
  The Node Version Manager
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;nvm, specifically designed for Node.js, allows you to seamlessly install and switch between different Node.js versions directly from your command line. It's a per-user installation and works with various POSIX-compliant shells (sh, dash, ksh, zsh, bash) on Unix-based systems, macOS, and Windows WSL.&lt;/em&gt;¹&lt;/p&gt;

&lt;p&gt;Let's explore some use cases from the &lt;strong&gt;official nvm repository&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;node &lt;span class="nt"&gt;-v&lt;/span&gt;
v16.9.1

&lt;span class="nv"&gt;$ &lt;/span&gt;nvm use 14
Now using node v14.18.0 &lt;span class="o"&gt;(&lt;/span&gt;npm v6.14.15&lt;span class="o"&gt;)&lt;/span&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;node &lt;span class="nt"&gt;-v&lt;/span&gt;
v14.18.0

&lt;span class="nv"&gt;$ &lt;/span&gt;nvm &lt;span class="nb"&gt;install &lt;/span&gt;12
Now using node v12.22.6 &lt;span class="o"&gt;(&lt;/span&gt;npm v6.14.5&lt;span class="o"&gt;)&lt;/span&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;node &lt;span class="nt"&gt;-v&lt;/span&gt;
v12.22.6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we see &lt;strong&gt;how to&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;Check the current Node.js version (&lt;code&gt;node -v&lt;/code&gt;).&lt;br&gt;
Switch to Node.js version 14 (&lt;code&gt;nvm use 14&lt;/code&gt;).&lt;br&gt;
Verify the switched version (&lt;code&gt;node -v&lt;/code&gt;).&lt;br&gt;
Install Node.js version 12 (&lt;code&gt;nvm install 12&lt;/code&gt;).&lt;br&gt;
Confirm the newly installed version (&lt;code&gt;node -v&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;In the next article, I'll provide a straightforward guide on how to install &lt;strong&gt;nvm&lt;/strong&gt; and effectively define specific Node.js versions using &lt;code&gt;.nvmrc&lt;/code&gt; files.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Utilizing a version manager for your projects is a critical time-saving strategy that ensures smooth development workflows. It's an essential tool for any developer's toolbox.&lt;/p&gt;

&lt;p&gt;What's your preferred solution for handling these situations? Share your thoughts in the comments below!&lt;/p&gt;




&lt;h4&gt;
  
  
  References
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://github.com/nvm-sh/nvm" rel="noopener noreferrer"&gt;https://github.com/nvm-sh/nvm&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>webdev</category>
      <category>node</category>
      <category>javascript</category>
      <category>cli</category>
    </item>
    <item>
      <title>8 Most Valuable Lessons I Learned in 5 Years as a Software Engineer</title>
      <dc:creator>Felipe Rocha</dc:creator>
      <pubDate>Mon, 09 Sep 2024 21:08:27 +0000</pubDate>
      <link>https://forem.com/feliperocha93/8-most-valuable-lessons-i-learned-in-5-years-as-a-software-engineer-35g2</link>
      <guid>https://forem.com/feliperocha93/8-most-valuable-lessons-i-learned-in-5-years-as-a-software-engineer-35g2</guid>
      <description>&lt;p&gt;I recently shared an article that I found incredibly inspiring. It featured a young software engineer reflecting on the key lessons they had learned after 35 years in the profession.&lt;/p&gt;

&lt;p&gt;Reading that piece made me ponder the lessons I might share when my time comes. But before that, I honestly wondered if my time would ever come. A 35-year career is quite a long journey, and since I started a bit later in life, at 26, I'd be over 60 by the time I reached that milestone.&lt;/p&gt;

&lt;p&gt;Perhaps I won't make it that far, or perhaps I will and simply forget to write about it. So, I figure it's best to start putting my thoughts down now, so that my future self can simply review and refine them. It's a way to lighten the load for my future self. Let's dive in:&lt;/p&gt;

&lt;h4&gt;
  
  
  Life is More Than Coding
&lt;/h4&gt;

&lt;p&gt;Life extends beyond coding. To be a productive developer, you need to maintain both physical and mental well-being. Over these past 5 years, I've met great engineers with diverse hobbies that help them stay healthy. Soccer players, rock climbers, weightlifters, runners, swimmers, those who play volleyball or practice jiu-jitsu. Some also frequently attend parties, music concerts, enjoy the beach, or travel to exciting destinations.&lt;/p&gt;

&lt;h4&gt;
  
  
  The Profession is More Than Coding
&lt;/h4&gt;

&lt;p&gt;Even the profession itself encompasses much more than coding. You need to understand your company's business and your team's goals. It's crucial to understand how your work contributes to achieving these objectives. As you gain experience, you'll share your knowledge with less experienced engineers or even guide another developer through a project they've never worked before. After spending some time at the company, you'll be recognized as an engineer with deep insights into the business. People from other departments will seek your perspective as an engineering expert.&lt;/p&gt;

&lt;h4&gt;
  
  
  It's Not Enough to Do, You Have to Show
&lt;/h4&gt;

&lt;p&gt;It's not about boasting about your accomplishments. It's about ensuring that everyone understands what you can deliver, the challenges you've overcome, and your resilience as a software engineer. Maintain clear and active communication about your tasks, both in writing and verbally. And lastly, continue to track the impact of your work after the release.&lt;/p&gt;

&lt;h4&gt;
  
  
  Together We Go Further
&lt;/h4&gt;

&lt;p&gt;We all know that people are paid to do their jobs, but they'll do them better and faster if they like you. Build positive relationships with others, respond to them as promptly as you'd like to be responded to. Treat them the way you'd want to be treated. And lastly, work correctly. I don't know anyone who hasn't built strong professional relationships by following this principle.&lt;br&gt;
In fact, I landed my current job building good relationships. A former manager of mine was hiring and knew I was seeking a new challenge. He contacted me and soon I was hired..&lt;/p&gt;

&lt;h4&gt;
  
  
  You Drive Your Career
&lt;/h4&gt;

&lt;p&gt;Managers and more experienced engineers can provide guidance to help you reach your goals. However, they won't do the work for you. Remember, this is YOUR career, YOUR future, and it will likely unfold far away from them. So, don't leave it in someone else's hands. Develop a solid career plan and review it periodically. Within your current company or team, seek out opportunities that align with your learning objectives. If you feel stagnant, ask for feedback, re-evaluate your plan, and ensure you're actively working towards your goals. Don't hesitate to revise your plan as needed, but never blame others for your lack of progress.&lt;/p&gt;

&lt;h4&gt;
  
  
  Deadlines are Dangerous
&lt;/h4&gt;

&lt;p&gt;Early in my career, I started estimating deadlines before I truly knew how. I vividly recall being introduced to planning poker and assigning estimates to tasks in the most random way imaginable. If you're unfamiliar with it, I strongly recommend reading the chapter on estimation in "The Pragmatic Programmer" or at least an article inspired by it. Missed deadlines are like snowballs of problems for the team.&lt;/p&gt;

&lt;h4&gt;
  
  
  Be a Problem Solver
&lt;/h4&gt;

&lt;p&gt;I believe this is the hardest skill to master, yet it's the one that can propel you to the next level the fastest. We're paid to solve problems, not to create them. How about trying to resolve your own issues before complaining in a daily meeting? Take initiative and do what needs to be done. If you need help unblocking your tasks, ask for it as soon as possible. If you're waiting too long for a response, politely follow up with the person. Having issues with another developer? Reach out to them and align your work. No one is reviewing your pull requests? Don't wait too long; send a gentle reminder. It's all about perspective. Approach problems as challenges and savor the endorphin rush of overcoming them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;I'm convinced that articles like this serve as invaluable compasses, guiding us on our professional journeys. That's precisely why I'm constantly seeking out the wisdom and insights of seasoned engineers.&lt;/p&gt;

&lt;p&gt;The most profound aspect of these lessons lies in their universality. They transcend the boundaries of software engineering, offering profound insights applicable to both our personal lives and a multitude of other professions. These lessons encapsulate timeless principles that empower us to navigate challenges, foster growth, and achieve success in all facets of our lives.&lt;/p&gt;

&lt;p&gt;Let me know if you have any other sections you'd like me to refine or any further questions!&lt;/p&gt;

</description>
      <category>career</category>
      <category>development</category>
      <category>productivity</category>
      <category>programming</category>
    </item>
    <item>
      <title>8 Real-Life Shell Functions to Boost Your Productivity</title>
      <dc:creator>Felipe Rocha</dc:creator>
      <pubDate>Thu, 15 Aug 2024 21:35:51 +0000</pubDate>
      <link>https://forem.com/feliperocha93/8-real-life-shell-functions-to-boost-your-productivity-4k1j</link>
      <guid>https://forem.com/feliperocha93/8-real-life-shell-functions-to-boost-your-productivity-4k1j</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Shell functions are &lt;strong&gt;powerful tools&lt;/strong&gt; that allow you to automate tasks, streamline your workflow, and &lt;strong&gt;boost productivity&lt;/strong&gt; by reducing repetitive manual work.&lt;/p&gt;

&lt;p&gt;Many developers are familiar with shell scripting, but it’s not common to see them using it to enhance their productivity. &lt;em&gt;Perhaps all that's missing is a bit of creativity.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In this article, I’m sharing &lt;strong&gt;8 functions&lt;/strong&gt; that I use daily to help with my work tasks. I hope they inspire you to create your own functions and boost your productivity. For the examples below, I'm using ZSH.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feyzkssy5dsiy1fj34ylu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feyzkssy5dsiy1fj34ylu.png" alt="Image description" width="680" height="460"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  1: Push in Dev Environment
&lt;/h3&gt;

&lt;p&gt;It's common for me to need to test my local branch in the development environment. To switch and merge branches faster, I’m currently using the following function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;function &lt;/span&gt;merge_dev &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="nv"&gt;BRANCH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;git branch &lt;span class="nt"&gt;--show-current&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  git checkout dev&lt;span class="p"&gt;;&lt;/span&gt;
  git fetch &lt;span class="nt"&gt;-pa&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  git reset &lt;span class="nt"&gt;--hard&lt;/span&gt; origin/dev&lt;span class="p"&gt;;&lt;/span&gt;
  git merge &lt;span class="nv"&gt;$BRANCH&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nb"&gt;echo &lt;/span&gt;Done! Now, finish the merge and push the changes.
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;git push&lt;/code&gt; command is intentionally left out of the &lt;em&gt;merge_dev&lt;/em&gt; function because I often need to resolve conflicts before pushing, so I decided to keep it separate.&lt;/p&gt;

&lt;h3&gt;
  
  
  2: Git Rebase
&lt;/h3&gt;

&lt;p&gt;Similar to &lt;strong&gt;Function 1&lt;/strong&gt;, this function is useful when I need to switch branches and run another &lt;em&gt;git command&lt;/em&gt;. To make this process faster, I created the &lt;em&gt;rebase&lt;/em&gt; function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;function &lt;/span&gt;rebase &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;BRANCH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;git branch &lt;span class="nt"&gt;--show-current&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    git checkout &lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    git pull&lt;span class="p"&gt;;&lt;/span&gt;
    git checkout &lt;span class="nv"&gt;$BRANCH&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    git rebase &lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;# usage example&lt;/span&gt;
rebase master
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3: Shortcut for ZSH Config Files
&lt;/h3&gt;

&lt;p&gt;I’m always creating new functions or updating old ones, and I never seem to remember the path to my &lt;em&gt;.zshrc&lt;/em&gt; files 😂.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;function &lt;/span&gt;config &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="c"&gt;# Check if parameter is null&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nt"&gt;-z&lt;/span&gt; &lt;span class="nv"&gt;$1&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then 
    &lt;/span&gt;code &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$HOME&lt;/span&gt;&lt;span class="s2"&gt;/.zshrc"&lt;/span&gt;
    &lt;span class="k"&gt;return
  fi

  case&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="k"&gt;in
    &lt;/span&gt;&lt;span class="nb"&gt;alias&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
      code &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$HOME&lt;/span&gt;&lt;span class="s2"&gt;/CUSTOM_ZSH/.alias.sh"&lt;/span&gt;
    &lt;span class="p"&gt;;;&lt;/span&gt;
    func &lt;span class="p"&gt;)&lt;/span&gt;
      code &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$HOME&lt;/span&gt;&lt;span class="s2"&gt;/CUSTOM_ZSH/.functions.sh"&lt;/span&gt;
    &lt;span class="p"&gt;;;&lt;/span&gt;
    &lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt; is not a valid parameter for config function"&lt;/span&gt;
    &lt;span class="p"&gt;;;&lt;/span&gt;
  &lt;span class="k"&gt;esac&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;# usage example&lt;/span&gt;
config func
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4: Set Upstream and Open Repo
&lt;/h3&gt;

&lt;p&gt;It’s very annoying to try pushing a branch that doesn't exist in the remote repository. To save myself from this hassle, I use the &lt;em&gt;gpp&lt;/em&gt; function to automatically add the &lt;code&gt;--set-upstream&lt;/code&gt; flag when needed. I also open the remote repo in a browser because I usually create a PR after pushing a new branch.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;function &lt;/span&gt;gpp &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="nv"&gt;BRANCH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;git branch &lt;span class="nt"&gt;--show-current&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nv"&gt;ORIGIN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"origin"&lt;/span&gt;

  git push
  &lt;span class="nv"&gt;RESULT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$?&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nv"&gt;$RESULT&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; 0 &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nv"&gt;GIT_PUSH_OUTPUT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;git push &lt;span class="nt"&gt;--set-upstream&lt;/span&gt; &lt;span class="nv"&gt;$ORIGIN&lt;/span&gt; &lt;span class="nv"&gt;$BRANCH&lt;/span&gt; 2&amp;gt;&amp;amp;1&lt;span class="si"&gt;)&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$GIT_PUSH_OUTPUT&lt;/span&gt;

    &lt;span class="nv"&gt;REPO_NAME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;pwd&lt;/span&gt; | &lt;span class="nb"&gt;awk&lt;/span&gt; &lt;span class="nt"&gt;-F&lt;/span&gt;/ &lt;span class="s1"&gt;'{print $NF}'&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
    open &lt;span class="s2"&gt;"https://github.com/feliperocha93/&lt;/span&gt;&lt;span class="nv"&gt;$REPO_NAME&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
  &lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  5: Fast PR
&lt;/h3&gt;

&lt;p&gt;Building on &lt;strong&gt;Function 4&lt;/strong&gt; and taking advantage of ZSH aliases, when I need to open a PR with a single commit, I save time using the &lt;em&gt;fast_pr&lt;/em&gt; function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;function &lt;/span&gt;fast_pr &lt;span class="o"&gt;{&lt;/span&gt;
  gaa&lt;span class="p"&gt;;&lt;/span&gt;
  gcmsg &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  gpp&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;# usage example&lt;/span&gt;
fast_pr &lt;span class="s2"&gt;"chore: update zsh function"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  6: Get and Export Credentials
&lt;/h3&gt;

&lt;p&gt;This is probably the most complex and time-saving function in this series of &lt;strong&gt;8 functions&lt;/strong&gt;. The variables are somewhat masked since it’s not necessary to show their real names, but the example should be sufficient to explain the concept.&lt;/p&gt;

&lt;p&gt;Basically, the application I usually run locally accesses several databases that require authentication. The application retrieves the credentials from environment variables.&lt;/p&gt;

&lt;p&gt;To handle this, the &lt;em&gt;get_credentials&lt;/em&gt; function authenticates me via the command line and saves the credentials as environment variables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;function &lt;/span&gt;get_credentials &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="c"&gt;# some command to get credentials&lt;/span&gt;
  &lt;span class="nv"&gt;credentials&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;foo &lt;span class="nt"&gt;--bar&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 

  &lt;span class="c"&gt;# in this example, credentials is a string like &lt;/span&gt;
  &lt;span class="c"&gt;# username:username password:password &lt;/span&gt;
  &lt;span class="c"&gt;# and awk method are extracting the value&lt;/span&gt;

  &lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;USERNAME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$credentials&lt;/span&gt; | &lt;span class="nb"&gt;awk&lt;/span&gt; &lt;span class="nt"&gt;-F&lt;/span&gt;&lt;span class="s1"&gt;'username: '&lt;/span&gt; &lt;span class="s1"&gt;'{print $2}'&lt;/span&gt; | &lt;span class="nb"&gt;tr&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s1"&gt;'[:space:]'&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;PASSWORD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$credentials&lt;/span&gt; | &lt;span class="nb"&gt;awk&lt;/span&gt; &lt;span class="nt"&gt;-F&lt;/span&gt;&lt;span class="s1"&gt;'password: '&lt;/span&gt; &lt;span class="s1"&gt;'{print $2}'&lt;/span&gt; | &lt;span class="nb"&gt;tr&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s1"&gt;'[:space:]'&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;REDIS_HOST&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;localhost
  &lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;REDIS_PORT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;6379

  &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$USERNAME&lt;/span&gt; &lt;span class="nv"&gt;$PASSWORD&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  7: Install Dependencies
&lt;/h3&gt;

&lt;p&gt;When working on a project after a long time, it's important to update the dependencies to avoid some incompatibility problems during development. So I always try to keep my local branch up to date with master branch.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;function &lt;/span&gt;start &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="nv"&gt;BRANCH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;git branch &lt;span class="nt"&gt;--show-current&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;function &lt;/span&gt;update_and_install &lt;span class="o"&gt;{&lt;/span&gt;
    git pull&lt;span class="p"&gt;;&lt;/span&gt;
    nvm use&lt;span class="p"&gt;;&lt;/span&gt;
    npm ci&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nv"&gt;$BRANCH&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="s1"&gt;'master'&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;git checkout master&lt;span class="p"&gt;;&lt;/span&gt;
    update_and_install&lt;span class="p"&gt;;&lt;/span&gt;
    git checkout &lt;span class="nv"&gt;$BRANCH&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;fi

 &lt;/span&gt;update_and_install&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  BONUS: Alias
&lt;/h3&gt;

&lt;p&gt;I know aliases aren't exactly functions, but they can help you save some time. In the examples below, I use some aliases to execut frequent commands with short words.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# browse to folder&lt;/span&gt;
&lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;deployments&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"cd ~/Documents/deployments"&lt;/span&gt;
&lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;feliperocha&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"cd ~/Documents/feliperocha"&lt;/span&gt;

&lt;span class="c"&gt;# browse to folder and list projects&lt;/span&gt;
&lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;projects&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"cd &lt;/span&gt;&lt;span class="nv"&gt;$HOME&lt;/span&gt;&lt;span class="s2"&gt;/Documents/projects &amp;amp;&amp;amp; ls -a"&lt;/span&gt;

&lt;span class="c"&gt;# open a specific folder&lt;/span&gt;
&lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;XPTO&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"cd ~/Documents/XPTO; open ."&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Thank you for reading until the end. My intetion in sharing these functions to open your mind and spark your criativity to create your own functions and boost your daily productivy.&lt;/p&gt;

&lt;p&gt;Leave a comment below sharing which function was your favorite or post your own.&lt;/p&gt;

&lt;p&gt;Bests regards,&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>shell</category>
    </item>
  </channel>
</rss>
