dotfiles

regexghost dotfiles and scripts
git clone https://git.regexghost.com/dotfiles.git
Log | Files | Refs | README

commit 163367eceb8448691a72d138ad14543f2201a8e5
parent 1587010655b9f22418788a63797cca19f654c0e4
Author: regexghost <dev@regexghost.com>
Date:   Wed,  5 Aug 2026 16:41:05 +0100

terminal and panel script comments

Diffstat:
Mpanel-scripts/cpu.c | 7+------
Mpanel-scripts/metoffice.sh | 1+
Mpanel-scripts/uptime.c | 24+++---------------------
Mterminal-scripts/Makefile | 1-
Mterminal-scripts/backup.sh | 12+++++++++++-
Mterminal-scripts/blog-devlog.sh | 9+++++++++
Mterminal-scripts/calendar.sh | 1+
Mterminal-scripts/cmpfolder.sh | 2++
Mterminal-scripts/directory-bookmarks.c | 6+++---
Mterminal-scripts/download-pods.sh | 1+
Mterminal-scripts/files.sh | 1+
Mterminal-scripts/geohash.go | 10+++++-----
Mterminal-scripts/howlongtobeat.py | 2++
Mterminal-scripts/iphone-mount.sh | 3+++
Mterminal-scripts/iphone-music-sync.sh | 7+++++++
Mterminal-scripts/media-cut.sh | 1+
Mterminal-scripts/qmount.sh | 3+++
Mterminal-scripts/tablealigner.go | 45++++++++++++++++++---------------------------
Dterminal-scripts/webm-to-m4a.sh | 14--------------
Mterminal-scripts/yt-data.sh | 2+-
20 files changed, 73 insertions(+), 79 deletions(-)

