DEV Community

Cover image for Why did I add a Terminal on my website (and how you can do it too)?
Bony Roopchandani
Bony Roopchandani

Posted on • Updated on

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

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.

Alt Text

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:

Link to Demo
Edit in CodeSandbox

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

Top comments (6)

Collapse
 
chillhumanoid profile image
Jonathan Thorne

So this adds a terminal, but a dev would need to code in any functionality? Not that that's an issue, and actually could be a ton of fun, but just making sure I understand this right

Collapse
 
bony2023 profile image
Bony Roopchandani

Yes Jonathan, you are right. And that was the whole idea of making this. A dev can code any custom command and provide it to the component and it will render it.

Collapse
 
jitheshkt profile image
Jithesh. KT

Cool component. However one doubt, How did you add URL to the terminal? for example for the command bony.resmue?

Collapse
 
drepram profile image
Andre Christoga Pramaditya

Hey, I'm seeing a goo for the sandbox embed, though the link you gave was right. Perhaps you should change the embedded preview.

Collapse
 
bony2023 profile image
Bony Roopchandani

Hi Andre, I think there's some issue rendering the codesandbox inside dev.to. I have added the edit button for now.

Collapse
 
mikgross profile image
Mikael

I built something like this in php back in the days. It was fun, but not so useful in terms of UX