I want to write a command opening a a Jupyter Notebook in firefox but I am struggling with bash.
# This is what I want to achieve:
$ firefox --new-tab localhost:8888/tree/notebooks/my_notebook.ipynb
So far I can echo the url to the notebook:
$ cd notebooks
$ var="my_notebook.ipynb"
$ echo localhost:8888/tree/${PWD}/${var} | sed 's/\/home\/johndoe\///g'
localhost:8888/tree/Dropbox/notebooks/my_notebook.ipynb
How to pass the string above to a firefox command? I tried to use command substitution $()
, piping |
, quotes, but without success.
I am assuming that jupyter-notebook is running from my home directory /home/johndoe
. Bonus points if you can pass $HOME
to that sed
command
SOLUTION: I created a function (not an alias) that opens Jupyter Notebook in firefox on a file or a directory as follows:
nb() {
firefox --new-tab "$(echo localhost:8888/tree/$(realpath --relative-to="$HOME" "${PWD}")/$1)" &
}