Can you focus on work when owning Bitcoin?
Tags: shell, productivity, intermediate, bitcoin
Published: 2021-04-02 17:21:42

If you are here I am guessing that you too jumped on the `bitcoin` train and that's why you consume anything you can find on the subject, including this article. Yeah, you and me too, I got roped in after seeing this tweet from **Elon Musk**: 

[![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2nwsap4nqked3lb7ra9l.png)](https://twitter.com/elonmusk/status/1340581313406001153)

Because `bitcoin` is so volatile and valuable (for the moment) you can have huge swings within hours and if you want to do some trading during those peaks and valleys you inevitably get into constantly checking  websites or some live ticker app, or worse, you might even have push notifications enabled ... so you end up in distraction hell, just ask **Elon**.

## TL;DR version

_Can you focus on work when owning Bitcoin?_  
**YES you can!**  

Just take away all the unnecessary convoluted, distracting and time consuming steps. 

OK, so what did I do to remove this distraction? 

I made the conversion rate between `BTC` and `EUR` visible in my `BASH` prompt because, of course I did, I always have at least one instance open ( and probably so do you ):

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zxgreqk2ljp73bdb9304.png)

This allows me to have the information in the corner of my eye, bare bones with no distraction. I don't have any cognitive effort and I don't switch the context. 

To do this, I wrote a few lines of `SHELL` script and with it I can configure my prompt to display whatever I need: 
 - how much is my current portfolio worth?
 - how much is X amount worth? (when buying / selling)
 - it's extensible to other crypto currencies 
 - it's easy to setup
 - anyone can pick up where I left off

## The long(er) version

I tagged this article ( at least the hands on part ) as `intermediate`, assuming that you know the concepts used to build this: 

- what the `.bashrc` file is
- how the `$PS1` environment variable is constructed
- how to use the `curl` command
- how to use the `bc` command
- `shell` scripring

### Step 1 - teaching BASH a new trick

Extend the `.bashrc` file (or any other file that your BASH consumes when starting up):  

```bash
mbtc () 
{
    KEUR=$(curl -s 'https://blockchain.info/tobtc?currency=EUR&value=1000')
    MINE="${1}" # amount of BTC you want to monitor
    CALC=$(echo "scale=3; $MINE/$KEUR" | bc -q)
    echo "${CALC}k €"
}
```  

Now your `linux` knows a new **_"command"_** called `mbtc` that accepts a parameter, this is the amount of `BTC` you want converted into `KILO EUROS` or `k €`  

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x4pbsk5lc5766b1535w9.png)

By adjusting the `value` parameter from the curl GET call to the public **[blockchain.info API](https://blockchain.info/tobtc?currency=EUR&value=1000)** you can transform other quantities, just be careful to adjust the   calculation string that is later passed to `bc`

### Step 2 - start BTC/EUR monitoring 

Check your current `$PS1` variable value: 

`echo $PS1`

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/la7euftxuj522c654y1h.png)

Create a file with the amount of `BTC` you want to monitor in your prompt: 

`echo "0.1234" > ~/btc.count`

Now redefine the `PS1` variable also by editing the `~/.bashrc` file, by adding a `subshell` call inside of the existing prompt:

`($(mbtc $(cat ~/btc.count)))`


 ![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5a2ihqfrkhb7c16ae26i.png)
 
### What next ?

Now you can rest assured, you will always know the up to date value of a Bitcoin or any other amount you want to monitor, just write the value in the  `~/btc.count`

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/perax4u6vnsft8ww034t.png)

Of course these concepts work just as well with any other `shell` implementation, you just need to edit the corresponding equivalent files.

All that is left for me to do is to wish you happy monitoring! Let me know if you were able to use this or if you were able to enhance or build something completely new on top of this. 

\#staysafe \#peace \#coderforever

Vio.