diff options
| author | Craig Jennings <c@cjennings.net> | 2026-06-02 12:16:38 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-06-02 12:16:38 -0500 |
| commit | b10cba594db836c0747066addad48bda4d30cd02 (patch) | |
| tree | 063119a623fa3f7139feda4ef302896d8f5f934c /dotfiles/common/.bashrc.d/utilities.sh | |
| parent | 49c2ba9c4510bf6e1acd306687473bc8ba9ad8dd (diff) | |
| download | archsetup-b10cba594db836c0747066addad48bda4d30cd02.tar.gz archsetup-b10cba594db836c0747066addad48bda4d30cd02.zip | |
refactor: drop in-repo dotfiles/, move stow tooling to the dotfiles repo
Since the installer clones DOTFILES_REPO into ~/.dotfiles and stows from there, the in-repo dotfiles/ tree was dead weight. Nothing reads it at install time. I removed it (831 files) now that both machines are migrated.
The Makefile's stow / restow / reset / unstow / import targets and the dotfile-script unit suites moved to the dotfiles repo. They sit alongside the scripts they manage and run standalone (cd ~/.dotfiles && make ...). This Makefile keeps the VM-integration targets and the installer-helper suite (safe-rm-rf).
I updated CLAUDE.md and README.md so stow operations run from ~/.dotfiles, and the dotfile-management, theme, and unit-test sections point at the standalone repo. The README was already describing the old in-repo model from before the installer switched to cloning. This brings it in line.
Diffstat (limited to 'dotfiles/common/.bashrc.d/utilities.sh')
| -rw-r--r-- | dotfiles/common/.bashrc.d/utilities.sh | 206 |
1 files changed, 0 insertions, 206 deletions
diff --git a/dotfiles/common/.bashrc.d/utilities.sh b/dotfiles/common/.bashrc.d/utilities.sh deleted file mode 100644 index 431cac0..0000000 --- a/dotfiles/common/.bashrc.d/utilities.sh +++ /dev/null @@ -1,206 +0,0 @@ -# utilities.sh -# Craig Jennings <c@cjennings.net> -# General utility functions - -# ============================================================================= -# Archive Extraction -# ============================================================================= -extract() { - if [ -f "$1" ]; then - case "$1" in - *.tar.bz2) tar xjf "$1" ;; - *.tar.gz) tar xzf "$1" ;; - *.bz2) bunzip2 "$1" ;; - *.rar) rar x "$1" ;; - *.gz) gunzip "$1" ;; - *.tar) tar xf "$1" ;; - *.tbz2) tar xjf "$1" ;; - *.tgz) tar xzf "$1" ;; - *.zip) unzip "$1" ;; - *.Z) uncompress "$1" ;; - *) echo "$1 cannot be extracted via extract()" ;; - esac - else - echo "$1 is not a valid file" - fi -} - -# ============================================================================= -# Archive Compression -# ============================================================================= -compress() { - if [ $# -ne 2 ]; then - echo "Usage: compress <format> <file_or_directory>" - echo "Formats: tar.bz2, tar.gz, bz2, tar, tbz2, tgz, zip, gz, Z" - return 1 - fi - - format="$1" - target="$2" - - if [ ! -e "$target" ]; then - echo "Error: '$target' does not exist" - return 1 - fi - - basename=$(basename "$target") - - case "$format" in - tar.bz2|tbz2) output="${basename}.tar.bz2" ;; - tar.gz|tgz) output="${basename}.tar.gz" ;; - bz2) output="${target}.bz2" ;; - gz) output="${target}.gz" ;; - tar) output="${basename}.tar" ;; - zip) output="${basename}.zip" ;; - Z) output="${target}.Z" ;; - *) - echo "Error: Unknown format '$format'" - return 1 - ;; - esac - - if [ -e "$output" ]; then - printf "Warning: '%s' already exists. Overwrite? (y/N): " "$output" - read -r response - case "$response" in - [yY]|[yY][eE][sS]) rm -f "$output" ;; - *) echo "Aborted." && return 1 ;; - esac - fi - - case "$format" in - tar.bz2|tbz2) tar -cjf "$output" "$target" ;; - tar.gz|tgz) tar -czf "$output" "$target" ;; - bz2) - [ -d "$target" ] && echo "Error: bz2 only works on files" && return 1 - bzip2 -k "$target" - ;; - gz) - [ -d "$target" ] && echo "Error: gz only works on files" && return 1 - gzip -k "$target" - ;; - tar) tar -cf "$output" "$target" ;; - zip) - [ -d "$target" ] && zip -r "$output" "$target" || zip "$output" "$target" - ;; - Z) - [ -d "$target" ] && echo "Error: Z only works on files" && return 1 - command compress -c "$target" > "$output" - ;; - esac - - [ $? -eq 0 ] && echo "Created $output" || echo "Compression failed" -} - -# ============================================================================= -# DD Helper -# ============================================================================= -dd_with_bs() { - OUT_DIR=$(dirname "$2") - if [ ! -e "$1" ] || [ ! -e "$OUT_DIR" ]; then - echo "$1 or $OUT_DIR doesn't exist" - return 1 - fi - IN_BS=$(stat -c "%o" "$1") - OUT_BS=$(stat -c "%o" "$OUT_DIR") - echo dd \"if=$1\" \"of=$2\" \"ibs=$IN_BS\" \"obs=$OUT_BS\" -} - -# ============================================================================= -# Clock, Timer, Alarm, Stopwatch -# ============================================================================= -export BEEP="/usr/share/sounds/freedesktop/stereo/bell.oga" -alias beep='paplay $BEEP' - -clock() { - while true; do - tput clear - echo "" - date +" %l : %M %p" | figlet -f roman -w 200 - sleep 1 - done -} - -timer() { - if [ "$#" -lt 2 ]; then - echo "Pass the time and a notification. Example: timer 1h30m Parking expiring" - return 1 - fi - message="${*:2}" - start_time=$(date +"%H:%M:%S %p") - printf "\nStarting %s timer at %s\n" "$1" "$start_time" - snore "$1" && paplay "$BEEP" && notify-send "Timer" "$message" -} - -alarm() { - if [ "$#" -lt 2 ]; then - echo "Pass both the time and a message. Example: alarm 1:45pm Time to eat!" - return 1 - fi - - if ! date -d "$1" >/dev/null 2>&1; then - echo "Invalid time: $1" - return 1 - fi - - echo "paplay \$BEEP && notify-send \"Alarm\" \"$*\"" | at "$1" >/dev/null 2>&1 - echo "" - echo "Alarm '${*:2}' is queued for $1." - echo "To see all alarms: atq" - echo "To remove an alarm: atrm <number>" - echo "" -} - -# Stopwatch -sw_start_time=0 -sw_started=0 - -swreset() { - sw_start_time=0 - sw_started=0 - echo "Stopwatch reset" -} - -swshow() { - if [ "$sw_started" = 0 ]; then - echo "Error: Stopwatch not started" >&2 - return 1 - fi - - current_time=$(date +%s) - elapsed_time=$((current_time - sw_start_time)) - - if [ "$elapsed_time" -lt 60 ]; then - echo "Elapsed time: $elapsed_time seconds" - elif [ "$elapsed_time" -lt 3600 ]; then - minutes=$((elapsed_time / 60)) - seconds=$((elapsed_time % 60)) - echo "Elapsed time: $minutes minutes, $seconds seconds" - else - hours=$((elapsed_time / 3600)) - minutes=$(((elapsed_time / 60) % 60)) - seconds=$((elapsed_time % 60)) - echo "Elapsed time: $hours hours, $minutes minutes, $seconds seconds" - fi -} - -swstop() { - swshow - swreset -} - -swstart() { - if [ "$sw_started" = 1 ]; then - printf "Stopwatch is already started. Reset? (y/n): " - read -r answer - case "$answer" in - [yY]) swreset ;; - [nN]) echo "Stopwatch not reset." && swshow && return ;; - *) echo "Error: Invalid input." >&2 && return 1 ;; - esac - fi - - sw_started=1 - sw_start_time=$(date +%s) - printf "Stopwatch started at %s\n\n" "$(date +"%H:%M:%S %p")" -} |
