68 lines
2.2 KiB
Plaintext
68 lines
2.2 KiB
Plaintext
# Compression
|
|
compress() { tar -czf "${1%/}.tar.gz" "${1%/}"; }
|
|
alias decompress="tar -xzf"
|
|
|
|
# Write iso file to sd card
|
|
iso2sd() {
|
|
if [ $# -ne 2 ]; then
|
|
echo "Usage: iso2sd <input_file> <output_device>"
|
|
echo "Example: iso2sd ~/Downloads/ubuntu-25.04-desktop-amd64.iso /dev/sda"
|
|
echo -e "\nAvailable SD cards:"
|
|
lsblk -d -o NAME | grep -E '^sd[a-z]' | awk '{print "/dev/"$1}'
|
|
else
|
|
sudo dd bs=4M status=progress oflag=sync if="$1" of="$2"
|
|
sudo eject $2
|
|
fi
|
|
}
|
|
|
|
# Format an entire drive for a single partition using ext4
|
|
format-drive() {
|
|
if [ $# -ne 2 ]; then
|
|
echo "Usage: format-drive <device> <name>"
|
|
echo "Example: format-drive /dev/sda 'My Stuff'"
|
|
echo -e "\nAvailable drives:"
|
|
lsblk -d -o NAME -n | awk '{print "/dev/"$1}'
|
|
else
|
|
echo "WARNING: This will completely erase all data on $1 and label it '$2'."
|
|
read -rp "Are you sure you want to continue? (y/N): " confirm
|
|
if [[ "$confirm" =~ ^[Yy]$ ]]; then
|
|
sudo wipefs -a "$1"
|
|
sudo dd if=/dev/zero of="$1" bs=1M count=100 status=progress
|
|
sudo parted -s "$1" mklabel gpt
|
|
sudo parted -s "$1" mkpart primary ext4 1MiB 100%
|
|
sudo mkfs.ext4 -L "$2" "$([[ $1 == *"nvme"* ]] && echo "${1}p1" || echo "${1}1")"
|
|
echo "Drive $1 formatted and labeled '$2'."
|
|
fi
|
|
fi
|
|
}
|
|
|
|
# Transcode a video to a good-balance 1080p that's great for sharing online
|
|
transcode-video-1080p() {
|
|
ffmpeg -i $1 -vf scale=1920:1080 -c:v libx264 -preset fast -crf 23 -c:a copy ${1%.*}-1080p.mp4
|
|
}
|
|
|
|
# Transcode a video to a good-balance 4K that's great for sharing online
|
|
transcode-video-4K() {
|
|
ffmpeg -i $1 -c:v libx265 -preset slow -crf 24 -c:a aac -b:a 192k ${1%.*}-optimized.mp4
|
|
}
|
|
|
|
# Transcode any image to JPG image that's great for shrinking wallpapers
|
|
img2jpg() {
|
|
magick $1 -quality 95 -strip ${1%.*}.jpg
|
|
}
|
|
|
|
# Transcode any image to JPG image that's great for sharing online without being too big
|
|
img2jpg-small() {
|
|
magick $1 -resize 1080x\> -quality 95 -strip ${1%.*}.jpg
|
|
}
|
|
|
|
# Transcode any image to compressed-but-lossless PNG
|
|
img2png() {
|
|
magick "$1" -strip -define png:compression-filter=5 \
|
|
-define png:compression-level=9 \
|
|
-define png:compression-strategy=1 \
|
|
-define png:exclude-chunk=all \
|
|
"${1%.*}.png"
|
|
}
|
|
|