commit f56ffe480d905db44185b9c66b7f21d03280df63 Author: hollorol Date: Wed Jul 31 23:12:49 2024 +0200 initial commit diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7fec7bd --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +DEST ?= $(HOME)/.local +install: + cp -r ./textmagicscripts $(DEST)/bin/ + cp ./tm $(DEST)/bin/ +uninstall: + rm -r $(DEST)/bin/textmagicsripts + rm $(DEST)/bin/tm + diff --git a/README.md b/README.md new file mode 100644 index 0000000..bd10bfd --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +dependencies: +- xclip +- rofi +- python3 diff --git a/textmagicscripts/edit b/textmagicscripts/edit new file mode 100755 index 0000000..834de50 --- /dev/null +++ b/textmagicscripts/edit @@ -0,0 +1,11 @@ +#!/bin/bash + +set -euo pipefail + +cat > /tmp/hollorol_edit + +st -e nvim /tmp/hollorol_edit + +cat /tmp/hollorol_edit + + diff --git a/textmagicscripts/google_link_to_wget b/textmagicscripts/google_link_to_wget new file mode 100755 index 0000000..b357a7d --- /dev/null +++ b/textmagicscripts/google_link_to_wget @@ -0,0 +1,7 @@ +#!/bin/bash + +while read LINK; do + DOCNAME=$(curl -s "$LINK" | grep -oP "'title': '.*?'" | sed -E "s/'title': '(.*)'/\1/") + DOCID=$(echo "$LINK" | sed -E 's/.*d\/(.*)\/view.*/\1/') + echo "wget -O $DOCNAME \"https://drive.usercontent.google.com/download?id=$DOCID""&confirm=t\"" +done diff --git a/textmagicscripts/lower b/textmagicscripts/lower new file mode 100755 index 0000000..63847a8 --- /dev/null +++ b/textmagicscripts/lower @@ -0,0 +1,7 @@ +#!/usr/bin/env python3 + +import sys + +if __name__ == "__main__": + for line in sys.stdin: + print(line.lower(),end='') diff --git a/textmagicscripts/mtalign b/textmagicscripts/mtalign new file mode 100755 index 0000000..a041890 --- /dev/null +++ b/textmagicscripts/mtalign @@ -0,0 +1,42 @@ +#!/usr/bin/python3 + +import re +import sys +import os +import copy + +ISPIPE = re.compile(r'(? colsizes[ind]: + colsizes[ind] = cell_size + return colsizes + +def pad_cells_and_center(rows): + pad = 1 + cells_to_pad = copy.deepcopy(rows) + colsizes = calc_colnums(rows) + for row_id,row in enumerate(cells_to_pad): + for col_ind,cell in enumerate(row): + cell_size = len(cell.strip()) + numspaces = (colsizes[col_ind] - cell_size) + pad + if row_id == 1: + cells_to_pad[row_id][col_ind] = ' ' * pad + '-' * colsizes[col_ind] + ' ' * pad + continue + cells_to_pad[row_id][col_ind] = ' ' * pad + cell.strip() + ' '* numspaces + return(cells_to_pad) + +if __name__ == "__main__": + table = [] + for row_string in sys.stdin: + table.append(ISPIPE.split(row_string.strip())[1:-1]) + table = pad_cells_and_center(table) + for row in ['|' + '|'.join(r) + '|' for r in table]: + print(row) + diff --git a/textmagicscripts/number_line b/textmagicscripts/number_line new file mode 100755 index 0000000..a10a886 --- /dev/null +++ b/textmagicscripts/number_line @@ -0,0 +1,3 @@ +#!/bin/bash + +nl -s ". " diff --git a/textmagicscripts/regex b/textmagicscripts/regex new file mode 100755 index 0000000..c6f81d5 --- /dev/null +++ b/textmagicscripts/regex @@ -0,0 +1,8 @@ +#!/bin/bash + +set -eou pipefail + +cat > /tmp/regex_tmp_hr +regex=$(rofi -dmenu -window-title 'regular expression') + + 127: # case ß + return False + + return ( + my_char.isalnum() or + char_num == 95 or + char_num == 47 or + char_num == 46 or + char_num == 45 + ) and (char_num < 127) + + +def sanitize(filename): + """ + A simple filename sanitizer + """ + spaceless_unicode = ["_" if i == " " else i for i in filename] + spaceless_unicode = unid.normalize("NFKD", "".join(spaceless_unicode)) + ret = [i if test_special_char(i) else "" for i in spaceless_unicode] + return "".join(ret) + + +if __name__ == "__main__": + for row in sys.stdin: + print(sanitize(row)) diff --git a/textmagicscripts/snake-to-cammel/Makefile b/textmagicscripts/snake-to-cammel/Makefile new file mode 100644 index 0000000..5750c49 --- /dev/null +++ b/textmagicscripts/snake-to-cammel/Makefile @@ -0,0 +1,8 @@ +DEST=$(HOME)/.local/bin +SRC=snake-to-cammel.c +OUT=../snake_to_cammel + +$(OUT): $(SRC) + gcc -pedantic -Wall -Wextra $(SRC) -o $(OUT) +install: + cp $(OUT) $(DEST) diff --git a/textmagicscripts/snake-to-cammel/snake-to-cammel.c b/textmagicscripts/snake-to-cammel/snake-to-cammel.c new file mode 100644 index 0000000..796337c --- /dev/null +++ b/textmagicscripts/snake-to-cammel/snake-to-cammel.c @@ -0,0 +1,43 @@ +/* + * This simple program is created by Roland Hollós (hollorol@rolandhollos.net) + */ +#include +#include +#include + +#define MAX_LINE_LEN 10000 + +int +main() +{ + char s[MAX_LINE_LEN]; + char out[MAX_LINE_LEN]; + while(fgets(s, MAX_LINE_LEN, stdin) != NULL){ + int string_length = strlen(s); + int k = 0; + int under = 0; + for(int i = 0; i < string_length; ++i) + { + /* if((s[i] >= 65) && (s[i] <= 90)) */ + if((s[i] == '_') && !under){ + under = 1; + continue; + } + + if((s[i] <= 122) && (s[i] >= 90) && under) + { + out[k] = s[i] - 32; + k++; + under = 0; + continue; + } + + out[k] = s[i]; + k++; + under = 0; + } + out[k] = '\0'; + printf("%s", out); + } + return 0; +} diff --git a/textmagicscripts/snake_to_cammel b/textmagicscripts/snake_to_cammel new file mode 100755 index 0000000..b8f4c86 Binary files /dev/null and b/textmagicscripts/snake_to_cammel differ diff --git a/textmagicscripts/space-to-snake/Makefile b/textmagicscripts/space-to-snake/Makefile new file mode 100644 index 0000000..543e25a --- /dev/null +++ b/textmagicscripts/space-to-snake/Makefile @@ -0,0 +1,8 @@ +DEST=$(HOME)/.local/bin +SRC=space-to-snake.c +OUT=space_to_snake + +../$(OUT): $(SRC) + gcc -pedantic -Wall -Wextra $(SRC) -o ../$(OUT) +install: + cp ../$(OUT) $(DEST) diff --git a/textmagicscripts/space-to-snake/space-to-snake.c b/textmagicscripts/space-to-snake/space-to-snake.c new file mode 100644 index 0000000..f1c1524 --- /dev/null +++ b/textmagicscripts/space-to-snake/space-to-snake.c @@ -0,0 +1,39 @@ +/* + * This simple program is created by Roland Hollós (hollorol@rolandhollos.net) + * It is works like this: +* ez itt egy nagyon hosszu valtozo == ez_itt_egy_nagyon_hosszu_valtozo_ + */ +#include +#include +#include + +#define MAX_LINE_LEN 10000 + +int +main() +{ + char s[MAX_LINE_LEN]; + char out[MAX_LINE_LEN]; + + while(fgets(s, MAX_LINE_LEN, stdin) != NULL){ + int string_length = strlen(s); + for(int i = 0; i < string_length; ++i) + { + /* if((s[i] >= 65) && (s[i] <= 90)) */ + if(s[i] == ' '){ + out[i] = '_'; + continue; + } + + if((s[i] >= 65) && (s[i] <= 90)) + { + out[i] = s[i] + 32; + } + out[i] = s[i]; + + } + out[string_length] = '\0'; + printf("%s", out); + } + return 0; +} diff --git a/textmagicscripts/space_to_snake b/textmagicscripts/space_to_snake new file mode 100755 index 0000000..a5f861e Binary files /dev/null and b/textmagicscripts/space_to_snake differ diff --git a/textmagicscripts/upper b/textmagicscripts/upper new file mode 100755 index 0000000..b81e74a --- /dev/null +++ b/textmagicscripts/upper @@ -0,0 +1,7 @@ +#!/usr/bin/env python3 + +import sys + +if __name__ == "__main__": + for line in sys.stdin: + print(line.upper(),end='') diff --git a/tm b/tm new file mode 100755 index 0000000..f24ec4b --- /dev/null +++ b/tm @@ -0,0 +1,44 @@ +#!/bin/bash + +set -eou pipefail + +SCRIPTLOC="$HOME/.local/bin/textmagicscripts" + +printResult () { + scriptname="$1" + script=$(echo $scriptname | head -c -3) + eval "xclip -o | $SCRIPTLOC"/"$script | xclip -sel c" + active_window_id=$(xdotool getactivewindow) + if [ -z "$(xprop -id $active_window_id WM_CLASS | grep -o terminal | head -n 1)" ] + then + xdotool key ctrl+v + else + xdotool key ctrl+shift+v + fi + +} + +export -f printResult + + +find $SCRIPTLOC -maxdepth 1 -type f -exec basename {} \; | while read line; +do + for i in {p,c} + do + echo ${line}_$i + done +done | \ + rofi -dmenu --window-title "TexMagics" -matching regex | \ + while read scriptname; + do + insertmode=$(echo $scriptname | tail -c 2) + + case $insertmode in + p) + printResult $scriptname;; + c) + script=$(echo $scriptname | head -c -3) + eval "xclip -o | $SCRIPTLOC"/"$script | xclip -sel c";; + esac + done +