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