Why did I add a Terminal on my website (and how you can do it too)?

Bony Roopchandani
Jan 11 · 2 min read
Image for post
Image for post

Being a Software Engineer, I always had this idea to have some kind of element on my personal website which not only showcases my skills but also gives it a bit of “nerd” touch. So, I went ahead and built a static Terminal having custom commands.

Image for post
Image for post
https://bonyroopchandani.com

This React component is also published as an NPM package for anyone who wants to add it to their app.

Show me the details

Installing

Install it using NPM npm install react-terminal or YARN yarn add react-terminal.

Usage

Just declare the commands object (key-value pair where value can be either a string or callback) and pass it as props to the component:

import { ReactTerminal } from "react-terminal";

function MyComponent(props) {
// Define commands here
const commands = {
whoami: "jackharper",
cd: (directory) => `changed path to ${directory}`
};

return (
<ReactTerminal
commands={commands}
/>
);
}

Also, make sure to wrap the application mount point around TerminalContextProvider. This retains the state even when the component is unmounted and then mounted back:

import { TerminalContextProvider } from "react-terminal";

ReactDOM.render(
<TerminalContextProvider>
<App/>
</TerminalContextProvider>,
rootElement
);

For a full list of props, please check the readme.

Demo:

codesandbox

If you found a bug in this library, please file a GitHub issue here.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store