Skip to content

Commit

Permalink
✨ functions
Browse files Browse the repository at this point in the history
  • Loading branch information
juftin committed Mar 23, 2024
1 parent 49e8207 commit 2f7f264
Show file tree
Hide file tree
Showing 11 changed files with 376 additions and 181 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cache/
macos/Brewfile.lock.json
macos/*.lock.json
46 changes: 26 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
SHELL := /bin/bash
OS := $(shell uname -s)
GIT := git
HATCH := hatch

.PHONY: help
help:
@echo "Usage: make [TARGET] ..."
@echo ""
@echo "Targets:"
@echo " bootstrap Initialize the project by running the bootstrap script."
@echo " deps Install dependencies for the project based on the OS."
@echo " docs Serve the documentation locally."
@echo " fmt Run pre-commit hooks on all files."
@echo " help Show this help message."
@echo " sync Update the project and its submodules."
##@ dotfiles

.PHONY: bootstrap
bootstrap:
bootstrap: ## Initialize the project by running the bootstrap script.
$(SHELL) ./bootstrap/bootstrap.sh

.PHONY: deps
deps:
deps: ## Install dependencies for the project based on the OS.
ifeq ($(OS),Linux)
$(SHELL) ./bin/aptfile ./linux/Aptfile
else ifeq ($(OS),Darwin)
Expand All @@ -30,13 +18,31 @@ else
endif

.PHONY: sync
sync:
$(GIT) pull --recurse-submodules --jobs=4
sync: ## Update the project and its submodules.
git pull --recurse-submodules --jobs=4

##@ development

.PHONY: fmt
fmt:
fmt: ## Run pre-commit hooks on all files.
pre-commit run --all-files

.PHONY: docs
docs:
$(HATCH) run docs:serve --livereload
docs: ## Serve the documentation locally.
hatch run docs:serve --livereload

##@ general

.PHONY: version
version: ## Show the version of the project.
@echo "dotfiles $$(git describe --tags --abbrev=0)"

.DEFAULT_GOAL := help
.PHONY: help
help: ## Show this help message and exit.
################################################
# Auto-Generated Help:
# - "##@" denotes a target category
# - "##" denotes a specific target description
###############################################
@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)
41 changes: 41 additions & 0 deletions bin/now
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

#
# See what 'read -t' returns on timeout.
#
# For that - read from stdout. Alternatively, it could read
# from /dev/zero, but it's not available under Cygwin and
# in other non-*nix environments.
#
# Also note, that while bash manual states that the return
# code on a timeout is greater than 128, it doesn't hold
# true with a number of bash implementations, most notably
# including GNU bash that returns 1 instead.
#
read -t 1 <&1
timeout=$?

#
# loop forever
#
while true; do
#
# relay stdin to stdout
#
while true; do
IFS= read -r -t 1 line
rc=$?
if [ $rc != 0 ]; then break; fi
echo "$line"
done
#
# exit status is greater than 128 if the timeout is exceeded
#
if [ $rc != $timeout ]; then break; fi

#
# print the timestamp
#
now=$(date ${1:++"$1"})
echo -ne "$now\r" >&2
done
23 changes: 12 additions & 11 deletions bootstrap/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,22 @@ function log_event() {
LOGGING_TIMESTAMP="${BLUE}$(date +"%F %T,000")${NO_COLOR}"
case "${1}" in
"info")
echo -e "${LOGGING_TIMESTAMP} ${GREEN}INFO: ${NO_COLOR}${2}"
echo -e "${LOGGING_TIMESTAMP} ${GREEN}[ INFO]: ${NO_COLOR}${2}"
;;
"error")
echo -e "${LOGGING_TIMESTAMP} ${RED}ERROR: ${NO_COLOR}${2}"
echo -e "${LOGGING_TIMESTAMP} ${RED}[ ERROR]: ${NO_COLOR}${2}"
;;
"warning")
echo -e "${LOGGING_TIMESTAMP} ${ORANGE}WARNING: ${NO_COLOR}${2}"
echo -e "${LOGGING_TIMESTAMP} ${ORANGE}[ WARNING]: ${NO_COLOR}${2}"
;;
"debug")
echo -e "${LOGGING_TIMESTAMP} ${PURPLE}[ DEBUG]: ${NO_COLOR}${2}"
;;
"critical")
echo -e "${LOGGING_TIMESTAMP} ${RED}[CRITICAL]: ${NO_COLOR}${2}"
;;
*)
echo -e "${LOGGING_TIMESTAMP} ${PURPLE}${1}: ${NO_COLOR}${2}"
echo -e "${LOGGING_TIMESTAMP} ${GREEN}[ INFO]: ${NO_COLOR}${1}"
;;
esac
}
Expand Down Expand Up @@ -267,12 +273,7 @@ function symlink_item() {

function symlink_shell() {
symlink_item "${DOTFILES_DIR}/shell/.shell_aliases" "${HOME}/.shell_aliases"
}

function symlink_mac() {
if [[ $(uname) == "Darwin" ]]; then
symlink_item "${DOTFILES_DIR}/shell/.mac_aliases" "${HOME}/.mac_aliases"
fi
symlink_item "${DOTFILES_DIR}/shell/.shell_functions" "${HOME}/.shell_functions"
}

function symlink_zsh() {
Expand Down Expand Up @@ -306,6 +307,7 @@ function symlink_misc() {

function symlink_bin() {
symlink_item "${DOTFILES_DIR}/bin/has" "/usr/local/bin/has"
symlink_item "${DOTFILES_DIR}/bin/now" "/usr/local/bin/now"
if [[ $(uname) == "Linux" ]]; then
symlink_item "${DOTFILES_DIR}/bin/aptfile" "/usr/local/bin/aptfile"
fi
Expand All @@ -318,7 +320,6 @@ function symlink_tools() {

function symlink_dotfiles() {
symlink_shell
symlink_mac
symlink_zsh
symlink_bash
symlink_git
Expand Down
2 changes: 1 addition & 1 deletion docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ the steps below:
ln -s ~/.dotfiles/shell/.profile ~/.profile
# SHELL
ln -s ~/.dotfiles/shell/.shell_aliases ~/.shell_aliases
ln -s ~/.dotfiles/shell/.mac_aliases ~/.mac_aliases
ln -s ~/.dotfiles/shell/.shell_functions ~/.shell_functions
# PYENV
ln -s ~/.dotfiles/bootstrap/pyenv ~/.pyenv
# GIT
Expand Down
12 changes: 11 additions & 1 deletion macos/Brewfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ tap "hashicorp/tap"
tap "homebrew/bundle"
tap "homebrew/cask-fonts"
tap "homebrew/services"
tap "derailed/k9s"

##########################################################
####################### UTILITIES ########################
##########################################################

brew "asdf"
brew "awsume"
brew "aws-sso-util"
brew "ca-certificates"
brew "checkov"
brew "curl"
brew "direnv"
brew "ffmpeg"
Expand All @@ -26,14 +31,18 @@ brew "helm"
brew "htop"
brew "hugo"
brew "jq"
brew "k9s"
brew "make"
brew "neovim"
brew "node"
brew "openjdk"
brew "pipx"
brew "pre-commit"
brew "ripgrep"
brew "sops"
brew "terraform"
brew "terragrunt"
brew "tmate"
brew "thefuck"
brew "tree"
brew "wget"
Expand All @@ -50,8 +59,9 @@ cask "docker"
cask "hammerspoon"
cask "iterm2"
cask "lens"
cask "ngrok"
cask "spotify"
cask "syntax-highlight"
cask "syntax-highlight", args: { no_quarantine: true }
cask "vlc"

##########################################################
Expand Down
15 changes: 15 additions & 0 deletions macos/XBrewfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
##########################################################
######################### TAPS ###########################
##########################################################

tap "homebrew/bundle"

##########################################################
######################## PYTHON ##########################
##########################################################

brew "[email protected]"
brew "[email protected]"
brew "[email protected]"
brew "[email protected]"
brew "[email protected]"
18 changes: 0 additions & 18 deletions shell/.mac_aliases

This file was deleted.

Loading

0 comments on commit 2f7f264

Please sign in to comment.