initial commit

This commit is contained in:
hollorol 2024-07-31 23:12:49 +02:00
commit f56ffe480d
17 changed files with 279 additions and 0 deletions

8
Makefile Normal file
View File

@ -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

4
README.md Normal file
View File

@ -0,0 +1,4 @@
dependencies:
- xclip
- rofi
- python3

11
textmagicscripts/edit Executable file
View File

@ -0,0 +1,11 @@
#!/bin/bash
set -euo pipefail
cat > /tmp/hollorol_edit
st -e nvim /tmp/hollorol_edit
cat /tmp/hollorol_edit

View File

@ -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

7
textmagicscripts/lower Executable file
View File

@ -0,0 +1,7 @@
#!/usr/bin/env python3
import sys
if __name__ == "__main__":
for line in sys.stdin:
print(line.lower(),end='')

42
textmagicscripts/mtalign Executable file
View File

@ -0,0 +1,42 @@
#!/usr/bin/python3
import re
import sys
import os
import copy
ISPIPE = re.compile(r'(?<!\\)\|')
def calc_colnums(rows):
colsizes = [0]
for row in rows:
for ind,cell in enumerate(row):
if (len(colsizes) -1) < ind:
colsizes.append(0)
cell_size = len(cell.strip())
if cell_size > 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)

3
textmagicscripts/number_line Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
nl -s ". "

8
textmagicscripts/regex Executable file
View File

@ -0,0 +1,8 @@
#!/bin/bash
set -eou pipefail
cat > /tmp/regex_tmp_hr
regex=$(rofi -dmenu -window-title 'regular expression')
</tmp/regex_tmp_hr sed "$regex"

40
textmagicscripts/sanitize Executable file
View File

@ -0,0 +1,40 @@
#!/usr/bin/python3
"""
This is a very-very simple filename sanitizer program written in python
"""
import sys # argv
import os # rename
import unicodedata as unid # normalize
sys.tracebacklimit = 0
def test_special_char(my_char):
"""
Test if a character is special in terms of filename
"""
char_num = ord(my_char)
if char_num > 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))

View File

@ -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)

View File

@ -0,0 +1,43 @@
/*
* This simple program is created by Roland Hollós (hollorol@rolandhollos.net)
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#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;
}

BIN
textmagicscripts/snake_to_cammel Executable file

Binary file not shown.

View File

@ -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)

View File

@ -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<stdio.h>
#include<stdlib.h>
#include<string.h>
#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;
}

BIN
textmagicscripts/space_to_snake Executable file

Binary file not shown.

7
textmagicscripts/upper Executable file
View File

@ -0,0 +1,7 @@
#!/usr/bin/env python3
import sys
if __name__ == "__main__":
for line in sys.stdin:
print(line.upper(),end='')

44
tm Executable file
View File

@ -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