dev-resources.site
for different kinds of informations.
My personal detox command
Published at
6/28/2024
Categories
detox
termux
tools
rename
Author
voyeg3r
Author
7 person written this
voyeg3r
open
The original detox
It is perfect but in termux i do not have it in my repositories, so:
#!/bin/bash
#
# Script: dtx
# Description: Rename files by removing special characters and normalizing names.
#
# Usage: dtx [-d] [-h] files...
# Options:
# -d Dry run. Show the final result without renaming.
# -h Show this help message.
#
# Dependencies: Requires Python 3 and the 'unidecode' module. Install with:
# pip install unidecode
#
# Get the script name dynamically
script_name=$(basename "${BASH_SOURCE[0]}")
show_help() {
echo "Usage: $script_name [-d] [-h] files..."
echo "Rename files by removing special characters and normalizing names."
echo
echo "Options:"
echo " -d Dry run. Show the final result without renaming."
echo " -h Show this help message."
}
check_unidecode() {
python3 -c 'import unidecode' >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Error: Python module 'unidecode' not found."
echo "Please install it using:"
echo " pip install unidecode"
exit 1
fi
}
dry_run=false
# Check if unidecode module is available
check_unidecode
# Parse options
while getopts "dh" opt; do
case ${opt} in
d )
dry_run=true
;;
h )
show_help
exit 0
;;
\? )
show_help
exit 1
;;
esac
done
shift $((OPTIND -1))
if [ "$#" -lt 1 ]; then
show_help
exit 1
fi
for file in "$@"; do
if [ -d "$file" ]; then
# Transliterate UTF-8 characters to ASCII using Python unidecode for directories
new_filename=$(echo "$file" | python3 -c 'import sys, unicodedata; filename = sys.stdin.read().strip(); filename = unicodedata.normalize("NFD", filename).encode("ascii", "ignore").decode("ascii").replace(" ", "-").replace("_", "-").replace("/", "-").replace(".", "-"); filename = "-".join(filter(None, filename.split("-"))); print(filename)')
# Check if the directory name needs to be changed
if [ "$file" != "$new_filename" ]; then
if [ "$dry_run" = true ]; then
echo "Would rename directory: '$file' -> '$new_filename'"
else
mv -v "$file" "$new_filename"
fi
else
if [ "$dry_run" = true ]; then
echo "Skipping directory: '$file', already correctly named."
fi
fi
else
# Separate filename and extension using parameter expansion
filename=$(basename -- "$file")
extension="${filename##*.}"
filename="${filename%.*}"
# Transliterate UTF-8 characters to ASCII using Python unidecode for files
new_filename=$(echo "$filename" | python3 -c 'import sys, unicodedata; filename = sys.stdin.read().strip(); filename = unicodedata.normalize("NFD", filename).encode("ascii", "ignore").decode("ascii").replace(" ", "-").replace("_", "-").replace("/", "-").replace(".", "-"); filename = "-".join(filter(None, filename.split("-"))); print(filename)')
# Construct the new filename with the preserved extension
newname="${new_filename}.${extension}"
# Check if the filename needs to be changed
if [ "$file" != "$newname" ]; then
if [ "$dry_run" = true ]; then
echo "Would rename file: '$file' -> '$newname'"
else
mv -v "$file" "$newname"
fi
else
if [ "$dry_run" = true ]; then
echo "Skipping file: '$file', already correctly named."
fi
fi
fi
done
termux Article's
30 articles in total
่ฎฉๅฎๅๆๆบไธๅๅ็ฐ๏ผๅจๅฎๅๆๆบไธๆญๅปบ Rust ๅผๅ็ฏๅข
read article
How to install React and Tailwind in Termux
read article
Small prototype... easy coding flash cards on android
read article
Run qBittorrent in Android
read article
Setup pygame in termux
read article
Termux-Ngrok Configuration
read article
How To Install Termux Box In Termux
read article
My personal detox command
currently reading
Como rodar um servidor NodeJS em um smartphone Android
read article
Run a Linux Distro in your Android device
read article
Install Official VS Code on Android
read article
Automatically Change IP Address ุชุบูุฑ ุงู ุจู ุจุดูู ุชููุงุฆู ูุงูู ููููุณ
read article
Linux On The Go (Termux)
read article
How To Install Lemon Rat In Termux 2024
read article
git diary
read article
Line Highlighting in Zsh Termux
read article
How To Install Code-Server On Android
read article
Installing NodeJS In Termux
read article
Obsidian Notes with git-crypt ๐
read article
Install Pfetch on Termux
read article
Youtube Two Click MP3 Downloader - Termux!
read article
HOW TO INSTALL NGROK IN TERMUX ANDROID
read article
Setting up Termux and a Linux Distro on Android
read article
New Github Repo
read article
Termux logo in python
read article
Termux getting terminated after 15s on starting the VNC server.
read article
Setting Up Termux and Node.js on Android for Web Development
read article
Programando pelo Tablet
read article
How to connect your android device to github using ssh key with termux
read article
Host TOR Hidden service (DARK WEB website) on a smartphone !!
read article
Featured ones: