Skip to content

Commit 6ba6c59

Browse files
committed
✨ dotfiles function
1 parent 41a1fc3 commit 6ba6c59

File tree

7 files changed

+50
-81
lines changed

7 files changed

+50
-81
lines changed

Makefile

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,33 @@
11
SHELL := /bin/bash
2+
MAKE_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
23
OS := $(shell uname -s)
34

45
##@ dotfiles
56

67
.PHONY: bootstrap
78
bootstrap: ## Initialize the project by running the bootstrap script.
8-
$(SHELL) ./bootstrap/bootstrap.sh
9+
$(SHELL) $(MAKE_DIR)/bootstrap/bootstrap.sh
910

1011
.PHONY: deps
1112
deps: ## Install dependencies for the project based on the OS.
1213
ifeq ($(OS),Linux)
13-
$(SHELL) ./bin/aptfile ./linux/Aptfile
14+
@echo "Installing packages from Aptfile 📦"
15+
$(SHELL) $(MAKE_DIR)/bin/aptfile $(MAKE_DIR)/linux/Aptfile
1416
else ifeq ($(OS),Darwin)
15-
brew bundle --file=./macos/Brewfile
17+
. ~/.shell_functions
18+
@echo "Installing packages from Brewfile 📦"
19+
brew bundle --file=$(MAKE_DIR)/macos/Brewfile
1620
else
17-
$(error Unsupported operating system - $(OS))
21+
@echo "Unsupported OS: $(OS)"
22+
exit 1
1823
endif
24+
@echo "Dependencies installed successfully 🎉"
1925

2026
.PHONY: sync
2127
sync: ## Update the project and its submodules.
28+
@echo "Updating dotfiles and its submodules 🔄"
2229
git pull --recurse-submodules --jobs=4
23-
24-
##@ development
25-
26-
.PHONY: fmt
27-
fmt: ## Run pre-commit hooks on all files.
28-
pre-commit run --all-files
29-
30-
.PHONY: docs
31-
docs: ## Serve the documentation locally.
32-
hatch run docs:serve --livereload
30+
@echo "Dotfiles synced successfully 🎉"
3331

3432
##@ general
3533

@@ -39,6 +37,20 @@ version: ## Show the version of the project.
3937
@git fetch --tags 2>/dev/null || true
4038
@echo "dotfiles $$(git describe --tags --abbrev=0)"
4139

40+
##################################################
41+
# dotfiles development - do not autodocument these
42+
##################################################
43+
44+
# Lint with pre-commit
45+
.PHONY: fmt
46+
fmt:
47+
pre-commit run --all-files
48+
49+
# Build the documentation
50+
.PHONY: docs
51+
docs:
52+
hatch run docs:serve --livereload
53+
4254
.DEFAULT_GOAL := help
4355
.PHONY: help
4456
help: ## Show this help message and exit.
@@ -47,4 +59,4 @@ help: ## Show this help message and exit.
4759
# - "##@" denotes a target category
4860
# - "##" denotes a specific target description
4961
###############################################
50-
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
62+
@awk 'BEGIN {FS = ":.*##"; printf "Usage:\n dotfiles \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

bootstrap/bootstrap.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ DEPENDENCIES=(
111111
zsh
112112
tar
113113
gh
114+
make
114115
)
115116

