Skip to content

Commit

Permalink
feat: Release article 47
Browse files Browse the repository at this point in the history
Release another article, and a bunch of small fixes.
Including supporting archetypes and taskfiles.
  • Loading branch information
hmajid2301 committed Oct 16, 2022
1 parent 86168b1 commit 40a480e
Show file tree
Hide file tree
Showing 11 changed files with 240 additions and 11 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,31 @@
My personal website and blog using the [PaperModX](https://github.com/reorx/hugo-PaperModX) theme and
built with hugo.

## Usage

> You need [go-task](https://taskfile.dev/installation/) installed
```bash
go-task start_server

# To see all talks
go-task --list-all
```

### New Content

To create a new post:

```
go-task new_post ARTICLE_NAME=a-new-post
```

To create a new talk:

```
go-task new_talk TALK_NAME=a-talk-post
```

## Older Versions

- [Version 1](https://v1.haseebmajid.dev)
Expand Down
14 changes: 13 additions & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
version: "3"

tasks:
start:
start_docker:
cmds:
- docker compose up --build

start_server:
cmds:
- hugo server -D

new_post:
cmds:
- hugo new --kind post-bundle posts/{{now | date "1995-01-23"}}-{{.ARTICLE_NAME}}
env:
ARTICLE_NAME: foo

new_talk:
cmds:
- hugo new --kind talk-bundle talks/{{.TALK_NAME}}
env:
TALK_NAME: foo
6 changes: 0 additions & 6 deletions archetype/post.md

This file was deleted.

Empty file.
7 changes: 7 additions & 0 deletions archetypes/post-bundle/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: {{ replace .Name "-" " " | title }}
date: {{ dateFormat "1995-01-23" .Date }}
draft: true
tags:
-
---
4 changes: 2 additions & 2 deletions archetype/talk.md → archetypes/talk-bundle/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "{{ replace .Name "-" " " | title }}
date: {{ .Date }}
title: {{ replace .Name "-" " " | title }}
date: {{ dateFormat "1995-01-23" .Date }}
ShowToc: false
ShowReadingTime: false
ShowWordCount: false
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
---
title: How to Manage Your Dotfiles With Dotbot
date: 2022-10-15
tags:
- dotfiles
- dotbot
- git
---

If you're like me you find yourself moving between multiple systems. Whether that be between my personal
desktop and my work laptop or distro hopping on Linux. See relevant meme below:

![Distro Hopping Meme](images/distro_hopping.jpg)

{{< admonition type="info" title="What are dotfiles?" details="false" >}}
Many tools/program store their configuration files as files on your machine.
For example on Linux you will often find these in `~/.config` directory.

Some common examples of dotfiles:

- .vimrc
- .bashrc
- .gitconfig
{{< /admonition >}}

I wanted to find an easy way to manage my dotfiles and share them between mutiple systems.
I also wanted a easy way to install software/tools I used between my systems.
Introducing [DotBot](https://github.com/anishathalye/dotbot), a tool that provides an easy
way to manage our dotfiles using VCS (git).

## How does it work?

Dotbot works by creating symlinks between files in your git repo i.e `~/dotfiles/bashrc -> ~/.bashrc`.
So this means if we edit either file it will edit in both places. Typically I will edit the files in the dotfiles repo.
You can then commit and push your changes at your leisure.

{{< admonition type="info" title="Symlinks" details="false" >}}
A symlink or a Symbolic Link is basically a shortcut to another file. It is a file that points to another file.
{{< /admonition >}}

## Why manage dotfiles with git?

One of the main reasons to use VCS (git) to manage your dotfiles is very much the same reason you would use VCS normally.
It allows us to track the history of files. So we can see all the changes. Recently in my case I have been trying different shell.
I prefer to keep my dotfiles clean so when I stop using a shell I delete it. For example I swapped from zsh back to fish.
When I did this I deleted zsh config from my repo. If I ever need my zsh config back I can trawl through my git
history and retrieve it.

## Getting started

To get started with a brand new repository we can use the [`init-dotfiles` script](https://github.com/Vaelatern/init-dotfiles).

```bash
curl -fsSLO https://raw.githubusercontent.com/Vaelatern/init-dotfiles/master/init_dotfiles.sh
chmod +x ./init_dotfiles.sh
./init_dotfiles.sh

# Output

Welcome to the configuration generator for Dotbot
Please be aware that if you have a complicated setup, you may need more customization than this script offers.

At any time, press ^C to quit. No changes will be made until you confirm.

~/.dotfiles is not in use.
Where do you want your dotfiles repository to be? (~/.dotfiles)
Shall we add Dotbot as a submodule (a good idea)? (Y/n) y
Will do.
Do you want Dotbot to clean ~/ of broken links added by Dotbot? (recommended) (Y/n) y
I will ask Dotbot to clean.
I found ~/.profile, do you want to Dotbot it? (Y/n) y
Dotbotted!
I found ~/.bashrc, do you want to Dotbot it? (Y/n) y
Dotbotted!
Shall I make the initial commit? (Y/n) y
Will do.
```
This will create an empty dotfiles repo we can then configure as we need. Which will look a bit like this:
```
.
|-- bashrc
|-- dotbot
|-- install
|-- install.conf.yaml
`-- profile
```

### install.conf.yaml

The main config file `install.conf.yaml` is where we configure what files to copy and where to copy them.

The default version of this file may look something like this:

```yaml
- clean: ['~']
- link:
~/.profile: profile
~/.bashrc: bashrc
```

Let's break down what this file is doing;
#### clean
> Clean commands specify directories that should be checked for dead symbolic links. These dead links are removed automatically. Only dead links that point to somewhere within the dotfiles directory are removed unless the force option is set to true - Dotbot
So this means it will check our home directory for any dead symbolic links and remove them.
#### link
This is the main part of config file, it tells use where to move files in the dotfiles repo on our systems.
Where each line refers to a different file.
The profile file in the dotfiles repository will be copied to `~/.profile` location.
```yaml
~/.profile: profile
```
If you want to copy all the files in a folder you could so something like:
```yaml
- link:
~/.config/fish:
path: fish/**
glob: true
create: true
```
We will copy everything from the `fish` folder in the dotfiles repo to the `~/.config/fish` location.
- `path`: acts as a glob and will copy everything in this folder to the location we specified
- `glob`: if set to true will treat path as a glob
- `create`: if set to true will create the folders for us if they don't exist, for example `~/.config/fish` folder

#### shell

We can also add a shell field where you specify commands to run on the shell. If we want to install starship prompt
we could do something like this.

```yaml
- shell:
- command: curl -fsSL https://starship.rs/install.sh | sh -s -- --yes
stdout: true
stderr: true
```

We set stdout and stderr to true so we can see the command output.

## How to run it?

To "install" our dotfiles on our machine run the following command `./install`.
This wil run all the commands in order of the config file we defined above.

## Closing Thoughts

Now that we have a repo locally, we can push it to a remote git repository like Github or Gitlab.
That way if we lose access to our machine we still have our dotfiles backed up and safe.

![Dotfiles Meme](images/dotfiles.jpg)

## Appendix

- [My Dotfiles](https://gitlab.com/hmajid2301/dotfiles)
- [Doge Dotfiles Meme](https://github.com/PatentLobster/dotfiles)
16 changes: 15 additions & 1 deletion netlify.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
[build]
command = "hugo"
publish = "public"
command = "hugo --gc --minify"

[context.production.environment]
HUGO_VERSION = "0.104.3"
HUGO_ENV = "production"
HUGO_ENABLEGITINFO = "true"

[context.deploy-preview]
command = "hugo --gc --minify --buildFuture -b $DEPLOY_PRIME_URL"

[context.deploy-preview.environment]
HUGO_VERSION = "0.104.3"

[context.next.environment]
HUGO_ENABLEGITINFO = "true"
6 changes: 5 additions & 1 deletion static/admin/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@
# - { label: "Body", name: "body", widget: "markdown", modes: ["raw"] }
backend:
name: git-gateway
branch: initial # Branch to update (optional; defaults to master)
branch: main
media_folder: static/images
public_folder: /images
collections:
- name: "blog"
label: "Blog"
folder: "content/posts"
# Support Hugo page bundles that puts index.md and images in folders named by slug
path: "{{slug}}/index"
media_folder: "images"
public_folder: "images"
create: true
slug: "{{year}}-{{month}}-{{day}}-{{slug}}"
editor:
Expand Down

0 comments on commit 40a480e

Please sign in to comment.