regexghost-dotfiles

My dotfiles and scripts
git clone git@git.regexghost.com/regexghost-dotfiles.git
Log | Files | Refs | README

commit 78c9c4083948c4fe57e07c33d00c21289e027f00
parent 550902b8b8ed6f9c5c00020fad6c83e976e13b36
Author: regexghost <regexghost@protonmail.com>
Date:   Fri, 24 Apr 2026 21:43:14 +0100

added scripts

Diffstat:
Adotfiles/.config/micro/bindings.json | 42++++++++++++++++++++++++++++++++++++++++++
Adotfiles/.config/micro/settings.json | 9+++++++++
Adotfiles/.config/tmux/tmux.conf | 8++++++++
Adotfiles/.config/zathura/zathurarc | 1+
Apanel-scripts/cpu.c | 73+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apanel-scripts/network.c | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apanel-scripts/sunrise.sh | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Apanel-scripts/uptime.c | 37+++++++++++++++++++++++++++++++++++++
Aterminal-scripts/cmpfolder.sh | 30++++++++++++++++++++++++++++++
Aterminal-scripts/directory_bookmarks.c | 378+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aterminal-scripts/github_latest_release.sh | 8++++++++
Aterminal-scripts/hashfolder.sh | 28++++++++++++++++++++++++++++
Aterminal-scripts/heic-to-jpg.sh | 14++++++++++++++
Aterminal-scripts/tablealigner.go | 209+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awm-scripts/altgrtosuper.sh | 10++++++++++
15 files changed, 953 insertions(+), 0 deletions(-)