116117
function install_dependencies() {
@@ -131,6 +132,8 @@ function install_dependencies() {
131132
curl
132133
zsh
133134
tar
135+
make
136+
gh
134137
)
135138
else
136139
log_event "error" "No package manager detected"

docs/dotfiles/dependencies.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ respectively.
1010

1111
## Installation
1212

13-
The `dotfiles-deps` alias will install the right dependencies for
13+
The `dotfiles deps` command will install the right dependencies for
1414
the current operating system. See the [macOS](#macos) and [Linux](#linux)
1515
sections for the manual installation steps.
1616

1717
```shell
18-
dotfiles-deps
18+
dotfiles deps
1919
```
2020

2121
### Linux

docs/dotfiles/features.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ productive and enjoyable:
3535

3636
### Functions
3737

38+
#### Dotfiles Management
39+
40+
The `dotfiles` command is a wrapper around the `dotfiles` directory and provides
41+
a number of useful operations:
42+
43+
- `dotfiles sync`: Sync the dotfiles.
44+
- `dotfiles bootstrap`: Bootstrap the dotfiles.
45+
- `dotfiles deps`: Install dependencies from Brewfile or Aptfile.
46+
3847
#### Directory Operations
3948

4049
- `mkcd`: Create a directory and change to it.
@@ -44,17 +53,10 @@ productive and enjoyable:
4453

4554
#### Git Operations
4655

47-
- `dotfiles-git`: Run a git command in the dotfiles directory.
4856
- `check`: Checkout a branch.
4957
- `git-remove-deleted`: Remove branches that have been deleted.
5058
- `git-tree`: Display a tree considering `.gitignore`.
5159

52-
#### Dotfiles Management
53-
54-
- `dotfiles-sync`: Sync the dotfiles.
55-
- `dotfiles-bootstrap`: Bootstrap the dotfiles.
56-
- `dotfiles-deps`: Install dependencies from Brewfile or Aptfile.
57-
5860
#### Search Operations
5961

6062
- `f`: Find a file by name.

docs/dotfiles/installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ the steps below:
3434
1. Install any missing dependencies
3535

3636
```shell
37-
apt install -y git curl zsh tar gh
37+
apt install -y git curl zsh make tar gh
3838
```
3939

4040
2. Clone the repo to `~/.dotfiles`

docs/dotfiles/quickstart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Install `curl` / `wget` to download the installation script:
3434
## Install any missing [dependencies](dependencies.md)
3535

3636
```shell
37-
dotfiles-deps
37+
dotfiles deps
3838
```
3939

4040
## Set `zsh` as the default shell

shell/.shell_functions

Lines changed: 7 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,65 +3,17 @@
33
##########################################################
44

55
#############################################
6-
# dotfiles-git
6+
# dotfiles
77
# -------------------------------------------
8-
# Run a git command in the dotfiles directory
8+
# Run a make command in the dotfiles directory
99
#############################################
10-
dotfiles-git() {
10+
dotfiles() {
1111
local DOTFILES_DIR="${DOTFILES_DIR:-${HOME}/.dotfiles}"
12-
local GIT_COMMAND="git ${*}"
13-
log_event "info" "${PURPLE}[${DOTFILES_DIR}]${NO_COLOR} ${CYAN}${GIT_COMMAND}${NO_COLOR} 📂"
14-
runin "${DOTFILES_DIR}" "${GIT_COMMAND}"
15-
}
16-
17-
#############################################
18-
# dotfiles-sync
19-
# -------------------------------------------
20-
# Sync the dotfiles
21-
#############################################
22-
dotfiles-sync() {
23-
log_event "info" "Syncing dotfiles 🔄"
24-
dotfiles-git pull --recurse-submodules --jobs=4
25-
log_event "info" "Dotfiles synced successfully 🎉"
26-
}
27-
28-
#############################################
29-
# dotfiles-bootstrap
30-
# -------------------------------------------
31-
# Bootstrap the dotfiles
32-
#############################################
33-
dotfiles-bootstrap() {
34-
local DOTFILES_DIR="${DOTFILES_DIR:-${HOME}/.dotfiles}"
35-
bash "${DOTFILES_DIR}/bootstrap/bootstrap.sh"
36-
}
37-
38-
#############################################
39-
# dotfiles-deps
40-
# -------------------------------------------
41-
# Install dependencies from Brewfile or Aptfile
42-
#############################################
43-
dotfiles-deps() {
44-
local DOTFILES_DIR="${DOTFILES_DIR:-${HOME}/.dotfiles}"
45-
OS_NAME=$(uname -s)
46-
if [[ ${OS_NAME} == "Darwin" ]]; then
47-
if ! command -v brew &>/dev/null; then
48-
echo "Error: Homebrew is not installed."
49-
return 1
50-
fi
51-
log_event "info" "Installing packages from Brewfile 📦"
52-
brew bundle --file="${DOTFILES_DIR}/macos/Brewfile"
53-
elif [[ ${OS_NAME} == "Linux" ]]; then
54-
if ! command -v apt &>/dev/null; then
55-
echo "Error: apt is not installed."
56-
return 1
57-
fi
58-
log_event "info" "Installing packages from Aptfile 📦"
59-
bash "${DOTFILES_DIR}/bin/aptfile" "${DOTFILES_DIR}/linux/Aptfile"
60-
else
61-
log_event "error" "Unsupported OS: ${OS_NAME}"
62-
return 1
12+
if [[ "${*}" == *"--help"* ]]; then
13+
make -s -C "${DOTFILES_DIR:-${HOME}/.dotfiles}" help
14+
return 0
6315
fi
64-
log_event "info" "Dependencies installed successfully 🎉"
16+
make -s -C "${DOTFILES_DIR:-${HOME}/.dotfiles}" ${*}
6517
}
6618

6719
##########################################################

0 commit comments

Comments
 (0)