Setting up
Python venv
On newer systems system-wide install of packages is not allowed. To solve:
- create
~/venv
- automatically activate venv in
.bashrc
source ~/venv/bin/activate
# optional: hide (venv) from prompt
export VIRTUAL_ENV_DISABLE_PROMPT=true
Bash helpers
You don't need to remember (or type) long commands every time.
A simple solution is to create bash_helpers.sh
file and source it for quick access to
handy functions.
Docker-related Functions
-
attach
Attach to a running Docker container. -
python-dev
Enter a development shell in a Docker container using a Python image from a specified registry. -
docker_stop_all
(alias) Stop all running Docker containers.
CAN and Serial Functions
-
canview
Launch CAN viewer for the given interface (default:slcan0
). -
repl
Connect to a serial device using Picocom. Uses$AMPY_PORT
or defaults to/dev/ttyACM0
.
SSHFS and Network Functions
-
mount_ssh
Mount a remote directory over SSHFS. Takes a remote path as an argument. -
open_ports
(alias) Show open network ports currently in use.
Virtual Environment and Python-related Functions
venv
(alias) Start Python virtual environment.
Automation script
run this script to set up automatically
#!/bin/bash
set -e
# Initialize the environment
# create python virtual environment ~/venv if not exists
if [ ! -d ~/venv ]; then
echo "Creating python virtual environment"
python3 -m venv ~/venv
fi
# add virtual environment to .bashrc if not exists
if ! grep -q "source ~/venv/bin/activate" ~/.bashrc; then
echo "Adding virtual environment to .bashrc"
echo "source ~/venv/bin/activate" >> ~/.bashrc
fi
# install docker if not exists
if ! command -v docker &> /dev/null; then
echo "Installing docker"
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG docker $USER
rm get-docker.sh
fi
# set custom prompt
if ! grep -q "export PS1" ~/.bashrc; then
echo "Setting custom prompt"
echo 'export PS1="🥝 \[\e[32m\]\u@\h\[\e[0m\]:\[\e[34m\]\w\[\e[0m\]\$ "' >> ~/.bashrc
fi
# get bash_helpers.sh if not exists
if [ ! -f ~/bash_helpers.sh ]; then
echo "Downloading bash_helpers.sh"
curl -fsSL https://docs.roxautomation.com/linux/bash_helpers.sh -o ~/bash_helpers.sh
# add bash_helpers.sh to .bashrc
echo "source ~/bash_helpers.sh" >> ~/.bashrc
fi
# activate the virtual environment
source ~/venv/bin/activate