🏠 Personal dotfiles for Linux and Windows OS.
mkdir ~/dotfiles# initialize git bare repo in ~/dotfiles
git init --bare# Linux/Unix
echo "alias config='git --git-dir=$HOME/dotfiles --work-tree=$HOME'" >> $HOME/.bashrc- Add that your source repository ignores the folder where you'll clone it, so that you don't create weird recursion problems:
# Create this .gitignore in `$HOME`
echo "dotfiles" >> .gitignoreTo make custom PowerShell aliases persistent, you should add them to your PowerShell profile. Here's how to do it:
⚡ Note: Open PowerShell as adminstrator.
- First, check if you already have a PowerShell profile:
Test-Path $PROFILE- If it returns False, create a new profile (returns true then follow skip this step):
New-Item -Path $PROFILE -Type File -Force- Open your PowerShell profile in a text editor (like vim):
notepad $PROFILE
- Add your custom aliases to the profile file. For example:
function config {
git --git-dir="$HOME\dotfiles" --work-tree="$HOME" $args
}-
Save the file and close the editor.
-
Reload your PowerShell profile:
. $PROFILENow you can use config in PowerShell just like you would use config in Linux/Unix. For example:
config status
config add .bashrc
config commit -m "Update .bashrc"- Run command to config Untrack file in git
config config --local status.showUntrackedFiles noIf you already store your configuration/dotfiles in a Git repository, on a new system you can migrate to this setup with the following steps:
- Before the installation make sure you have committed the alias to your
.bashrc,.zshandpowershell:
# Linux/Unix
alias dotfiles='git --git-dir=$HOME/dotfiles/ --work-tree=$HOME'
# Windows PowerShell
function config {
git --git-dir="$HOME\dotfiles" --work-tree="$HOME" $args
}- Add that your source repository ignores the folder where you'll clone it, so that you don't create weird recursion problems:
# Create this .gitignore in `$HOME`
echo "dotfiles" >> .gitignore- Now clone your dotfiles into a bare repository in a "dotfiles" folder of your
$HOME:
git clone --bare https://github.com/chamannarved/dotfiles.git $HOME/dotfiles- Define the alias in the current shell scope:
alias config='git --git-dir=$HOME/dotfiles/ --work-tree=$HOME'- Checkout the actual content from the bare repository to your
$HOME:
config checkout- The step above might fail with a message like:
error: The following untracked working tree files would be overwritten by checkout:
.bashrc
.gitignore
Please move or remove them before you can switch branches.
AbortingThis is because of $HOME folder might already have some stock configuration files that Git would overwrite. The solution is simple: back up the files if you care about them, and remove them if you don't care. I provide you with a possible rough shortcut to move all the offending files automatically to a backup folder:
mkdir -p .config-backup && \
config checkout 2>&1 | egrep "\s+\." | awk {'print $1'} | \
xargs -I{} mv {} .config-backup/{}- Re-run the checkout if you had problems:
config checkout- Set the flag
showUntrackedFilestonoon this specific (local) repository:
config config --local status.showUntrackedFiles no- You're done, from now on you can now type
configcommands to add and update your dotfiles:
config status
config add .vimrc
config commit -m "Add vimrc"
config add .bashrc
config commit -m "Add bashrc"
config pushAgain as a shortcut not to have to remember all these steps on any new machine you want to setup, you can create a simple script, store it as a GitHub snippet, create a short URL for it and call it like this:
curl -Lks <Github-snippet-link> | /bin/bashScript code
git clone --bare https://github.com/chamannarved/dotfiles.git $HOME/dotfiles
# Linux/Unix
echo "alias dotfiles='/usr/bin/git --git-dir=$HOME/dotfiles --work-tree=$HOME'" >> $HOME/.bashrc
mkdir -p .config-backup
config checkout
if [ $? = 0 ]; then
echo "Checked out dotfiles.";
else
echo "Backing up pre-existing dotfiles.";
config checkout 2>&1 | egrep "\s+\." | awk {'print $1'} | xargs -I{} mv {} .config-backup/{}
fi;
config checkout
config config status.showUntrackedFiles no