diff --git a/panel-scripts/cpu.c b/panel-scripts/cpu.c @@ -36,20 +36,16 @@ void save_new_values(Values new_values) { int main() { Values prev_values = get_previous_values(); - + FILE *f; f = fopen("/proc/stat", "r"); char buf[100] = {0}; fgets(buf, 100, f); - //printf("%s\n", buf); fclose(f); int user, nice, system, idle, iowait, irq, softirq, steal; sscanf(buf, "%*s %d %d %d %d %d %d %d %d %*d %*d", &user, &nice, &system, &idle, &iowait, &irq, &softirq, &steal); - - //printf("Current: %d %d %d %d %d %d %d %d\n", user, nice, system, idle, iowait, irq, softirq, steal); - //printf("Old: %d %d\n", prev_values.total, prev_values.idle); int total = user + nice + system + idle + iowait + irq + softirq + steal; int total_since_last = total - prev_values.total; @@ -59,7 +55,6 @@ int main() { double usage = 1 - fraction; double percentage = usage * 100; - //printf("%f %f %f\n", fraction, usage, percentage); if (percentage < 9.995) { printf("%0.2f%%\n", percentage); } else { diff --git a/panel-scripts/metoffice.sh b/panel-scripts/metoffice.sh @@ -10,6 +10,7 @@ lat=$(cat "$curLocationFile" | cut -d "|" -f 1) lon=$(cat "$curLocationFile" | cut -d "|" -f 2) geohash=$(geohash $lat $lon 9) today_string="$(date "+%Y-%m-%d")" +# Diffrent date versions need different syntax for specifiying the date to use if date --version 2>&1 | grep -q "GNU coreutils" > /dev/null; then tomorrow_string="$(date -d @$(($(date +%s)+86400)) "+%Y-%m-%d")" second_day_string="$(date -d @$(($(date +%s)+86400+86400)) "+%Y-%m-%d")" diff --git a/panel-scripts/uptime.c b/panel-scripts/uptime.c @@ -4,34 +4,16 @@ int main() { struct sysinfo info; - + if (sysinfo(&info) != 0) { printf("Error"); return 1; } - - //printf("Uptime: %ld\n", info.uptime); - //return 0; - - + int hours = info.uptime/3600; int minutes = (info.uptime - hours * 3600)/60; - + printf("%02d:%02d\n", hours, minutes); return 1; - float f_load = 1.f / (1 << SI_LOAD_SHIFT); - - time_t bootTime = time(NULL) - info.uptime + 1; - struct tm* bootTimeFormatted; - bootTimeFormatted = localtime(&bootTime); - - printf("%s", asctime(bootTimeFormatted)); - time_t a; - time(&a); - //printf("%d\n", a); - - - //printf("<tool>Load Average (1m): %0.2f\nLoad Average (5m): %0.2f\nLoad Average (15m): %0.2f</tool>", info.loads[0] * f_load, info.loads[1] * f_load, info.loads[2] * f_load); - //printf("\n"); } diff --git a/terminal-scripts/Makefile b/terminal-scripts/Makefile @@ -26,7 +26,6 @@ normal: cp stream-check.sh ${BIN}/stream-check cp opus-soundtrack.sh ${BIN}/opus-soundtrack cp opus-single.sh ${BIN}/opus-single - cp webm-to-m4a.sh ${BIN}/webm-to-m4a gcc string-trunc.c -o string-trunc mv string-trunc ${BIN}/string-trunc cp ytdl-wrapper.sh ${BIN}/ytdl-wrapper diff --git a/terminal-scripts/backup.sh b/terminal-scripts/backup.sh @@ -6,19 +6,27 @@ BACKUP_FILE="$XDG_CONFIG_HOME/regexghost/backup.txt" BACKUP_LOCATION="$HOME/Downloads/BackupMount/MainBackup" if [ "$1" = "add" ]; then + # Get real filename, and remove "/home/<user>" [ -e "$2" ] && echo "$(readlink -f "$2")" | sed "s|$HOME||g" >> "$BACKUP_FILE" elif [ "$1" = "remove" ] || [ "$1" = "rm" ]; then + # Get real filename, and remove "/home/<user>" file="$(readlink -f "$2" | sed "s|$HOME||g")" + # Check if it's in backup file, if so, remove and overwrite if grep -q "^${file}\$" "$BACKUP_FILE"; then sed "\:^$file\$:d" "$BACKUP_FILE" > /tmp/backup-tempfile mv /tmp/backup-tempfile "$BACKUP_FILE" fi elif [ "$1" = "ls" ]; then + # Add "~" to the start of each path cat "$BACKUP_FILE" | sed 's/^/~/g' elif [ "$1" = "make" ]; then + # Log backup date +"%y-%m-%d" >> "$XDG_DATA_HOME/regexghost/script-data/backup-history.txt" + # Copy last backup, to previous slot rsync -ar --links --delete --info=progress2 "${BACKUP_LOCATION}/latest/" "${BACKUP_LOCATION}/previous/" + # Make backup from live system rsync -ar --links --delete --info=progress2 --files-from="${BACKUP_FILE}" "$HOME" "${BACKUP_LOCATION}/latest/" + # Hash all files (on PC) and save to file hashFile="${BACKUP_LOCATION}/hashes/$(date +"%y%m%d-%H%M").txt" while read -r thing; do echo "Hashing: ${HOME}${thing}" @@ -28,7 +36,9 @@ elif [ "$1" = "make" ]; then $(cat "$BACKUP_FILE") EOF elif [ "$1" = "diff" ]; then + # Get last 2 hash files and compare last2="$(find "${BACKUP_LOCATION}/hashes" | sort | tail -n 2 | head -n 1)" last1="$(find "${BACKUP_LOCATION}/hashes" | sort | tail -n 1)" - diff --color=auto "$last2" "$last1" + # --color=always so that you can grep -v while maintaining colour + diff --color=always "$last2" "$last1" fi diff --git a/terminal-scripts/blog-devlog.sh b/terminal-scripts/blog-devlog.sh @@ -3,17 +3,23 @@ # Helper scripts for my blog and devlog blog () { + # Get dir, make if doesn't exist dir="$HOME/Programs/websites/personal-website/blog/$(date +%Y/%B | awk '{print tolower($0)}')" [ -d "$dir" ] || mkdir -p "$dir" + # If cd argument given just echo the dir and exit (a function in shell rc picks this up and does the actual cd) [ "$1" = "cd" ] && echo "$dir" && exit + + # Get date in proper format month_num="$(date "+%m")" year="$(date "+%Y")" date="$(date "+%d")" + # Prompt for filename and title read -p "Enter filename: " filename read -p "Enter title: " title if ! echo "$filename" | grep -q ".md$"; then filename="${filename}.md" fi + # Add header to document and open fullpath="${dir}/${filename}" echo "+++" >> "$fullpath" echo "title = \"${title}\"" >> "$fullpath" @@ -24,14 +30,17 @@ blog () { } devlog () { + # Get date and form filename month_num="$(date "+%m")" month_name="$(date "+%B")" year="$(date "+%Y")" date="$(date "+%d")" filename="$HOME/Programs/websites/personal-website/devlog/${year}-${month_num}-${month_name}.md" + # If the file exists, just open it if [ -f "$filename" ]; then "${VISUAL:-${EDITOR:-vi}}" "$filename" + # Otherwise make and add header else echo "+++" >> "$filename" echo "title = \"${month_name} ${year} Devlog\"" >> "$filename" diff --git a/terminal-scripts/calendar.sh b/terminal-scripts/calendar.sh @@ -17,6 +17,7 @@ suffix () { fi } +# Unbuffer keeps the little box around the current day, sed deletes empty line at the end unbuffer cal -w -n 3 "$@" | sed '/^ *$/d' day="$(date +'%A')" diff --git a/terminal-scripts/cmpfolder.sh b/terminal-scripts/cmpfolder.sh @@ -12,6 +12,8 @@ IFS=$'\n' filesA=( $(find "$1" -type f | sort) ) filesB=( $(find "$2" -type f | sort) ) +# -o means only cmp files in first dir, to matching files in second dir +# Useful if first directory is an incomplete copy of the second one if [[ "$3" == "-o" ]]; then for fileA in "${filesA[@]}"; do fileName=$(basename "$fileA") diff --git a/terminal-scripts/directory-bookmarks.c b/terminal-scripts/directory-bookmarks.c @@ -48,7 +48,7 @@ int get_bookmarks(Bookmark* bookmarks) { int i = 0; char buffer[400]; - + while (fgets(buffer, sizeof(buffer), f) != NULL) { if (i > 99) { printf("Error, bookmarks file too big\n"); @@ -77,7 +77,7 @@ int get_file_bookmarks(FileBookmark* bookmarks) { int i = 0; char buffer[400]; - + while (fgets(buffer, sizeof(buffer), f) != NULL) { if (i > 99) { printf("Error, file bookmarks file too big\n"); @@ -164,7 +164,7 @@ void add_bookmark(char* to_add) { strcpy(bookmarks[num_bookmarks].bookmark_name, to_add); strcpy(bookmarks[num_bookmarks].directory_name, cwd); - + num_bookmarks++; write_bookmarks(bookmarks, num_bookmarks); } diff --git a/terminal-scripts/download-pods.sh b/terminal-scripts/download-pods.sh @@ -17,6 +17,7 @@ while read -r podcast_file; do fi filename="$(mediainfo /tmp/out.mp3 | grep -e "Track name" -e "Album" | sed 's/Track name/Trackname/g' | tr -s " " | cut -d " " -f 3- | tr "\n" "+" | sed 's/[+]/ - /g' | sed 's/ - $//g')" + # Sometimes there won't be a track name in the metadata, in which case just name it based on data and time downloaded. Not ideal [ "$filename" = "" ] && filename="$(date +"%y-%m-%d-%H-%M-%S")" mv /tmp/out.mp3 "${LOC}/${filename}.mp3" grep -v "$podcast_file" /tmp/toDownload.txt > /tmp/toDownload.txt.tmp diff --git a/terminal-scripts/files.sh b/terminal-scripts/files.sh @@ -1,4 +1,5 @@ #!/bin/sh +# Have to specify the variables as part of the command, otherwise if tmux is open elsewhere, it won't inherit environmental variables set here tmux new-session -d -s mys "NNN_FIFO=/tmp/nnn.fifo NNN_PLUG=v:preview-tui nnn -P v" tmux attach -t mys diff --git a/terminal-scripts/geohash.go b/terminal-scripts/geohash.go @@ -22,14 +22,14 @@ func main() { printHelp() os.Exit(1) } - + var lat string = os.Args[1] var lon string = os.Args[2] var precision string = "12" if len(os.Args) == 4 { precision = os.Args[3] } - + fmt.Println(encode(lat, lon, precision)) } @@ -53,12 +53,12 @@ func encode(latInput, lonInput, precisionInput string) string { var lat float64 = getFloat64(latInput) var lon float64 = getFloat64(lonInput) var precision int = getInt(precisionInput) - + var n, s int = 0, 0 var o bool = true var r, c, d, l float64 = -90, 90, -180, 180 var encodedString string = "" - + for len(encodedString) < precision { if o { var e2 float64 = (d + l) / 2 @@ -87,6 +87,6 @@ func encode(latInput, lonInput, precisionInput string) string { n = 0 } } - + return encodedString } diff --git a/terminal-scripts/howlongtobeat.py b/terminal-scripts/howlongtobeat.py @@ -39,6 +39,8 @@ gameName = ' '.join(args).rstrip() if not outputJson: print("Searching for game: " + gameName) +# Added `0.0`, otherwise sometimes you get 0 results if the string match isn't big enough +# e.g. typing "Lufia" wouldn't return anything, because you are missing 80% of the title of each game results = HowLongToBeat(0.0).search(gameName) length = len(results) diff --git a/terminal-scripts/iphone-mount.sh b/terminal-scripts/iphone-mount.sh @@ -2,6 +2,9 @@ MOUNTPOINT="$HOME/Downloads/USBDrive" +# This is a horrible script and I need to re-write it to dynamically get all these apps +# and present using fzf + if [[ "$1" == "mount" ]]; then idevicepair validate idevicepair pair || exit diff --git a/terminal-scripts/iphone-music-sync.sh b/terminal-scripts/iphone-music-sync.sh @@ -25,14 +25,21 @@ ifuse --documents com.foobar2000.mobile "$MOUNT_LOCATION" # Copy/update playlists while read -r line; do + # Local path computer="$(echo "$line" | cut -d "," -f 1)" + # Phone path phone="$(echo "$line" | cut -d "," -f 2)" echo "${computer} -> ${phone}" + # Create phone dir if non existant [ -d "${MOUNT_LOCATION}/${phone}" ] || mkdir "${MOUNT_LOCATION}/${phone}" + # Copy, with --copy-links, so locally symlinked playlists (e.g. CurrentPlaylist) copy as files rsync -vr --copy-links --update --delete --modify-window=1 --info=progress2 "${HOME}/Music/${computer}/" "${MOUNT_LOCATION}/${phone}/" + # Shuffle into playlist file find "${MOUNT_LOCATION}/${phone}/" -type f | sort | sed "s|.*${phone}/|../${phone}/|g" > "/tmp/${phone}.m3u8" cp "/tmp/${phone}.m3u8" "${MOUNT_LOCATION}/Playlists/" done < "$XDG_CONFIG_HOME/regexghost/playlists-phone-sync.csv" +# Unmount phone + fusermount -u "${MOUNT_LOCATION}" idevicepair unpair diff --git a/terminal-scripts/media-cut.sh b/terminal-scripts/media-cut.sh @@ -13,6 +13,7 @@ start_time="$2" end_time="$3" output_file="$4" +# I got this from somewhere, but I can't find where, likely stackoverflow cut_time=$(awk -v start="$start_time" -v end="$end_time" ' BEGIN { split(start, a, ":") diff --git a/terminal-scripts/qmount.sh b/terminal-scripts/qmount.sh @@ -6,6 +6,7 @@ mount_points="~/Downloads/USBDrive root_device="$(/usr/bin/lsblk -l -n --output NAME,MOUNTPOINTS | grep '/$' | sed 's/p[0-9] \///g; s/[0-9] \///g')" mount () { + # Filter out root disk unmounted="$(/usr/bin/lsblk -l -n --output NAME,FSTYPE,SIZE,MOUNTPOINTS,TYPE | grep "part" | grep -v "/" | grep -v "$root_device" | tr -s " " | cut -d " " -f 1-3)" [ "$unmounted" = "" ] && echo "No drives to mount" && exit @@ -17,6 +18,7 @@ mount () { chosen_mount_point="$(echo "$mount_points" | fzf | sed "s|~|$HOME|")" [ "$chosen_mount_point" = "" ] && exit + # Check if vfat or exfat, if so need special mount options to get permissions right args="" if [ "$chosen_fstype" = "vfat" ] || [ "$chosen_fstype" = "exfat" ]; then args="-o rw,users,umask=000" @@ -26,6 +28,7 @@ mount () { } unmount () { + # Filter out root disk mounted="$(/usr/bin/lsblk -l -n --output NAME,MOUNTPOINTS | grep "/" | grep -v "$root_device" | tr -s " ")" [ "$mounted" = "" ] && echo "No drives to unmount" && exit diff --git a/terminal-scripts/tablealigner.go b/terminal-scripts/tablealigner.go @@ -7,7 +7,6 @@ import ( "strings" "regexp" "os/exec" - //"strconv" ) func Print(str string) { @@ -15,6 +14,7 @@ func Print(str string) { cmd.Run() } +// This is definitely not a good solution to wide characters var EMOJIS []rune = []rune{'❌', '✅', '❔', '❓', '📅', '🚗', '🌙', '⏳'} func isEmoji(r rune) bool { @@ -29,10 +29,7 @@ func isEmoji(r rune) bool { func properLen(input string) int { var noEndSpaces string = strings.TrimRight(input, " ") var length int = utf8.RuneCountInString(noEndSpaces) + 1 - - //fmt.Printf("A:%s:B\n", input) - //fmt.Printf("C:%s:D\n", noEndSpaces) - + for _, r := range noEndSpaces { if isEmoji(r) { length++ @@ -46,7 +43,7 @@ func readFile(filename string) []string { if err != nil { panic(err) } - + return strings.Split(string(dat), "\n") } @@ -54,7 +51,7 @@ func testForAlignRow(line string) bool { if len(line) < 1 { return false } - + if line[0] != '|' || line[len(line)-1] != '|' { return false } @@ -65,7 +62,7 @@ func testForAlignRow(line string) bool { return false } } - + return true } @@ -78,9 +75,9 @@ func testForEnd(line string) bool { func findTables(input []string) [][]int { var tables [][]int - + var inTable bool = false - + for i, line := range input { if !inTable && testForAlignRow(line) { tables = append(tables, []int{i-1}) @@ -90,7 +87,7 @@ func findTables(input []string) [][]int { inTable = false } } - + return tables } @@ -100,19 +97,18 @@ func calcLengths(thisTable []string) []int { if numCells < 1 { os.Exit(1) } - + var columnLengths []int = make([]int, numCells) - + for i, line := range thisTable { if i == 1 { continue } cells := strings.Split(line, "|") cells = cells[1:len(cells)-1] - + for j, cell := range cells { var cellLen int = properLen(cell) - //fmt.Println(cell) if cellLen > columnLengths[j] { columnLengths[j] = cellLen } @@ -122,15 +118,13 @@ func calcLengths(thisTable []string) []int { } func alignTable(table []int, data[]string) []string { - //fmt.Println("Table:") thisTable := data[table[0]:table[1]+1] columnLengths := calcLengths(thisTable) - //fmt.Println(columnLengths) - + for i:=0; i<len(thisTable); i++ { cells := strings.Split(thisTable[i], "|") cells = cells[1:len(cells)-1] - + newCells := []string{} for j, cell := range cells { cell = strings.TrimRight(cell, " ") + " " @@ -138,7 +132,7 @@ func alignTable(table []int, data[]string) []string { if cellLen != columnLengths[j] { var paddedCell string = padCell(cell, cellLen, i, j, columnLengths) newCells = append(newCells, paddedCell) - + } else { newCells = append(newCells, cell) } @@ -189,21 +183,18 @@ func main() { fmt.Println("Usage: \n tablealigner input.md output.md") panic("wrong args") } - + var inputFile string = os.Args[1] var outputFile string = os.Args[2] if os.Args[1] == "-s" { inputFile = os.Args[2] outputFile = os.Args[2] } - + data := readFile(inputFile) - + tables := findTables(data) - //fmt.Println(tables) data = alignTables(tables, data) - - //data = fixEmojis(data) - + saveToFile(data, outputFile) } diff --git a/terminal-scripts/webm-to-m4a.sh b/terminal-scripts/webm-to-m4a.sh @@ -1,14 +0,0 @@ -#!/usr/bin/env bash - -oldIFS="$IFS" -IFS=$'\n' -files=( $(find initial/ -type f) ) -IFS="$oldIFS" - -for file in "${files[@]}"; do - echo $file - new="$(echo "$file" | sed 's/webm$/m4a/g; s/^initial/done/g')" - dir="$(dirname "$new")" - [ -d "$dir" ] || mkdir "$dir" - ffmpeg -i "$file" -map_metadata -1 -vn -acodec aac -aac_pns 0 "$new" -done diff --git a/terminal-scripts/yt-data.sh b/terminal-scripts/yt-data.sh @@ -1,6 +1,6 @@ #!/bin/sh -# Get basic data for a YouTube video +# Get basic data for a YouTube video without yt-dlp url="$1" TEMP_FILE=/tmp/yt-data.html