diff --git a/dotfiles/.config/micro/bindings.json b/dotfiles/.config/micro/bindings.json @@ -0,0 +1,42 @@ +{ + "Alt-,": "PreviousTab", + "Alt-.": "NextTab", + "Alt-/": "lua:comment.comment", + "Alt-[": "CursorDown,CursorDown,CursorDown,CursorDown,CursorDown", + "Alt-]": "CursorUp,CursorUp,CursorUp,CursorUp,CursorUp", + "Alt-o": "command:open_ref", + "Ctrl-D": "DuplicateLine", + "Ctrl-Delete": "DeleteWordRight", + "Ctrl-J": "lua:aspell.togglecheck", + "Ctrl-K": "DeleteLine", + "Ctrl-N": "AddTab", + "Ctrl-O": "IndentLine", + "Ctrl-Q": "QuitAll", + "Ctrl-R": "command-edit:replaceall ", + "Ctrl-S": "Save", + "Ctrl-T": "command:jumptag", + "Ctrl-L": "command:linking", + "Ctrl-U": "OutdentLine", + "Ctrl-W": "Quit", + "CtrlBackslash": "Redo", + "CtrlP": "command:palettero", + "CtrlUnderscore": "lua:comment.comment", + "F3": "FindNext", + "Ctrl-G": "FindNext", + "F4": "command:jumptag", + "F5": "lua:wc.wordCount", + "OldBackspace": "DeleteWordLeft", + "Alt-m": "MoveLinesDown", + "Alt-p": "MoveLinesUp", + "Alt-G": "CursorEnd", + "Alt-b": "WordLeft", + "Alt-0": "StartOfLine", + "Alt-^": "StartOfText", + "Alt-s": "Delete", + "Alt-u": "Undo", + "Alt-U": "Redo", + "Alt-l": "CursorRight", + "Alt-j": "CursorDown", + "Alt-k": "CursorUp", + "Alt-h": "CursorLeft", +} diff --git a/dotfiles/.config/micro/settings.json b/dotfiles/.config/micro/settings.json @@ -0,0 +1,9 @@ +{ + "autoclose": false, + "aspell.check": "off", + "hlsearch": true, + "colorscheme": "retro", + "ftoptions": false, + "savecursor": true, + "softwrap": true +} diff --git a/dotfiles/.config/tmux/tmux.conf b/dotfiles/.config/tmux/tmux.conf @@ -0,0 +1,8 @@ +bind -n C-Tab select-window -n +bind -n C-BTab select-window -p +set -g mouse on +set -g escape-time 0 +set-option -sa terminal-features ',alacritty:RGB' +set-option -ga terminal-features ",alacritty:usstyle" +set-option -ga terminal-overrides ',alacritty:Tc' +set -g default-terminal "alacritty" diff --git a/dotfiles/.config/zathura/zathurarc b/dotfiles/.config/zathura/zathurarc @@ -0,0 +1 @@ +set selection-clipboard clipboard diff --git a/panel-scripts/cpu.c b/panel-scripts/cpu.c @@ -0,0 +1,73 @@ +#include <stdio.h> + +#define PREV_FILE_LOC "/tmp/cpu_c_previous" + +typedef struct { + int total; + int idle; +} Values; + +Values get_previous_values() { + FILE *f; + f = fopen(PREV_FILE_LOC, "r"); + if (f == NULL) { + Values prev_values; + prev_values.total = 0; + prev_values.idle = 0; + return prev_values; + } + char buf[100]; + fgets(buf, 100, f); + int total, idle; + sscanf(buf, "%d %d", &total, &idle); + Values prev_values; + prev_values.total = total; + prev_values.idle = idle; + fclose(f); + return prev_values; +} + +void save_new_values(Values new_values) { + FILE *f; + f = fopen(PREV_FILE_LOC, "w"); + fprintf(f, "%d %d", new_values.total, new_values.idle); + fclose(f); +} + +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; + int idle_since_last = idle - prev_values.idle; + + double fraction = (double)idle_since_last/(double)total_since_last; + 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 { + printf("%0.1f%%\n", percentage); + } + + prev_values.total = total; + prev_values.idle = idle; + + save_new_values(prev_values); +} diff --git a/panel-scripts/network.c b/panel-scripts/network.c @@ -0,0 +1,56 @@ +#include <stdio.h> + +#ifdef UP_SPEED +#define PREV_FILE_LOC "/tmp/network_up_previous" +#define BYTES_FILE_LOC "/sys/class/net/wlp0s20f3/statistics/tx_bytes" +#else +#define PREV_FILE_LOC "/tmp/network_down_previous" +#define BYTES_FILE_LOC "/sys/class/net/wlp0s20f3/statistics/rx_bytes" +#endif + +int get_previous_value() { + FILE *f; + f = fopen(PREV_FILE_LOC, "r"); + if (f == NULL) { + return 0; + } + char buf[100]; + fgets(buf, 100, f); + int total; + sscanf(buf, "%d", &total); + fclose(f); + return total; +} + +void save_new_value(int new_value) { + FILE *f; + f = fopen(PREV_FILE_LOC, "w"); + fprintf(f, "%d", new_value); + fclose(f); +} + +int main() { + int previous_value = get_previous_value(); + + FILE *f; + f = fopen(BYTES_FILE_LOC, "r"); + char buf[100] = {0}; + fgets(buf, 100, f); + fclose(f); + + int total; + sscanf(buf, "%d", &total); + + int total_since_last = total - previous_value; + + double mebibytes = (double)total_since_last/(double)1048576/(double)2; + + if (mebibytes < 10) { + printf("%0.2f MiB/s\n", mebibytes); + } + else { + printf("%0.1f MiB/s\n", mebibytes); + } + + save_new_value(total); +} diff --git a/panel-scripts/sunrise.sh b/panel-scripts/sunrise.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash + +curLocationFile="$XDG_CONFIG_HOME/regexghost/current_location.csv" + +lat=$(cat "$curLocationFile" | cut -d "|" -f 1) +lon=$(cat "$curLocationFile" | cut -d "|" -f 2) + +theme=$(cat "$XDG_CONFIG_HOME/regexghost/current_theme.txt") + +if [[ "$theme" == "dracula" ]]; then + sunsetColour="8be9fd" + sunriseColour="ffff80" + goldenHourColour="ffff80" +elif [[ "$theme" == "christmas" ]]; then + sunsetColour="FD971F" + sunriseColour="F1C769" + goldenHourColour="F1C769" +elif [[ "$theme" == "tube" ]]; then + sunsetColour="e67823" + sunriseColour="ffd204" + goldenHourColour="ffd204" +fi + +if [[ "$1" == "--sunrise" ]]; then + #json_tomorrow=$(curl -s "https://api.sunrisesunset.io/json?lat=${lat}&lng=${lon}&date=tomorrow&time_format=24") + json_tomorrow=$(curl -s "https://api.sunrise-sunset.org/json?lat=${lat}&lng=${lon}&date=tomorrow&formatted=0") + sunrise=$(echo "$json_tomorrow" | jq -r .results.sunrise | sed 's/.*T//g' | sed 's/:[0-9]*+.*//g') + astro_twilight=$(echo "$json_tomorrow" | jq -r .results.astronomical_twilight_begin | sed 's/.*T//g' | sed 's/:[0-9]*+.*//g') + if [[ "$2" == "--conky" ]]; then + echo "\${color #$sunriseColour}$astro_twilight - $sunrise \${color}" + else + echo "<span font='Font Awesome 7 Free Solid 9' foreground='#$sunriseColour'> </span> <span foreground='#$sunriseColour'>$astro_twilight - $sunrise </span>" + fi +elif [[ "$1" == "--sunset" ]]; then + #json_today=$(curl -s "https://api.sunrisesunset.io/json?lat=${lat}&lng=${lon}&time_format=24") + json_today=$(curl -s "https://api.sunrise-sunset.org/json?lat=${lat}&lng=${lon}&date=today&formatted=0") + sunset=$(echo "$json_today" | jq -r .results.sunset | sed 's/.*T//g' | sed 's/:[0-9]*+.*//g') + astro_twilight=$(echo "$json_today" | jq -r .results.astronomical_twilight_end | sed 's/.*T//g' | sed 's/:[0-9]*+.*//g') + if [[ "$2" == "--conky" ]]; then + echo "\${color #$sunsetColour}$sunset - $astro_twilight \${color}" + else + echo "<span font='Font Awesome 7 Free Solid 9' foreground='#$sunsetColour'> </span> <span foreground='#$sunsetColour'>$sunset - $astro_twilight </span>" + fi +#elif [[ "$1" == "--golden-hour" ]]; then +# json_today=$(curl -s "https://api.sunrisesunset.io/json?lat=${lat}&lng=${lon}&time_format=24") +# golden_hour=$(echo "$json_today" | jq -r .results.golden_hour | sed 's/:[0-9]*$//g') +# echo "<span font='Font Awesome 7 Free Solid 9' foreground='#$goldenHourColour'> </span> <span foreground='#$goldenHourColour'>$golden_hour </span>" +fi + + diff --git a/panel-scripts/uptime.c b/panel-scripts/uptime.c @@ -0,0 +1,37 @@ +#include <sys/sysinfo.h> +#include <stdio.h> +#include <time.h> + +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/cmpfolder.sh b/terminal-scripts/cmpfolder.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +# Script to compare two folders to ensure they are byte for byte identical + +if [[ "$2" == "" ]]; then + echo "Usage: ./cmpfolder.sh [-o] folder1 folder2" + echo " -o means compare only files in first dir" + exit +fi + +IFS=$'\n' +filesA=( $(find "$1" -type f | sort) ) +filesB=( $(find "$2" -type f | sort) ) + +if [[ "$3" == "-o" ]]; then + for fileA in "${filesA[@]}"; do + fileName=$(basename "$fileA") + fileToCmp="${2}/${fileName}" + cmp "$fileA" "$fileToCmp" + done + exit +fi + +index=0 +for fileA in "${filesA[@]}"; do + fileToCmp="${filesB[index]}" + indexA=$((index+1)) + index="$indexA" + cmp "$fileA" "$fileToCmp" +done diff --git a/terminal-scripts/directory_bookmarks.c b/terminal-scripts/directory_bookmarks.c @@ -0,0 +1,378 @@ +#include <stdio.h> +#include <stdlib.h> +#include <stdbool.h> +#include <string.h> +#include <unistd.h> +#include <linux/limits.h> + +#define BOOKMARK_FILE_LOCATION "/.local/share/regexghost/script_data/directory_bookmarks.txt" +#define FILE_BOOKMARK_FILE_LOCATION "/.local/share/regexghost/script_data/file_bookmarks.txt" +#define RANGER_BOOKMARK_FILE_LOCATION "/.local/share/regexghost/script_data/ranger_directory_bookmarks.conf" + +// This script is based on apparix: https://github.com/micans/apparix + +static char file_loc[256]; +static char file_bookmarks_file_loc[256]; +static char ranger_file_loc[256]; + +typedef struct { + char bookmark_name[11]; + char directory_name[251]; +} Bookmark; + +typedef struct { + char bookmark_name[11]; + char file_path[251]; +} FileBookmark; + +void print_help() { + printf("Usage:\n"); + printf(" Add New Bookmark: bookmarks add *name*\n"); + printf(" Remove Bookmark: bookmarks remove *name*\n"); + printf(" Get Bookmark: bookmarks get *name*\n"); + printf(" List Bookmarks: bookmarks list\n"); + printf(" Get Bookmark Name of Current Directory: bookmarks current\n"); + printf("Usage (File Bookmarks):\n"); + printf(" Add New File Bookmark: bookmarks file add *name* *filename*\n"); + printf(" Remove Bookmark: bookmarks file remove *name*\n"); + printf(" Get Bookmark: bookmarks file get *name*\n"); + printf(" List Bookmarks: bookmarks file list\n"); +} + +int get_bookmarks(Bookmark* bookmarks) { + FILE* f; + f = fopen(file_loc, "r"); + if (f == NULL) { + return 0; + } + + int i = 0; + char buffer[400]; + + while (fgets(buffer, sizeof(buffer), f) != NULL) { + if (i > 99) { + printf("Error, bookmarks file too big\n"); + break; + } + + char bookmark_name[11] = {0}; + char directory_name[251] = {0}; + sscanf(buffer, "%s %[^\n]", bookmark_name, directory_name); + strcpy(bookmarks[i].bookmark_name, bookmark_name); + strcpy(bookmarks[i].directory_name, directory_name); + + memset(buffer, 0, sizeof(buffer)); + + i++; + } + return i; +} + +int get_file_bookmarks(FileBookmark* bookmarks) { + FILE* f; + f = fopen(file_bookmarks_file_loc, "r"); + if (f == NULL) { + return 0; + } + + int i = 0; + char buffer[400]; + + while (fgets(buffer, sizeof(buffer), f) != NULL) { + if (i > 99) { + printf("Error, file bookmarks file too big\n"); + break; + } + + char bookmark_name[11] = {0}; + char file_path[251] = {0}; + sscanf(buffer, "%s %[^\n]", bookmark_name, file_path); + strcpy(bookmarks[i].bookmark_name, bookmark_name); + strcpy(bookmarks[i].file_path, file_path); + + memset(buffer, 0, sizeof(buffer)); + + i++; + } + return i; +} + +void write_bookmarks(Bookmark* bookmarks, int num_bookmarks) { + FILE* f; + f = fopen(file_loc, "w"); + for (int i=0; i<num_bookmarks; i++) { + fprintf(f, "%s %s\n", bookmarks[i].bookmark_name, bookmarks[i].directory_name); + } + fclose(f); + + FILE* g; + g = fopen(ranger_file_loc, "w"); + for (int i=0; i<num_bookmarks; i++) { + fprintf(g, "map go%s cd %s\n", bookmarks[i].bookmark_name, bookmarks[i].directory_name); + } + fclose(g); +} + +void write_file_bookmarks(FileBookmark* bookmarks, int num_bookmarks) { + FILE* f; + f = fopen(file_bookmarks_file_loc, "w"); + for (int i=0; i<num_bookmarks; i++) { + fprintf(f, "%s %s\n", bookmarks[i].bookmark_name, bookmarks[i].file_path); + } + fclose(f); +} + +void add_file_bookmark(char* bookmark_name, char* filename) { + FileBookmark bookmarks[100]; + memset(bookmarks, 0, sizeof(bookmarks)); + int num_bookmarks = get_file_bookmarks(bookmarks); + + if (num_bookmarks > 99) { + printf("Error, file bookmarks full\n"); + } + + char cwd[PATH_MAX] = {0}; + if (getcwd(cwd, sizeof(cwd)) == NULL) { + printf("Error, unable to get current directory\n"); + return; + } + + strcpy(bookmarks[num_bookmarks].bookmark_name, bookmark_name); + strcpy(bookmarks[num_bookmarks].file_path, cwd); + strcpy(bookmarks[num_bookmarks].file_path, filename); + strcat(strcat(strcpy(bookmarks[num_bookmarks].file_path, cwd), "/"), filename); + + + num_bookmarks++; + write_file_bookmarks(bookmarks, num_bookmarks); +} + +void add_bookmark(char* to_add) { + Bookmark bookmarks[100]; + memset(bookmarks, 0, sizeof(bookmarks)); + int num_bookmarks = get_bookmarks(bookmarks); + + if (num_bookmarks > 99) { + printf("Error, bookmarks full\n"); + } + + char cwd[PATH_MAX] = {0}; + if (getcwd(cwd, sizeof(cwd)) == NULL) { + printf("Error, unable to get current directory\n"); + return; + } + + strcpy(bookmarks[num_bookmarks].bookmark_name, to_add); + strcpy(bookmarks[num_bookmarks].directory_name, cwd); + + num_bookmarks++; + write_bookmarks(bookmarks, num_bookmarks); +} + +void resolve_bookmark(char* to_resolve) { + Bookmark bookmarks[100]; + memset(bookmarks, 0, sizeof(bookmarks)); + int num_bookmarks = get_bookmarks(bookmarks); + + for (int i=0; i<num_bookmarks; i++) { + if (!strcmp(bookmarks[i].bookmark_name, to_resolve)) { + printf("%s\n", bookmarks[i].directory_name); + return; + } + } +} + +void resolve_file_bookmark(char* to_resolve) { + FileBookmark bookmarks[100]; + memset(bookmarks, 0, sizeof(bookmarks)); + int num_bookmarks = get_file_bookmarks(bookmarks); + + for (int i=0; i<num_bookmarks; i++) { + if (!strcmp(bookmarks[i].bookmark_name, to_resolve)) { + printf("%s\n", bookmarks[i].file_path); + return; + } + } +} + +void bookmark_for_current_dir() { + Bookmark bookmarks[100]; + memset(bookmarks, 0, sizeof(bookmarks)); + int num_bookmarks = get_bookmarks(bookmarks); + + char cwd[PATH_MAX] = {0}; + if (getcwd(cwd, sizeof(cwd)) == NULL) { + printf("Error, unable to get current directory\n"); + return; + } + + for (int i=0; i<num_bookmarks; i++) { + if (!strcmp(bookmarks[i].directory_name, cwd)) { + printf("-(%s)", bookmarks[i].bookmark_name); + return; + } + } +} + +void list_bookmarks() { + Bookmark bookmarks[100]; + memset(bookmarks, 0, sizeof(bookmarks)); + int num_bookmarks = get_bookmarks(bookmarks); + + for (int i=0; i<num_bookmarks; i++) { + printf("%s: %s\n", bookmarks[i].bookmark_name, bookmarks[i].directory_name); + } +} + +void list_file_bookmarks() { + FileBookmark bookmarks[100]; + memset(bookmarks, 0, sizeof(bookmarks)); + int num_bookmarks = get_file_bookmarks(bookmarks); + + for (int i=0; i<num_bookmarks; i++) { + printf("%s: %s\n", bookmarks[i].bookmark_name, bookmarks[i].file_path); + } +} + +void remove_bookmark(char* to_remove) { + Bookmark bookmarks[100]; + memset(bookmarks, 0, sizeof(bookmarks)); + int num_bookmarks = get_bookmarks(bookmarks); + + bool move_backwards = false; + + for (int i=0; i<num_bookmarks; i++) { + if (move_backwards) { + memset(bookmarks[i-1].bookmark_name, 0, sizeof(bookmarks[i-1].bookmark_name)); + memset(bookmarks[i-1].directory_name, 0, sizeof(bookmarks[i-1].directory_name)); + strcpy(bookmarks[i-1].bookmark_name, bookmarks[i].bookmark_name); + strcpy(bookmarks[i-1].directory_name, bookmarks[i].directory_name); + } + else { + if (!strcmp(bookmarks[i].bookmark_name, to_remove)) { + move_backwards = true; + } + } + } + if (move_backwards) { + num_bookmarks--; + } + write_bookmarks(bookmarks, num_bookmarks); +} + +void remove_file_bookmark(char* to_remove) { + FileBookmark bookmarks[100]; + memset(bookmarks, 0, sizeof(bookmarks)); + int num_bookmarks = get_file_bookmarks(bookmarks); + + bool move_backwards = false; + + for (int i=0; i<num_bookmarks; i++) { + if (move_backwards) { + memset(bookmarks[i-1].bookmark_name, 0, sizeof(bookmarks[i-1].bookmark_name)); + memset(bookmarks[i-1].file_path, 0, sizeof(bookmarks[i-1].file_path)); + strcpy(bookmarks[i-1].bookmark_name, bookmarks[i].bookmark_name); + strcpy(bookmarks[i-1].file_path, bookmarks[i].file_path); + } + else { + if (!strcmp(bookmarks[i].bookmark_name, to_remove)) { + move_backwards = true; + } + } + } + if (move_backwards) { + num_bookmarks--; + } + write_file_bookmarks(bookmarks, num_bookmarks); +} + +int main(int argc, char* argv[]) { + if (argc == 1) { + print_help(); + return 1; + } + + memset(file_loc, 0, 256); + memset(ranger_file_loc, 0, 256); + strcat(strcpy(file_loc, getenv("HOME")), BOOKMARK_FILE_LOCATION); + strcat(strcpy(file_bookmarks_file_loc, getenv("HOME")), FILE_BOOKMARK_FILE_LOCATION); + strcat(strcpy(ranger_file_loc, getenv("HOME")), RANGER_BOOKMARK_FILE_LOCATION); + + // Add a new bookmark for current directory + if (!strcmp(argv[1], "file")) { + if (!strcmp(argv[2], "add")) { + if (argc != 5) { + print_help(); + return 1; + } + char* to_add = argv[3]; + char* file_name = argv[4]; + add_file_bookmark(to_add, file_name); + } + // Get a bookmark + else if (!strcmp(argv[2], "get")) { + if (argc != 4) { + print_help(); + return 1; + } + char* to_resolve = argv[3]; + resolve_file_bookmark(to_resolve); + } + // List all file bookmarks + else if (!strcmp(argv[2], "list")) { + list_file_bookmarks(); + } + // Remove a bookmark by name + else if (!strcmp(argv[2], "remove")) { + if (argc != 4) { + print_help(); + return 1; + } + char* to_remove = argv[3]; + remove_file_bookmark(to_remove); + } + else { + print_help(); + return 1; + } + } else { + if (!strcmp(argv[1], "add")) { + if (argc != 3) { + print_help(); + return 1; + } + char* to_add = argv[2]; + add_bookmark(to_add); + } + // Get a bookmark + else if (!strcmp(argv[1], "get")) { + if (argc != 3) { + print_help(); + return 1; + } + char* to_resolve = argv[2]; + resolve_bookmark(to_resolve); + } + // Print the current directory's bookmark, if it exists + else if (!strcmp(argv[1], "current")) { + bookmark_for_current_dir(); + } + // List all bookmarks + else if (!strcmp(argv[1], "list")) { + list_bookmarks(); + } + // Remove a bookmark by name + else if (!strcmp(argv[1], "remove")) { + if (argc != 3) { + print_help(); + return 1; + } + char* to_remove = argv[2]; + remove_bookmark(to_remove); + } + else { + print_help(); + return 1; + } + } +} diff --git a/terminal-scripts/github_latest_release.sh b/terminal-scripts/github_latest_release.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +user_name="$1" +repo_name="$2" + +latest_tag=$(curl -w "%{redirect_url}" https://github.com/${user_name}/${repo_name}/releases/latest/ | sed 's/.*\///g') + +echo https://github.com/${user_name}/${repo_name}/archive/refs/tags/${latest_tag}.zip diff --git a/terminal-scripts/hashfolder.sh b/terminal-scripts/hashfolder.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +# Script to get sha256/sha512 hashes of all files in a directory + +if [[ "$1" == "" ]]; then + echo "Usage: ./hashfolder.sh [-l] folder" + echo " -l for sha512" + exit +fi + +hash_command="sha256sum" +input_folder="$1" +if [[ "$1" == "-h" ]]; then + echo "Usage: hashfolder [-l] folder/ (-l for sha512 instead of sha256)" +elif [[ "$1" == "-l" ]]; then + hash_command="sha512sum" + input_folder="$2" +fi + +# There is probably a better way of doing this +oldIFS="$IFS" +IFS=$'\n' +filesA=( $(find "$input_folder" -type f | sort) ) +IFS="$oldIFS" + +for fileA in "${filesA[@]}"; do + "$hash_command" "$fileA" +done diff --git a/terminal-scripts/heic-to-jpg.sh b/terminal-scripts/heic-to-jpg.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +oldIFS="$IFS" +IFS=$'\n' + +files=( $(find . -maxdepth 1 -type f | grep -i heic) ) + +for file in "${files[@]}"; do + echo "Converting ${file} to jpg" + file_name_without_extension="${file%.*}" + magick "${file}" "${file_name_without_extension}.jpg" +done + +echo "All done" diff --git a/terminal-scripts/tablealigner.go b/terminal-scripts/tablealigner.go @@ -0,0 +1,209 @@ +package main + +import ( + "fmt" + "unicode/utf8" + "os" + "strings" + "regexp" + "os/exec" + //"strconv" +) + +func Print(str string) { + cmd := exec.Command("notify-send", str) + cmd.Run() +} + +var EMOJIS []rune = []rune{'❌', '✅', '❔', '❓', '📅', '🚗', '🌙', '⏳'} + +func isEmoji(r rune) bool { + for _, emoji := range EMOJIS { + if r == emoji { + return true + } + } + return false +} + +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++ + } + } + return length +} + +func readFile(filename string) []string { + dat, err := os.ReadFile(filename) + if err != nil { + panic(err) + } + + return strings.Split(string(dat), "\n") +} + +func testForAlignRow(line string) bool { + if len(line) < 1 { + return false + } + + if line[0] != '|' || line[len(line)-1] != '|' { + return false + } + split := strings.Split(line, "|") + var isCorrect = regexp.MustCompile("^(-*:* *)*$").MatchString + for _, x := range split { + if !isCorrect(x) { + return false + } + } + + return true +} + +func testForEnd(line string) bool { + if len(line) == 0 || line[0] != '|' { + return true + } + return false +} + +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}) + inTable = true + } else if inTable && testForEnd(line) { + tables[len(tables)-1] = append(tables[len(tables)-1], i-1) + inTable = false + } + } + + return tables +} + +func calcLengths(thisTable []string) []int { + numCells := strings.Count(thisTable[0], "|") - 1 + + 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 + } + } + } + return columnLengths +} + +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, " ") + " " + var cellLen int = properLen(cell) + if cellLen != columnLengths[j] { + var paddedCell string = padCell(cell, cellLen, i, j, columnLengths) + newCells = append(newCells, paddedCell) + + } else { + newCells = append(newCells, cell) + } + } + // Build new row string + var newCellString string = "|" + for _, cell := range newCells { + newCellString = newCellString + cell + "|" + } + thisTable[i] = newCellString + } + return data +} + +func padCell(cell string, cellLen int, i int, j int, columnLengths []int) string { + var paddedCell string + if i == 1 { + paddedCell = " :" + strings.Repeat("-", columnLengths[j]-4) + ": " + } else { + paddedCell = cell + strings.Repeat(" ", columnLengths[j]-cellLen) + } + return paddedCell +} + +func alignTables(tables [][]int, data []string) []string { + for _, table := range tables { + data = alignTable(table, data) + } + return data +} + +func saveToFile(data []string, filename string) { + if len(data[len(data)-1]) == 0 { + data = data[:len(data)-1] + } + var toSave string + for _, line := range data { + toSave = toSave + line + "\n" + } + err := os.WriteFile(filename, []byte(toSave), 0666) + if err != nil { + panic(err) + } +} + +func main() { + if len(os.Args) != 3 { + 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/wm-scripts/altgrtosuper.sh b/wm-scripts/altgrtosuper.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env sh + +# Remove mod5 from AltGr +xmodmap -e 'remove mod5 = ISO_Level3_Shift' +# Map it to Super_L +xmodmap -e 'keycode 108 = Super_L' + +# ksuperkey has to be launched/restarted after doing this, otherwise it will not recognise AltGr as Super +pkill ksuperkey +ksuperkey