Skip to content

Instantly share code, notes, and snippets.

@NegatioN
Created February 3, 2025 11:43
Show Gist options
  • Save NegatioN/b8aa937b3b409b6a381fd6fd2fd82daf to your computer and use it in GitHub Desktop.
Save NegatioN/b8aa937b3b409b6a381fd6fd2fd82daf to your computer and use it in GitHub Desktop.
Recursively convert epubs to mobi of a folder
#!/usr/bin/env fish
# Check if directory path is provided as an argument
if test (count $argv) -eq 0
echo "Usage: $argv[0] <directory>"
exit 1
end
function list_epub
# Check if directory path and extension are provided as arguments
if test (count $argv) -lt 1
echo "Usage: $argv[0] <directory>"
exit 1
end
# Get the directory path and extension from the arguments
set dir $argv[1]
# Use the 'find' command to list files with the given extension recursively
find $dir -type f -name "*.epub"
end
# Get the directory path from the argument
set dir $argv[1]
# Loop through each file in the directory and echo the filename
for file in (find $dir -type f -name "*.epub")
echo $file
set fname (basename $file)
set d (dirname $file)
set parts (string split -r -m 1 '.' $fname)
set base $parts[1]
ebook-convert $file "$d/$base.mobi"
echo "Done converting $base to mobi"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment