Linux Config to Git - Streamlining my workflow - part 1


Intro
Have you ever experienced the sinking feeling of losing your meticulously crafted Linux workspace? Whether it's a hardware failure, a new job, or simply a fresh machine, setting up your environment from scratch is a daunting task. I've spent countless hours painstakingly recreating my ideal setup, only to find lingering inconsistencies. To combat this, I'm embarking on a journey to version control my Linux configuration using Git. This series will document my progress, sharing tips and tricks along the way.
Target
The goal is to create a portable, version-controlled Linux environment that can be quickly replicated on any machine. By leveraging Git, I aim to minimize the frustration of setting up a new workspace.
Key Principles
Git as the Central Repository: Anything that can be comfortably stored in Git will be included.
Incremental Approach: Starting with
.zshrc
and gradually expanding to other configuration files.Security First: Only non-sensitive data will be committed to the repository.
Automation with Makefiles: Using Makefiles to ensure configuration files are consistently updated.
Continuous Improvement: This series will evolve as new ideas and challenges arise.
Start from Setting Up the Git Repository:
I began by creating a new repository on GitHub (tutaj dodaj link). Then, I cloned it locally and started adding the essential files.
I created a
terminal
folder to house my.zshrc
andshell.pre-oh-my-zsh
files. Initially, these files were empty.Next, I created a
Makefile
in the root directory.
Makefile
ZSHRC_SOURCE := ~/.zshrc
ZSHRC_TARGET := ./terminal/.zshrc
SHELL_PRE_OH_MY_ZSH_SOURCE := ~/.shell.pre-oh-my-zsh
SHELL_PRE_OH_MY_ZSH_TARGET := ./terminal/shell.pre-oh-my-zsh
.PHONY: all update-zshrc update-shell-pre-oh-my-zsh
all: update-zshrc update-shell-pre-oh-my-zsh
$(ZSHRC_TARGET): $(ZSHRC_SOURCE)
cp $(ZSHRC_SOURCE) $(ZSHRC_TARGET)
@echo "Updated .zshrc in project folder."
$(SHELL_PRE_OH_MY_ZSH_TARGET): $(SHELL_PRE_OH_MY_ZSH_SOURCE)
cp $(SHELL_PRE_OH_MY_ZSH_SOURCE) $(SHELL_PRE_OH_MY_ZSH_TARGET)
@echo "Updated shell.pre-oh-my-zsh in project folder."
What does the Makefile do
This Makefile
automates the process of copying your current .zshrc
and shell.pre-oh-my-zsh
configuration files into the project's terminal
directory. Here's a breakdown:
Variables:
ZSHRC_SOURCE
,ZSHRC_TARGET
,SHELL_PRE_OH_MY_ZSH_SOURCE
, andSHELL_PRE_OH_MY_ZSH_TARGET
define the paths to your configuration files..PHONY: Declares
all
,update-zshrc
, andupdate-shell-pre-oh-my-zsh
as phony targets, meaning they don't correspond to actual files.all: This target, when executed, runs both
update-zshrc
andupdate-shell-pre-oh-my-zsh
.update-zshrc and update-shell-pre-oh-my-zsh: These targets use the
cp
command to copy the configuration files from your home directory to the project'sterminal
directory. The@echo
command provides feedback on the update process.
Updating Files in the Repository
To update all files, simply run make
in the root directory. To update a specific file, use make update-zshrc
or make update-shell-pre-oh-my-zsh
.
Troubleshooting
If make
doesn't seem to do anything, it might be because the files in the repository are newer than your local configuration files. In that case, use touch ~/.zshrc
and touch ~/.shell.pre-oh-my-zsh
to update the timestamps of your local files. Then, run make
again.
Next Steps
In the upcoming parts of this series, I'll be:
Adding more configuration files and frequently used shell scripts.
Creating a script and alias to run
make all
from any terminal location and automatically create a pull request with the changes.
Stay tuned for more updates on my journey to a fully version-controlled Linux workspace!
Subscribe to my newsletter
Read articles from Przemysław Kozłowski directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
