Have you ever thought about having your own custom terminal portfolio with a set of commands that showcase your skills and accomplishments? I did, and I turned that idea into a reality. In this blog post, I'll walk you through my journey of building a terminal portfolio using Node.js, complete with auto-complete functionality, and then publishing it as an npm package.

Open terminal and run the command:

npx tajmirul

 

The Idea

The idea of a terminal portfolio struck me one day. I wanted a unique way to present my skills and experiences to others. A terminal portfolio seemed like a perfect choice, given my love for command-line interfaces. So, I set out to create one.

 

The Command List

The first step was to define the commands that my terminal portfolio would support. Here's a list of the available commands:

welcome     - Welcome message
help        - List available commands
exit        - Exit the terminal
clear       - Clear the terminal
echo        - Print a string to the terminal   
history     - See command history
whoami      - Print the current user
gui         - Visit my website
about       - Know more about me
education   - My education background
experience  - Experience i have gathered so far
skills      - My skills
projects    - View my projects
contact     - Contact Information
email       - Send me an email
resume      - Want to see my resume?

 

Input Challenges

The journey started with handling user input. I tried different libraries like prompt-sync and prompt-sync-plus, but they had their limitations. prompt-sync struggled with left and right arrow key support, and the up/down arrow keys didn't work as expected.

 

Embracing `readline`

I finally settled on using Node.js's built-in readline module along with process.stdin. This combination allowed me to capture user input effectively and handle command history, left/right editing, and more. However, one crucial piece was still missing: auto-completion.

 

Auto-Complete Functionality

With readline in place, I had to implement auto-complete functionality manually. This involved analyzing user input, comparing it with available commands, and suggesting completions. It was challenging, but it added a great user experience to my terminal portfolio.

 

Two Days of Hard Work

Building this terminal portfolio was no walk in the park. It took two days of hard work, debugging, and testing to get everything right. But the satisfaction of seeing it function as intended was worth every moment.

 

Publishing as an npm Package

Once I was satisfied with the output, I decided to share my terminal portfolio with the world. I followed the npm package publishing process, but there was a catch. When I ran npx tajmirul, it didn't work as expected. Instead, the index.js file opened in a text editor.

 

The Shebang Solution

After some research, I discovered the issue. To make an npm package executable with npx, I needed to add a shebang line at the top of my entry file (typically index.js). The shebang #!/usr/bin/env node tells the operating system to use the Node.js interpreter to run the script. This simple addition solved the problem.

 

Conclusion 

Building a terminal portfolio with custom commands and auto-complete functionality was a fun and educational journey. It taught me a lot about handling user input, creating a command-line interface, and publishing packages on npm. If you're interested in building your own terminal portfolio or command-line tool, I hope this story inspires you to take the plunge. Happy coding!

Technologies

  • Node js
  • Typescript

Say hello!

If you want to talk to me about something that could interest me or just want to say hi, you can send me an email at @tasmirolislam. My inbox is always open. I'll try my best to get back to you. You can also find me on Facebook.