Slow Times, 9/100 Days of Code
The best part of programming is those slow moments of realization
I worked on a bash script for running a program via the terminal. I started by creating two variables in my bash profile.
The first would change to a parent directory of another directory containing Cypress. The second would go deeper into the child directory to open Cypress. When executed one by one, this worked no problem. However, that’s the problem. I used TWO variables to perform ONE task. But before I figured this out, I did a fair bit of head banging.
I tried piping the output of the first variable into the second, spacing them out when entering them into the terminal. Eventually, I gave up on using the terminal for this task. I resorted to scripting. I figured if I wrote a script that used both variables in succession, I could get it to work. More head banging, and still nothing. The day ended, and I decided to leave this issue alone for the next day.
The next day, I’m stretching after a run when it finally hits me, “Why not use one variable?” It was obvious! I laughed to myself for a moment. See, instead of executing cyNavi to navigate to one directory, and cyStart to navigate/start Cypress, I could just type the entire directory to Cypress.
I played around some more and found I could also edit the cyNavi string and append it at the start of the cyStart string to achieve the same result.
This was a fun exercise. Took a little while, but I figured it out. Now I can start cypress on a whim before you can say Robert is your father’s brother, and Bethany is your mother’s sister…or so I thought
Turns out this opens Cypress, but it doesn’t include any of my scripts! It appears to open to some default setting where I only see sample scripts that came with the installation. In order to access my files, I have to start Cypress from the installation directory. Additionally, Cypress lets users add a script to start it using the Node Package Manager.
To remedy this, I wrote a script that changes to the installation directory and invokes the open command to run Cypress.
The script is convenient because it can run from any directory and it opens Cypress with my project files intact.