Skip to content

Commit 6d8dd28

Browse files
committed
added newly added words and copy to library and string replacement scenarios to ebook menu
1 parent addbb37 commit 6d8dd28

2 files changed

Lines changed: 922 additions & 824 deletions

File tree

bin/ebookmenu

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,20 @@ source "$DOTFILES/bash/functions/flatpak_functions.sh"
1515
TEMP_PATH="$EBOOKS/Temp"
1616
DRM_PATH="$TEMP_PATH/drm"
1717
LIBRARY_PATH="$EBOOKS/Library"
18+
NOTES_PATH="$HOME/Notes/Obsidian"
1819

1920
# Check if fzf is installed
2021
if ! command -v fzf >/dev/null 2>&1; then
2122
echo "Error: 'fzf' is required but not installed. Please install fzf to use this menu."
2223
exit 1
2324
fi
2425

26+
function select_file_from_library() {
27+
# we ignore the shell check here since we want to echo the result rather than just let it disappear
28+
# shellcheck disable=SC2005
29+
echo "$(find "$LIBRARY_PATH" -type f -name "*.epub" | fzf --prompt="Select EPUB file> " --height=15 --border --layout=reverse --exit-0)"
30+
}
31+
2532
# TODO: can the logic in this file be refactored/made easier to use and maintain?
2633

2734
# Menu options
@@ -34,6 +41,8 @@ MENU_OPTIONS=(
3441
"Mass Rename"
3542
"Rename"
3643
"Update"
44+
"Copy from Library"
45+
"Replace Strings"
3746
)
3847

3948
# Main menu with fzf
@@ -86,7 +95,6 @@ case "$CHOICE" in
8695
# TODO move this out of loop and just cut it down to actions
8796
# add logic for TUI manual fixes
8897
# add logic for non-TUI manual fixes
89-
# add logic for moving tl notes in file
9098
UPDATE_OPTIONS=(
9199
"validateepub: Validate EPUB"
92100
"validateandfixepub: Validate and Fix EPUB"
@@ -104,7 +112,6 @@ case "$CHOICE" in
104112
validateepub "$EPUBFILE" out.txt && fixepub "$EPUBFILE" out.txt && rm out.txt && validateepub "$EPUBFILE"
105113
;;
106114
manuallyfixableissues)
107-
# echo "TODO: Display manually fixable issues (to implement later...)"
108115
epubmanualfixes "$EPUBFILE" "use-tui"
109116
;;
110117
editeepub)
@@ -147,6 +154,37 @@ case "$CHOICE" in
147154
esac
148155
done
149156
;;
157+
"Copy from Library")
158+
EPUBFILE="$(select_file_from_library)"
159+
[ -z "$EPUBFILE" ] && echo "You must select an actual file" && exit 0
160+
161+
DESTINATION_FOLDER="$TEMP_PATH/$(basename "$(dirname "$EPUBFILE")")"
162+
163+
[[ ! -d "$DESTINATION_FOLDER" ]] && mkdir "$DESTINATION_FOLDER"
164+
165+
cp "$EPUBFILE" "$DESTINATION_FOLDER"
166+
echo "Copied $(basename "$EPUBFILE") to $DESTINATION_FOLDER"
167+
;;
168+
"Replace Strings")
169+
REPLACEMENTS_FILE="$NOTES_PATH/replaceme.md"
170+
[[ ! -f "$REPLACEMENTS_FILE" ]] && echo "Replacements file \"$REPLACEMENTS_FILE\" must exist in order to run string replacements" && exit 0
171+
172+
EPUBFILE="$(select_file_from_library)"
173+
[ -z "$EPUBFILE" ] && echo "You must select an actual file" && exit 0
174+
175+
DESTINATION_FOLDER="$TEMP_PATH/$(basename "$(dirname "$EPUBFILE")")"
176+
177+
[[ ! -d "$DESTINATION_FOLDER" ]] && mkdir "$DESTINATION_FOLDER"
178+
179+
cp "$EPUBFILE" "$DESTINATION_FOLDER"
180+
181+
EPUB_NAME="$(basename "$EPUBFILE")"
182+
echo "Copied $EPUB_NAME to $DESTINATION_FOLDER"
183+
184+
TEMP_EPUB="$DESTINATION_FOLDER/$EPUB_NAME"
185+
186+
epubreplaceallstrings "$TEMP_EPUB" "$REPLACEMENTS_FILE"
187+
;;
150188
*)
151189
# Esc or closed menu
152190
exit 0

0 commit comments

Comments
 (0)