*small changes to mangaterm

master
Alex 2022-09-17 02:44:44 -05:00
parent b73c2b2114
commit ad8e4780e8
1 changed files with 16 additions and 10 deletions

View File

@ -1,9 +1,17 @@
#!/bin/bash #!/bin/sh
#using PID for dirname in case multiple instances are opened they do not interfere #using PID for dirname in case multiple instances are opened they do not interfere
CACHEDIR="$HOME/.cache/mangaterm" CACHEDIR="$HOME/.cache/mangaterm"
TMPDIR="$CACHEDIR/$$" TMPDIR="$CACHEDIR/$$"
# read_char var
# from: https://stackoverflow.com/a/30022297
read_char() {
stty -icanon -echo
eval "$1=\$(dd bs=1 count=1 2>/dev/null)"
stty icanon echo
}
help() { help() {
echo "Read manga/comics in the terminal" echo "Read manga/comics in the terminal"
echo " mangaterm.sh DIRECTORY" echo " mangaterm.sh DIRECTORY"
@ -21,7 +29,7 @@ disp() {
clear clear
[ -f "$FILE" ] && chafa -C on "$FILE" [ -f "$FILE" ] && chafa -C on "$FILE"
echo -n "$FILE" printf "%s" "$FILE"
} }
close() { close() {
@ -30,29 +38,25 @@ close() {
exit exit
} }
readDir() { readDir() {
DIR="$(echo "$1" | xargs)" DIR="$(echo "$1" | xargs)"
#if opening an archive that created a subdirectory, open subdirectories until there are multiple files #if opening an archive that created a subdirectory, open subdirectories until there are multiple files
SDIR="$(ls -A "$DIR")" SDIR="$(ls -A "$DIR")"
if [ "$(echo "$SDIR" | wc -l)" = "1" ]; then if [ "$(echo "$SDIR" | wc -l)" = "1" ]; then
echo "==============="
ls "$SDIR"
echo "XXXXXXXXXXXXXX"
if [ -d "$DIR/$SDIR" ]; then if [ -d "$DIR/$SDIR" ]; then
readDir "$DIR"/"$SDIR" readDir "$DIR"/"$SDIR"
fi fi
fi fi
echo "before FILES"
FILES="$(ls "$DIR")" FILES="$(ls "$DIR")"
LEN="$(echo "$FILES" | wc -l)" LEN="$(echo "$FILES" | wc -l)"
disp "1" disp "1"
I=1 I=1
while read -n 1 char; do #TODO this read is bash specific
while read_char char; do
if [ "$char" = "j" ]; then if [ "$char" = "j" ]; then
I=$((I + 1)) I=$((I + 1))
elif [ "$char" = "k" ]; then elif [ "$char" = "k" ]; then
@ -87,11 +91,13 @@ handleFile() {
esac esac
} }
trap 'close' 2
trap 'close' 15
mkdir -p "$TMPDIR" mkdir -p "$TMPDIR"
ARGS="$1"
if [ "$(echo "$1" | cut -c1-1)" = "-" ]; then if [ "$(echo "$1" | cut -c1-1)" = "-" ]; then
foot -e mangaterm "$2" 2>/dev/null > /dev/null foot -e mangaterm "$2" 2>/dev/null > /dev/null
fi fi
handleFile "$ARGS" handleFile "$1"