diff --git a/.local/share/nautilus/scripts/Accessed recently/01 List SHA-256 b/.local/share/nautilus/scripts/Accessed recently/01 List SHA-256 new file mode 120000 index 0000000..49e6121 --- /dev/null +++ b/.local/share/nautilus/scripts/Accessed recently/01 List SHA-256 @@ -0,0 +1 @@ +/home/tobias/.local/share/nautilus/scripts/Hash and checksum/List SHA-256 \ No newline at end of file diff --git a/.local/share/nautilus/scripts/Accessed recently/02 Convert to 'flac' b/.local/share/nautilus/scripts/Accessed recently/02 Convert to 'flac' new file mode 120000 index 0000000..e737db8 --- /dev/null +++ b/.local/share/nautilus/scripts/Accessed recently/02 Convert to 'flac' @@ -0,0 +1 @@ +/home/tobias/.local/share/nautilus/scripts/Audio/Convert to 'flac' \ No newline at end of file diff --git a/.local/share/nautilus/scripts/Accessed recently/03 Convert to 'wav' b/.local/share/nautilus/scripts/Accessed recently/03 Convert to 'wav' new file mode 120000 index 0000000..3badcc6 --- /dev/null +++ b/.local/share/nautilus/scripts/Accessed recently/03 Convert to 'wav' @@ -0,0 +1 @@ +/home/tobias/.local/share/nautilus/scripts/Audio/Convert to 'wav' \ No newline at end of file diff --git a/.local/share/nautilus/scripts/Accessed recently/04 Convert to 'mp3' (48 kbps, mono) b/.local/share/nautilus/scripts/Accessed recently/04 Convert to 'mp3' (48 kbps, mono) new file mode 120000 index 0000000..386bcf9 --- /dev/null +++ b/.local/share/nautilus/scripts/Accessed recently/04 Convert to 'mp3' (48 kbps, mono) @@ -0,0 +1 @@ +/home/tobias/.local/share/nautilus/scripts/Audio/Convert to 'mp3' (48 kbps, mono) \ No newline at end of file diff --git a/.local/share/nautilus/scripts/Accessed recently/05 Convert to 'png' b/.local/share/nautilus/scripts/Accessed recently/05 Convert to 'png' new file mode 120000 index 0000000..65ac7e0 --- /dev/null +++ b/.local/share/nautilus/scripts/Accessed recently/05 Convert to 'png' @@ -0,0 +1 @@ +/home/tobias/.local/share/nautilus/scripts/Image/Convert/Convert to 'png' \ No newline at end of file diff --git a/.local/share/nautilus/scripts/Accessed recently/06 Verify 'md5sum.txt' b/.local/share/nautilus/scripts/Accessed recently/06 Verify 'md5sum.txt' new file mode 120000 index 0000000..3fe03a7 --- /dev/null +++ b/.local/share/nautilus/scripts/Accessed recently/06 Verify 'md5sum.txt' @@ -0,0 +1 @@ +/home/tobias/.local/share/nautilus/scripts/Hash and checksum/Verify 'md5sum.txt' \ No newline at end of file diff --git a/.local/share/nautilus/scripts/Accessed recently/07 Produce 'md5sum.txt' b/.local/share/nautilus/scripts/Accessed recently/07 Produce 'md5sum.txt' new file mode 120000 index 0000000..60eea5d --- /dev/null +++ b/.local/share/nautilus/scripts/Accessed recently/07 Produce 'md5sum.txt' @@ -0,0 +1 @@ +/home/tobias/.local/share/nautilus/scripts/Hash and checksum/Produce 'md5sum.txt' \ No newline at end of file diff --git a/.local/share/nautilus/scripts/Accessed recently/08 List all hashes b/.local/share/nautilus/scripts/Accessed recently/08 List all hashes new file mode 120000 index 0000000..4da5003 --- /dev/null +++ b/.local/share/nautilus/scripts/Accessed recently/08 List all hashes @@ -0,0 +1 @@ +/home/tobias/.local/share/nautilus/scripts/Hash and checksum/List all hashes \ No newline at end of file diff --git a/.local/share/nautilus/scripts/Alacritty b/.local/share/nautilus/scripts/Alacritty new file mode 100755 index 0000000..a9b881e --- /dev/null +++ b/.local/share/nautilus/scripts/Alacritty @@ -0,0 +1,44 @@ +#!/bin/bash + +# https://help.ubuntu.com/community/NautilusScriptsHowto/SampleScripts + + # This script opens a gnome-terminal in the directory you select. + # + # Distributed under the terms of GNU GPL version 2 or later + # + # Install in ~/.gnome2/nautilus-scripts or ~/Nautilus/scripts + # You need to be running Nautilus 1.0.3+ to use scripts. + + # When a directory is selected, go there. Otherwise go to current + # directory. If more than one directory is selected, show error. + if [ -n "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" ]; then + set $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS + if [ $# -eq 1 ]; then + destination="$1" + # Go to file's directory if it's a file + if [ ! -d "$destination" ]; then + destination="`dirname "$destination"`" + fi + else + zenity --error --title="Error - Open terminal here" \ + --text="You can only select one directory." + exit 1 + fi + else + destination="`echo "$NAUTILUS_SCRIPT_CURRENT_URI" | sed 's/^file:\/\///'`" + fi + + # It's only possible to go to local directories + if [ -n "`echo "$destination" | grep '^[a-zA-Z0-9]\+:'`" ]; then + zenity --error --title="Error - Open terminal here" \ + --text="Only local directories can be used." + exit 1 + fi + + + # replace %20 with space + destination=$(echo $destination |sed -e 's/%20/ /g') + + cd "$destination" + # exec x-terminal-emulator + /home/tobias/.local/bin/alacritty --working-directory "$destination" & diff --git a/.local/share/nautilus/scripts/Archive/Compress to '7z' (each) b/.local/share/nautilus/scripts/Archive/Compress to '7z' (each) new file mode 100755 index 0000000..59eeb20 --- /dev/null +++ b/.local/share/nautilus/scripts/Archive/Compress to '7z' (each) @@ -0,0 +1,57 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _command_exists "bsdtar" || _check_dependencies " + command=7za; pkg_manager=apt; package=p7zip-full | + command=7za; pkg_manager=dnf; package=p7zip | + command=7za; pkg_manager=pacman; package=p7zip | + command=7za; pkg_manager=zypper; package=p7zip" + _display_wait_box "2" + input_files=$(_get_files "par_type=all") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=7z") + if [[ -d "$input_file" ]]; then + cd -- "$input_file" || return 1 + + if _command_exists "7za"; then + std_output=$(7za a -mx9 "$output_file" -- . 2>&1) + elif _command_exists "bsdtar"; then + std_output=$(bsdtar --strip-components 1 -a -cf "$output_file" -- . 2>&1) + fi + else + cd -- "$(_get_filename_dir "$input_file")" || return 1 + local input_file_basename="" + input_file_basename=$(basename -- "$input_file") + + if _command_exists "7za"; then + std_output=$(7za a -mx9 "$output_file" -- "$input_file_basename" 2>&1) + elif _command_exists "bsdtar"; then + std_output=$(bsdtar -a -cf "$output_file" -- "$input_file_basename" 2>&1) + fi + fi + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Archive/Compress to 'iso' (each) b/.local/share/nautilus/scripts/Archive/Compress to 'iso' (each) new file mode 100755 index 0000000..28c37c3 --- /dev/null +++ b/.local/share/nautilus/scripts/Archive/Compress to 'iso' (each) @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=genisoimage; pkg_manager=apt | + command=genisoimage; pkg_manager=dnf | + command=genisoimage; pkg_manager=pacman; package=cdrtools | + command=mkisofs; pkg_manager=zypper" + _display_wait_box "2" + input_files=$(_get_files "par_type=all") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + local volume_id="" + volume_id=$(basename -- "$input_file" | cut -c 1-32 2>/dev/null) + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=iso") + if _command_exists "mkisofs"; then + std_output=$(mkisofs -input-charset "utf-8" -o "$output_file" -V "$volume_id" -A "" -sysid "" -J -R "$input_file" 2>&1) + elif _command_exists "genisoimage"; then + std_output=$(genisoimage -input-charset "utf-8" -o "$output_file" -V "$volume_id" -A "" -sysid "" -J -R "$input_file" 2>&1) + fi + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Archive/Compress to 'squashfs' (each) b/.local/share/nautilus/scripts/Archive/Compress to 'squashfs' (each) new file mode 100755 index 0000000..f290e3a --- /dev/null +++ b/.local/share/nautilus/scripts/Archive/Compress to 'squashfs' (each) @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=mksquashfs; pkg_manager=apt; package=squashfs-tools | + command=mksquashfs; pkg_manager=dnf; package=squashfs-tools | + command=mksquashfs; pkg_manager=pacman; package=squashfs-tools | + command=mksquashfs; pkg_manager=zypper; package=squashfs" + _display_wait_box "2" + input_files=$(_get_files "par_type=all") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=squashfs") + std_output=$(mksquashfs "$input_file" "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Archive/Compress to 'tar.gz' (each) b/.local/share/nautilus/scripts/Archive/Compress to 'tar.gz' (each) new file mode 100755 index 0000000..dfbe95f --- /dev/null +++ b/.local/share/nautilus/scripts/Archive/Compress to 'tar.gz' (each) @@ -0,0 +1,46 @@ +#!/usr/bin/env bash +# install_keyboard_shortcut=G + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=tar | command=gunzip; package=gzip" + _display_wait_box "2" + input_files=$(_get_files "par_type=all") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=tar.gz") + if [[ -d "$input_file" ]]; then + local files="" + cd -- "$input_file" || return 1 + files=$(find . -mindepth 1 -maxdepth 1 -printf "%p$FIELD_SEPARATOR" | sed "s|\./||g") + std_output=$(printf "%s" "$files" | xargs --no-run-if-empty --delimiter="$FIELD_SEPARATOR" tar -czf "$output_file" --) + else + cd -- "$(_get_filename_dir "$input_file")" || return 1 + local input_file_basename="" + input_file_basename=$(basename -- "$input_file") + std_output=$(tar -czf "$output_file" -- "$input_file_basename" 2>&1) + fi + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Archive/Compress to 'tar.xz' (each) b/.local/share/nautilus/scripts/Archive/Compress to 'tar.xz' (each) new file mode 100755 index 0000000..4b0d845 --- /dev/null +++ b/.local/share/nautilus/scripts/Archive/Compress to 'tar.xz' (each) @@ -0,0 +1,55 @@ +#!/usr/bin/env bash +# install_keyboard_shortcut=X + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=tar | + command=xz; pkg_manager=apt; package=xz-utils | + command=xz; pkg_manager=dnf | + command=xz; pkg_manager=pacman | + command=xz; pkg_manager=zypper" + _display_wait_box "2" + input_files=$(_get_files "par_type=all") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Use the maximum compression. + XZ_OPT="-9" + export XZ_OPT + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=tar.xz") + if [[ -d "$input_file" ]]; then + local files="" + cd -- "$input_file" || return 1 + files=$(find . -mindepth 1 -maxdepth 1 -printf "%p$FIELD_SEPARATOR" | sed "s|\./||g") + std_output=$(printf "%s" "$files" | xargs --no-run-if-empty --delimiter="$FIELD_SEPARATOR" tar -cJf "$output_file" --) + else + cd -- "$(_get_filename_dir "$input_file")" || return 1 + local input_file_basename="" + input_file_basename=$(basename -- "$input_file") + std_output=$(tar -cJf "$output_file" -- "$input_file_basename" 2>&1) + fi + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Archive/Compress to 'tar.zst' (each) b/.local/share/nautilus/scripts/Archive/Compress to 'tar.zst' (each) new file mode 100755 index 0000000..3204dc6 --- /dev/null +++ b/.local/share/nautilus/scripts/Archive/Compress to 'tar.zst' (each) @@ -0,0 +1,46 @@ +#!/usr/bin/env bash +# install_keyboard_shortcut=S + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=tar | command=zstd" + _display_wait_box "2" + input_files=$(_get_files "par_type=all") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=tar.zst") + if [[ -d "$input_file" ]]; then + local files="" + cd -- "$input_file" || return 1 + files=$(find . -mindepth 1 -maxdepth 1 -printf "%p$FIELD_SEPARATOR" | sed "s|\./||g") + std_output=$(printf "%s" "$files" | xargs --no-run-if-empty --delimiter="$FIELD_SEPARATOR" tar --zstd -cf "$output_file" --) + else + cd -- "$(_get_filename_dir "$input_file")" || return 1 + local input_file_basename="" + input_file_basename=$(basename -- "$input_file") + std_output=$(tar --zstd -cf "$output_file" -- "$input_file_basename" 2>&1) + fi + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Archive/Compress to 'zip' (each) b/.local/share/nautilus/scripts/Archive/Compress to 'zip' (each) new file mode 100755 index 0000000..a491de6 --- /dev/null +++ b/.local/share/nautilus/scripts/Archive/Compress to 'zip' (each) @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +# install_keyboard_shortcut=Z + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=zip" + _display_wait_box "2" + input_files=$(_get_files "par_type=all") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=zip") + if [[ -d "$input_file" ]]; then + cd -- "$input_file" || return 1 + std_output=$(zip --symlinks --quiet --recurse-paths "$output_file" -- . 2>&1) + else + cd -- "$(_get_filename_dir "$input_file")" || return 1 + local input_file_basename="" + input_file_basename=$(basename -- "$input_file") + std_output=$(zip --symlinks --quiet --recurse-paths "$output_file" -- "$input_file_basename" 2>&1) + fi + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Archive/Compress... b/.local/share/nautilus/scripts/Archive/Compress... new file mode 100755 index 0000000..c3325f9 --- /dev/null +++ b/.local/share/nautilus/scripts/Archive/Compress... @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# install_keyboard_shortcut=C + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + + # Execute initial checks. + input_files=$(_get_files "par_type=all") + + # Run the main process. + # shellcheck disable=SC2086 + if _command_exists "file-roller"; then + file-roller --add -- $input_files & + elif _command_exists "ark"; then + ark --add --dialog -- $input_files & + elif _command_exists "engrampa"; then + engrampa --add -- $input_files & + elif _command_exists "lxqt-archiver"; then + lxqt-archiver --add -- $input_files & + elif _command_exists "arqiver"; then + arqiver --sa $input_files & + elif _command_exists "xarchiver"; then + xarchiver --compress=$input_files & + else + _check_dependencies "command=file-roller" + file-roller --add -- $input_files & + fi +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Archive/Extract Here b/.local/share/nautilus/scripts/Archive/Extract Here new file mode 100755 index 0000000..4fc2fc6 --- /dev/null +++ b/.local/share/nautilus/scripts/Archive/Extract Here @@ -0,0 +1,463 @@ +#!/usr/bin/env bash +# install_keyboard_shortcut=E + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + input_files=$(_get_files "par_type=file") + + local dependencies="" + dependencies=$(_get_dependencies "$input_files") + _check_dependencies "$dependencies" + _display_wait_box "0" + + export -f \ + _all_commands_exists \ + _get_command \ + _run_command + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + + # Run the main process. + local command="" + command=$(_get_command "$input_file" "available") + _run_command "$input_file" "$command" "$output_dir" +} + +_get_dependencies() { + local input_files=$1 + local dependencies="" + + # Check dependencies for each file. + for input_file in $input_files; do + local command="" + command=$(_get_command "$input_file" "available") + + # If there is an available command, skip the dependency. + if [[ -n "$command" ]]; then + continue + fi + + command=$(_get_command "$input_file" "default") + + case $command in + "7za") + dependencies+=" + command=7za; pkg_manager=apt; package=p7zip-full | + command=7za; pkg_manager=dnf; package=p7zip | + command=7za; pkg_manager=pacman; package=p7zip | + command=7za; pkg_manager=zypper; package=p7zip" + ;; + "ar") dependencies+="command=ar; package=binutils" ;; + "bsdtar") + dependencies+=" + command=bsdtar; pkg_manager=apt; package=libarchive-tools | + command=bsdtar; pkg_manager=dnf | + command=bsdtar; pkg_manager=pacman; package=libarchive | + command=bsdtar; pkg_manager=zypper" + ;; + "bsdtar+unar+7za") + dependencies+=" + command=bsdtar; pkg_manager=apt; package=libarchive-tools | + command=bsdtar; pkg_manager=dnf | + command=bsdtar; pkg_manager=pacman; package=libarchive | + command=bsdtar; pkg_manager=zypper" + dependencies+=$'\n' + dependencies+=" + command=unar; pkg_manager=apt | + command=unar; pkg_manager=dnf | + command=unar; pkg_manager=pacman; package=unarchiver | + command=unar; pkg_manager=zypper" + dependencies+=$'\n' + dependencies+=" + command=7za; pkg_manager=apt; package=p7zip-full | + command=7za; pkg_manager=dnf; package=p7zip | + command=7za; pkg_manager=pacman; package=p7zip | + command=7za; pkg_manager=zypper; package=p7zip" + ;; + "bzip2") dependencies+="command=bzip2" ;; + "cpio") dependencies+="command=cpio" ;; + "gpg") + dependencies+=" + command=gpg; pkg_manager=apt; package=gpg | + command=gpg; pkg_manager=dnf; package=gnupg2 | + command=gpg; pkg_manager=pacman; package=gnupg | + command=gpg; pkg_manager=zypper; package=gpg2" + ;; + "gzip") dependencies+="command=gzip" ;; + "lha") dependencies+="command=lha; package=lhasa" ;; + "lrzip") dependencies+="command=lrzip" ;; + "lz4") dependencies+="command=lz4" ;; + "lzip") dependencies+="command=lzip" ;; + "lzop") dependencies+="command=lzop" ;; + "tar") dependencies+="command=tar" ;; + "tar+bzip2") dependencies+="command=tar | command=bzip2" ;; + "tar+gzip") dependencies+="command=tar | command=gzip" ;; + "tar+lrzip") dependencies+="command=lrztar; package=lrzip" ;; + "tar+lz4") dependencies+="command=tar | command=lz4" ;; + "tar+lzip") dependencies+="command=tar | command=lzip" ;; + "tar+lzop") dependencies+="command=tar | command=lzop" ;; + "tar+xz") + dependencies+=" + command=tar | + command=xz; pkg_manager=apt; package=xz-utils | + command=xz; pkg_manager=dnf | + command=xz; pkg_manager=pacman | + command=xz; pkg_manager=zypper" + ;; + "tar+zstd") dependencies+="command=tar | command=zstd" ;; + "unar") + dependencies+=" + command=unar; pkg_manager=apt | + command=unar; pkg_manager=dnf | + command=unar; pkg_manager=pacman; package=unarchiver | + command=unar; pkg_manager=zypper" + ;; + "unrar") dependencies+="command=unrar" ;; + "unsquashfs") + dependencies+=" + command=unsquashfs; pkg_manager=apt; package=squashfs-tools | + command=unsquashfs; pkg_manager=dnf; package=squashfs-tools | + command=unsquashfs; pkg_manager=pacman; package=squashfs-tools | + command=unsquashfs; pkg_manager=zypper; package=squashfs" + ;; + "unzip") dependencies+="command=unzip" ;; + "xorriso") dependencies+="command=xorriso" ;; + "xz") + dependencies+=" + command=xz; pkg_manager=apt; package=xz-utils | + command=xz; pkg_manager=dnf | + command=xz; pkg_manager=pacman | + command=xz; pkg_manager=zypper" + ;; + "zpaq") dependencies+="command=zpaq" ;; + "zstd") dependencies+="command=zstd" ;; + esac + dependencies+=$'\n' + done + + printf "%s" "$dependencies" +} + +_get_command() { + local input_file=$1 + local command_status=$2 + local preferred_commands="" + local command="" + + # Define the preferred commands for each archive format. + case "${input_file,,}" in + *.tar.bz | *.tbz | *.tar.bz2 | *.tbz2 | *.tb2) preferred_commands="tar+bzip2 unar 7za" ;; + *.tar.gz | *.tgz) preferred_commands="tar+gzip unar 7za" ;; + *.tar.lrz | *.tlrz) preferred_commands="tar+lrzip" ;; + *.tar.lz) preferred_commands="tar+lzip" ;; + *.tar.lz4) preferred_commands="tar+lz4" ;; + *.tar.lzma | *.tlz) preferred_commands="tar+lzma unar 7za" ;; + *.tar.lzo | *.tzo) preferred_commands="tar+lzop" ;; + *.tar.xz | *.txz) preferred_commands="tar+xz unar 7za" ;; + *.tar.z | *.taz) preferred_commands="tar+gzip unar 7za" ;; + *.tar.zst | *.tzst) preferred_commands="tar+zstd" ;; + *.7z) preferred_commands="7za unar bsdtar" ;; + *.ace) preferred_commands="unar" ;; + *.alz) preferred_commands="unar" ;; + *.ar) preferred_commands="ar bsdtar" ;; + *.arc) preferred_commands="unar" ;; + *.arj) preferred_commands="unar" ;; + *.bz | *.bz2) preferred_commands="bzip2 unar 7za" ;; + *.cab) preferred_commands="unar" ;; + *.cpio) preferred_commands="cpio unar bsdtar" ;; + *.deb | *.udeb) preferred_commands="ar" ;; + *.gpg | *.asc | *.pgp) preferred_commands="gpg" ;; + *.gz) preferred_commands="gzip unar 7za" ;; + *.iso) preferred_commands="xorriso bsdtar" ;; + *.lrz) preferred_commands="lrzip" ;; + *.lz) preferred_commands="lzip" ;; + *.lz4) preferred_commands="lz4" ;; + *.lzh | *.lzs | *.lha) preferred_commands="lha unar" ;; + *.lzma) preferred_commands="xz unar" ;; + *.lzo) preferred_commands="lzop" ;; + *.msi) preferred_commands="unar" ;; + *.pak) preferred_commands="unar" ;; + *.rar) preferred_commands="unrar unar bsdtar" ;; + *.sit) preferred_commands="unar" ;; + *.sqsh | *.squashfs | *.sfs) preferred_commands="unsquashfs" ;; + *.tar | *.gtar | *.gem) preferred_commands="tar bsdtar unar 7za" ;; + *.xar) preferred_commands="unar bsdtar" ;; + *.xz) preferred_commands="xz unar 7za" ;; + *.z) preferred_commands="gzip unar" ;; + *.zip) preferred_commands="7za bsdtar unar unzip" ;; + *.zoo) preferred_commands="unar" ;; + *.zpaq) preferred_commands="zpaq" ;; + *.zst) preferred_commands="zstd" ;; + *) preferred_commands="bsdtar+unar+7za" ;; + esac + + local preferred_commands_array=() + IFS=" " read -r -a preferred_commands_array <<<"$preferred_commands" + + if [[ "$command_status" == "default" ]]; then + # The default command is the first command of preferred commands. + command=${preferred_commands_array[0]} + elif [[ "$command_status" == "available" ]]; then + # Get the available command in the system. + local preferred_command="" + for preferred_command in "${preferred_commands_array[@]}"; do + if [[ "$preferred_command" == *"+"* ]]; then + if _all_commands_exists "${preferred_command//+/ }"; then + command=$preferred_command + break + fi + elif _command_exists "$preferred_command"; then + command=$preferred_command + break + fi + done + fi + + printf "%s" "$command" +} + +_run_command() { + local input_file=$1 + local command=$2 + local output_dir=$3 + local exit_code=0 + local filename="" + local std_output="" + + if [[ -z "$output_dir" ]]; then + output_dir=$(dirname -- "$input_file") + fi + + # Try to use the command '7z' instead of '7za'. + local command_7za="7za" + if [[ "$command" == *"7za"* ]]; then + _command_exists "7z" && command_7za="7z" + fi + + filename=$(basename -- "$input_file") # Remove the path. + filename=$(_strip_filename_extension "$filename") # Remove the extension. + + __temp_dir_cd() { + temp_dir_output=$(_get_temp_dir_local "$output_dir" "$filename") + pushd "$temp_dir_output" &>/dev/null || true + } + __temp_dir_exit() { + # Exit the temporary directory. + popd &>/dev/null || true + } + __temp_dir_remove() { + rm -rf -- "$temp_dir_output" &>/dev/null + } + __get_password() { + _display_password_box "Enter the password for the archive '$(basename -- "$input_file")'.\nPassword:" + } + + # Use a local temporary directory to work. + __temp_dir_cd + + case "$command" in + "7za") + std_output=$($command_7za x -aoa -p"null" -- "$input_file" 2>&1) + exit_code=$? + + if ((exit_code != 0)) && grep -i -q "wrong password" <<<"$std_output"; then + local password="" + __temp_dir_exit && __temp_dir_remove + password=$(__get_password) || exit 1 + __temp_dir_cd + std_output=$($command_7za x -aoa -p"$password" -- "$input_file" 2>&1) + exit_code=$? + fi + ;; + "ar") std_output=$(ar x -- "$input_file" 2>&1) ;; + "bsdtar") + std_output=$(bsdtar --passphrase "null" -xf "$input_file" 2>&1) + exit_code=$? + + if ((exit_code != 0)) && grep -i -q "incorrect passphrase" <<<"$std_output"; then + local password="" + __temp_dir_exit && __temp_dir_remove + password=$(__get_password) || exit 1 + __temp_dir_cd + std_output=$(bsdtar --passphrase "$password" -xf "$input_file" 2>&1) + exit_code=$? + fi + ;; + "bzip2") std_output=$(bzip2 -d -c -k -- "$input_file" >"$filename") ;; + "cpio") std_output=$(cpio -idv <"$input_file" 2>&1) ;; + "gpg") std_output=$(gpg --batch --yes --decrypt --output "$filename" -- "$input_file" 2>&1) ;; + "gzip") std_output=$(gzip -d -c -k -- "$input_file" >"$filename") ;; + "lha") std_output=$(lha -e "$input_file" 2>&1) ;; + "lrzip") std_output=$(lrzip -d -o "$temp_dir_output/$filename" -- "$input_file" 2>&1) ;; + "lz4") std_output=$(lz4 -d -c -- "$input_file" >"$filename") ;; + "lzip") std_output=$(lzip -d -c -k -- "$input_file" >"$filename") ;; + "lzop") std_output=$(lzop -d -- "$input_file" 2>&1) ;; + "tar+bzip2") std_output=$(tar --extract --bzip2 --file="$input_file" 2>&1) ;; + "tar+gzip") std_output=$(tar --extract --gzip --file="$input_file" 2>&1) ;; + "tar+lrzip") std_output=$(lrztar -d "$input_file" 2>&1) ;; + "tar+lzip") std_output=$(tar --extract --lzip --file="$input_file" 2>&1) ;; + "tar+lz4") std_output=$(lz4 -d -c -- "$input_file" | tar xf -) ;; + "tar+lzma") std_output=$(tar --extract --lzma --file="$input_file" 2>&1) ;; + "tar+lzop") std_output=$(tar --extract --lzop --file="$input_file" 2>&1) ;; + "tar+xz") std_output=$(tar --extract --xz --file="$input_file" 2>&1) ;; + "tar+z") std_output=$(tar --extract --file="$input_file" 2>&1) ;; + "tar+zstd") std_output=$(zstd -f -d -c -- "$input_file" | tar xf -) ;; + "tar") std_output=$(tar --extract --file="$input_file" 2>&1) ;; + "unar") + std_output=$(unar -- "$input_file" 2>&1) + exit_code=$? + + if ((exit_code != 0)) && grep -i -q "requires a password" <<<"$std_output"; then + local password="" + __temp_dir_exit && __temp_dir_remove + password=$(__get_password) || exit 1 + __temp_dir_cd + std_output=$(unar -force-overwrite -password "$password" -- "$input_file" 2>&1) + exit_code=$? + fi + ;; + "unrar") + std_output=$(unrar x -p"null" -- "$input_file" 2>&1) + exit_code=$? + + if ((exit_code != 0)) && grep -i -q "incorrect password for" <<<"$std_output"; then + local password="" + __temp_dir_exit && __temp_dir_remove + password=$(__get_password) || exit 1 + __temp_dir_cd + std_output=$(unrar x -p"$password" -- "$input_file" 2>&1) + exit_code=$? + fi + ;; + "unsquashfs") std_output=$(unsquashfs "$input_file" 2>&1) ;; + "unzip") + std_output=$(unzip -P "null" -- "$input_file" 2>&1) + exit_code=$? + + if ((exit_code != 0)) && grep -i -q "incorrect password" <<<"$std_output"; then + local password="" + __temp_dir_exit && __temp_dir_remove + password=$(__get_password) || exit 1 + __temp_dir_cd + std_output=$(unzip -P "$password" -- "$input_file" 2>&1) + exit_code=$? + fi + ;; + "xorriso") std_output=$(xorriso -osirrox on -indev "$input_file" -- -extract / . -rollback_end 2>&1) ;; + "xz") std_output=$(xz -d -c -k -- "$input_file" >"$filename") ;; + "zpaq") std_output=$(zpaq x "$input_file" 2>&1) ;; + "zstd") std_output=$(zstd -d -c -- "$input_file" >"$filename") ;; + "bsdtar+unar+7za") + exit_code=1 + + # Try to extract with 'bsdtar'. + if ((exit_code != 0)); then + std_output=$(bsdtar -xf "$input_file" 2>&1) + exit_code=$? + fi + + # Try to extract with 'unar'. + if ((exit_code != 0)); then + std_output=$(unar -- "$input_file" 2>&1) + exit_code=$? + fi + + # Try to extract with '7za'. + if ((exit_code != 0)); then + std_output=$($command_7za x -aoa -- "$input_file" 2>&1) + exit_code=$? + fi + + if ((exit_code != 0)); then + std_output="Could not recognize the archive format." + fi + ;; + esac + + # Check for result errors. + local exit_code_last=$? + if ((exit_code != 0)) || ((exit_code_last != 0)); then + _check_output "1" "$std_output" "$input_file" "" + + # If all extracted files have zero bytes, then abort. + local non_zero_files="" + non_zero_files=$(find . -type f ! -size 0 2>/dev/null) + if [[ -z "$non_zero_files" ]]; then + __temp_dir_exit && __temp_dir_remove + exit 1 + fi + fi + + # Fix permissions of extracted files in "iso" archive format. + if [[ "${input_file,,}" == *".iso" ]]; then + chmod --recursive u+rw -- . + fi + + # Check if the archive has just one item (single file/directory compressed). + local count_root_items="" + local single_root_item="" + count_root_items=$(find . -mindepth 1 -maxdepth 1 2>/dev/null | wc -l) + if ((count_root_items == 1)); then + single_root_item=$(find . -mindepth 1 -maxdepth 1 2>/dev/null) + single_root_item="${single_root_item#./}" + fi + + # Check if the 'temp_dir_output' is empty. + if ((count_root_items == 0)); then + __temp_dir_exit && __temp_dir_remove + exit 1 + fi + + __temp_dir_exit + + # Move the items to the correct directory. + if [[ "$single_root_item" == "$filename" ]] || [[ "$(_strip_filename_extension "$single_root_item")" == "$filename" ]]; then + # For archives with "one item with the same name of the archive". + # For example: "README.txt.tar.gz" or "README.tar.gz". + std_output=$(_move_file "rename" "$temp_dir_output/$single_root_item" "$output_dir/$single_root_item" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" + elif [[ "$single_root_item" == "squashfs-root" ]] && [[ "$command" == "unsquashfs" ]]; then + # For the "squashfs" archive format. + std_output=$(_move_file "rename" "$temp_dir_output/$single_root_item" "$output_dir/$filename" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" + else + # For archives with "one item with a different name of the archive" or "multiple items". + std_output=$(_move_file "rename" "$temp_dir_output" "$output_dir/$filename" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" + fi + + __temp_dir_remove +} + +_all_commands_exists() { + local commands=$1 + + local command="" + local commands_array=() + IFS=" " read -r -a commands_array <<<"$commands" + + for command in "${commands_array[@]}"; do + if ! _command_exists "$command"; then + return 1 + fi + done + return 0 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Audio MP3/Apply max gain (recursive) b/.local/share/nautilus/scripts/Audio MP3/Apply max gain (recursive) new file mode 100755 index 0000000..c67e55a --- /dev/null +++ b/.local/share/nautilus/scripts/Audio MP3/Apply max gain (recursive) @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=mp3gain" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_recursive=true; par_select_mime=audio/mpeg; par_skip_extension=bak") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + local temp_file="" + + # Work on a temporary file. + temp_file=$(_get_temp_file) + std_output=$(cp --archive -- "$input_file" "$temp_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 + + # Run the main process. + std_output=$(mp3gain -q -r -s s -m 100 -k "$temp_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 + + # Move the temporary file to the output. + output_file=$input_file + _move_temp_file_to_output "$input_file" "$temp_file" "$output_file" + + # Remove the temporary files on each iteration (if not removed before). + rm -f -- "$temp_file" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Audio MP3/Apply normal gain (recursive) b/.local/share/nautilus/scripts/Audio MP3/Apply normal gain (recursive) new file mode 100755 index 0000000..17b2fbd --- /dev/null +++ b/.local/share/nautilus/scripts/Audio MP3/Apply normal gain (recursive) @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=mp3gain" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_recursive=true; par_select_mime=audio/mpeg; par_skip_extension=bak") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + local temp_file="" + + # Work on a temporary file. + temp_file=$(_get_temp_file) + std_output=$(cp --archive -- "$input_file" "$temp_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 + + # Run the main process. + std_output=$(mp3gain -q -r -s s -c "$temp_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 + + # Move the temporary file to the output. + output_file=$input_file + _move_temp_file_to_output "$input_file" "$temp_file" "$output_file" + + # Remove the temporary files on each iteration (if not removed before). + rm -f -- "$temp_file" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Audio MP3/List ID3 tags b/.local/share/nautilus/scripts/Audio MP3/List ID3 tags new file mode 100755 index 0000000..747fb9b --- /dev/null +++ b/.local/share/nautilus/scripts/Audio MP3/List ID3 tags @@ -0,0 +1,56 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=mediainfo" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_recursive=true; par_select_mime=audio/mpeg; par_skip_extension=bak") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + + local std_output="" + std_output=$(_storage_text_read_all) + std_output=$(_text_sort "$std_output") + + _display_list_box "$std_output" "--column=Artist;--column=Title;--column=File" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + + # Run the main process. + std_output=$(mediainfo -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 + # shellcheck disable=SC2001 + std_output=$(tr -s " " <<<"$std_output") + # shellcheck disable=SC2001 + std_output=$(sed "s|: |$FIELD_SEPARATOR|" <<<"$std_output") + + local tag_artist="" + local tag_title="" + tag_artist=$(grep -m1 "^Performer $FIELD_SEPARATOR" <<<"$std_output" | cut -d "$FIELD_SEPARATOR" -f 2) + tag_title=$(grep -m1 "^Track name $FIELD_SEPARATOR" <<<"$std_output" | cut -d "$FIELD_SEPARATOR" -f 2) + + # Check if the values are not empty. + if [[ -z "$tag_artist" ]]; then + tag_artist="(empty)" + fi + if [[ -z "$tag_title" ]]; then + tag_title="(empty)" + fi + + _storage_text_write_ln "$tag_artist$FIELD_SEPARATOR$tag_title$FIELD_SEPARATOR$(_text_remove_pwd "$input_file")" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Audio MP3/List MP3 info b/.local/share/nautilus/scripts/Audio MP3/List MP3 info new file mode 100755 index 0000000..c442269 --- /dev/null +++ b/.local/share/nautilus/scripts/Audio MP3/List MP3 info @@ -0,0 +1,70 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=mediainfo" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_recursive=true; par_select_mime=audio/mpeg; par_skip_extension=bak") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + + local std_output="" + std_output=$(_storage_text_read_all) + std_output=$(_text_sort "$std_output") + + _display_list_box "$std_output" "--column=Mode;--column=Bit rate;--column=Sampling rate;--column=Channels;--column=File" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + + # Run the main process. + std_output=$(mediainfo -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 + # shellcheck disable=SC2001 + std_output=$(tr -s " " <<<"$std_output") + # shellcheck disable=SC2001 + std_output=$(sed "s|: |$FIELD_SEPARATOR|" <<<"$std_output") + + local mode="" + local bit_rate="" + local sampling_rate="" + local channels="" + mode=$(grep -m1 "^Overall bit rate mode $FIELD_SEPARATOR" <<<"$std_output" | cut -d "$FIELD_SEPARATOR" -f 2) + bit_rate=$(grep -m1 "^Overall bit rate $FIELD_SEPARATOR" <<<"$std_output" | cut -d "$FIELD_SEPARATOR" -f 2) + sampling_rate=$(grep -m1 "^Sampling rate $FIELD_SEPARATOR" <<<"$std_output" | cut -d "$FIELD_SEPARATOR" -f 2) + channels=$(grep -m1 "^Channel(s) $FIELD_SEPARATOR" <<<"$std_output" | cut -d "$FIELD_SEPARATOR" -f 2) + + # Check if the values are not empty. + if [[ -z "$mode" ]]; then + mode="(empty)" + elif [[ "${mode,,}" == "constant" ]]; then + mode="CBR" + elif [[ "${mode,,}" == "variable" ]]; then + mode="VBR" + fi + if [[ -z "$bit_rate" ]]; then + bit_rate="(empty)" + fi + if [[ -z "$sampling_rate" ]]; then + sampling_rate="(empty)" + fi + if [[ -z "$channels" ]]; then + channels="(empty)" + fi + + _storage_text_write_ln "$mode$FIELD_SEPARATOR$bit_rate$FIELD_SEPARATOR$sampling_rate$FIELD_SEPARATOR$channels$FIELD_SEPARATOR$(_text_remove_pwd "$input_file")" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Audio MP3/Repair (recursive) b/.local/share/nautilus/scripts/Audio MP3/Repair (recursive) new file mode 100755 index 0000000..e737b6c --- /dev/null +++ b/.local/share/nautilus/scripts/Audio MP3/Repair (recursive) @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=mp3val" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_recursive=true; par_select_mime=audio/mpeg; par_skip_extension=bak") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + local temp_file="" + + # Work on a temporary file. + temp_file=$(_get_temp_file) + std_output=$(cp --archive -- "$input_file" "$temp_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 + + # Run the main process. + std_output=$(mp3val -si -f "$temp_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 + + # Move the temporary file to the output. + output_file=$input_file + _move_temp_file_to_output "$input_file" "$temp_file" "$output_file" + + # Remove the temporary files on each iteration (if not removed before). + rm -f -- "$temp_file" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Audio MP3/Tag - ID3 to filename (artist - title) b/.local/share/nautilus/scripts/Audio MP3/Tag - ID3 to filename (artist - title) new file mode 100755 index 0000000..0820e8a --- /dev/null +++ b/.local/share/nautilus/scripts/Audio MP3/Tag - ID3 to filename (artist - title) @@ -0,0 +1,59 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=mediainfo" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_recursive=true; par_select_mime=audio/mpeg; par_skip_extension=bak") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + std_output=$(mediainfo -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 + # shellcheck disable=SC2001 + std_output=$(tr -s " " <<<"$std_output") + # shellcheck disable=SC2001 + std_output=$(sed "s|: |$FIELD_SEPARATOR|" <<<"$std_output") + + local tag_artist="" + local tag_title="" + tag_artist=$(grep -m1 "^Performer $FIELD_SEPARATOR" <<<"$std_output" | cut -d "$FIELD_SEPARATOR" -f 2) + tag_title=$(grep -m1 "^Track name $FIELD_SEPARATOR" <<<"$std_output" | cut -d "$FIELD_SEPARATOR" -f 2) + + # Check if the values are not empty. + if [[ -z "$tag_artist" ]]; then + _check_output "1" "Empty 'Artist' value." "$input_file" "" || return 1 + fi + if [[ -z "$tag_title" ]]; then + _check_output "1" "Empty 'Title' value." "$input_file" "" || return 1 + fi + + # Rename the file. + local dir_file="" + dir_file=$(_get_filename_dir "$input_file") + std_output=$(_move_file "rename" "$input_file" "$dir_file/$tag_artist - $tag_title.mp3" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" + + # Remove the temporary files on each iteration (if not removed before). + rm -f -- "$temp_file" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Audio MP3/Tag - filename to ID3 (artist - title) b/.local/share/nautilus/scripts/Audio MP3/Tag - filename to ID3 (artist - title) new file mode 100755 index 0000000..71ff769 --- /dev/null +++ b/.local/share/nautilus/scripts/Audio MP3/Tag - filename to ID3 (artist - title) @@ -0,0 +1,70 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=id3v2" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_recursive=true; par_select_mime=audio/mpeg; par_skip_extension=bak") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Work on a temporary file. + local temp_file="" + temp_file=$(_get_temp_file) + std_output=$(cp --archive -- "$input_file" "$temp_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 + + local basename="" + basename=$(basename -- "$input_file") + basename=$(_strip_filename_extension "$basename") + basename=$(tr -s " " <<<"$basename") + # shellcheck disable=SC2001 + basename=$(sed "s| - |$FIELD_SEPARATOR|" <<<"$basename") + + local audio_artist="" + local audio_title="" + audio_artist=$(cut -d "$FIELD_SEPARATOR" -f 1 <<<"$basename") + audio_title=$(cut -d "$FIELD_SEPARATOR" -f 2- <<<"$basename") + + # Check if the values are not empty. + if [[ -z "$audio_artist" ]]; then + _check_output "1" "Empty 'Artist' value." "$input_file" "" || return 1 + fi + if [[ -z "$audio_title" ]]; then + _check_output "1" "Empty 'Title' value." "$input_file" "" || return 1 + fi + + # Run the main process. + std_output=$(id3v2 --artist "$audio_artist" --song "$audio_title" "$temp_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 + + # Strip id3v1 tags. + std_output=$(id3v2 --delete-v1 "$temp_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 + + # Move the temporary file to the output. + output_file=$input_file + _move_temp_file_to_output "$input_file" "$temp_file" "$output_file" + + # Remove the temporary files on each iteration (if not removed before). + rm -f -- "$temp_file" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Audio/Concatenate files ('wav' output) b/.local/share/nautilus/scripts/Audio/Concatenate files ('wav' output) new file mode 100755 index 0000000..6643231 --- /dev/null +++ b/.local/share/nautilus/scripts/Audio/Concatenate files ('wav' output) @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=ffmpeg; pkg_manager=apt; package=ffmpeg | + command=ffmpeg; pkg_manager=dnf; package=ffmpeg-free | + command=ffmpeg; pkg_manager=pacman; package=ffmpeg | + command=ffmpeg; pkg_manager=zypper; package=ffmpeg" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime='audio/|video/'; par_min_items=2; par_sort_list=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + _main_task "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_files=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Create the input list for the 'ffmpeg'. + local temp_file="" + temp_file=$(_get_temp_file) + input_files="file '$input_files'" + # shellcheck disable=SC2001 + input_files=$(sed "s|$FIELD_SEPARATOR|'${FIELD_SEPARATOR}file '|g" <<<"$input_files") + _convert_filenames_to_text "$input_files" >"$temp_file" + + # Run the main process. + output_file=$(_get_output_filename "Concatenated audio.wav" "$output_dir" "par_extension_opt=preserve") + std_output=$(ffmpeg -hide_banner -y -f "concat" -safe 0 -i "$temp_file" -- "$output_file" 2>&1) + _check_output "$?" "$std_output" "" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Audio/Convert to 'flac' b/.local/share/nautilus/scripts/Audio/Convert to 'flac' new file mode 100755 index 0000000..2f97bbc --- /dev/null +++ b/.local/share/nautilus/scripts/Audio/Convert to 'flac' @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=ffmpeg; pkg_manager=apt; package=ffmpeg | + command=ffmpeg; pkg_manager=dnf; package=ffmpeg-free | + command=ffmpeg; pkg_manager=pacman; package=ffmpeg | + command=ffmpeg; pkg_manager=zypper; package=ffmpeg" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime='audio/|video/'; par_validate_conflict=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=flac") + std_output=$(ffmpeg -hide_banner -y -i "$input_file" -vn -ac 2 -- "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Audio/Convert to 'mp3' (192 kbps) b/.local/share/nautilus/scripts/Audio/Convert to 'mp3' (192 kbps) new file mode 100755 index 0000000..3be4fce --- /dev/null +++ b/.local/share/nautilus/scripts/Audio/Convert to 'mp3' (192 kbps) @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=ffmpeg; pkg_manager=apt; package=ffmpeg | + command=ffmpeg; pkg_manager=dnf; package=ffmpeg-free | + command=ffmpeg; pkg_manager=pacman; package=ffmpeg | + command=ffmpeg; pkg_manager=zypper; package=ffmpeg" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime='audio/|video/'; par_validate_conflict=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=mp3") + std_output=$(ffmpeg -hide_banner -y -i "$input_file" -vn -c:a libmp3lame -b:a 192k -ac 2 -- "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Audio/Convert to 'mp3' (320 kbps) b/.local/share/nautilus/scripts/Audio/Convert to 'mp3' (320 kbps) new file mode 100755 index 0000000..489627f --- /dev/null +++ b/.local/share/nautilus/scripts/Audio/Convert to 'mp3' (320 kbps) @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=ffmpeg; pkg_manager=apt; package=ffmpeg | + command=ffmpeg; pkg_manager=dnf; package=ffmpeg-free | + command=ffmpeg; pkg_manager=pacman; package=ffmpeg | + command=ffmpeg; pkg_manager=zypper; package=ffmpeg" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime='audio/|video/'; par_validate_conflict=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=mp3") + std_output=$(ffmpeg -hide_banner -y -i "$input_file" -vn -c:a libmp3lame -b:a 320k -ac 2 -- "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Audio/Convert to 'mp3' (48 kbps, mono) b/.local/share/nautilus/scripts/Audio/Convert to 'mp3' (48 kbps, mono) new file mode 100755 index 0000000..466221b --- /dev/null +++ b/.local/share/nautilus/scripts/Audio/Convert to 'mp3' (48 kbps, mono) @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=ffmpeg; pkg_manager=apt; package=ffmpeg | + command=ffmpeg; pkg_manager=dnf; package=ffmpeg-free | + command=ffmpeg; pkg_manager=pacman; package=ffmpeg | + command=ffmpeg; pkg_manager=zypper; package=ffmpeg" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime='audio/|video/'; par_validate_conflict=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=mp3") + std_output=$(ffmpeg -hide_banner -y -i "$input_file" -vn -c:a libmp3lame -b:a 48k -ac 1 -- "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Audio/Convert to 'ogg' b/.local/share/nautilus/scripts/Audio/Convert to 'ogg' new file mode 100755 index 0000000..e86cddd --- /dev/null +++ b/.local/share/nautilus/scripts/Audio/Convert to 'ogg' @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=ffmpeg; pkg_manager=apt; package=ffmpeg | + command=ffmpeg; pkg_manager=dnf; package=ffmpeg-free | + command=ffmpeg; pkg_manager=pacman; package=ffmpeg | + command=ffmpeg; pkg_manager=zypper; package=ffmpeg" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime='audio/|video/'; par_validate_conflict=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=ogg") + std_output=$(ffmpeg -hide_banner -y -i "$input_file" -vn -ac 2 -- "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Audio/Convert to 'wav' b/.local/share/nautilus/scripts/Audio/Convert to 'wav' new file mode 100755 index 0000000..97e3954 --- /dev/null +++ b/.local/share/nautilus/scripts/Audio/Convert to 'wav' @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=ffmpeg; pkg_manager=apt; package=ffmpeg | + command=ffmpeg; pkg_manager=dnf; package=ffmpeg-free | + command=ffmpeg; pkg_manager=pacman; package=ffmpeg | + command=ffmpeg; pkg_manager=zypper; package=ffmpeg" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime='audio/|video/'; par_validate_conflict=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=wav") + std_output=$(ffmpeg -hide_banner -y -i "$input_file" -vn -ac 2 -- "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Audio/Effect Fade in b/.local/share/nautilus/scripts/Audio/Effect Fade in new file mode 100755 index 0000000..729522b --- /dev/null +++ b/.local/share/nautilus/scripts/Audio/Effect Fade in @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=ffmpeg; pkg_manager=apt; package=ffmpeg | + command=ffmpeg; pkg_manager=dnf; package=ffmpeg-free | + command=ffmpeg; pkg_manager=pacman; package=ffmpeg | + command=ffmpeg; pkg_manager=zypper; package=ffmpeg" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime='audio/|video/'") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(ffmpeg -hide_banner -y -i "$input_file" -filter:a "afade=d=10" -- "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Audio/Effect Fade out b/.local/share/nautilus/scripts/Audio/Effect Fade out new file mode 100755 index 0000000..eab6da7 --- /dev/null +++ b/.local/share/nautilus/scripts/Audio/Effect Fade out @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=ffmpeg; pkg_manager=apt; package=ffmpeg | + command=ffmpeg; pkg_manager=dnf; package=ffmpeg-free | + command=ffmpeg; pkg_manager=pacman; package=ffmpeg | + command=ffmpeg; pkg_manager=zypper; package=ffmpeg" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime='audio/|video/'") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(ffmpeg -hide_banner -y -i "$input_file" -filter:a "areverse, afade=d=10, areverse" -- "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Audio/Effect Noise gate (-30 dB) b/.local/share/nautilus/scripts/Audio/Effect Noise gate (-30 dB) new file mode 100755 index 0000000..2549a4f --- /dev/null +++ b/.local/share/nautilus/scripts/Audio/Effect Noise gate (-30 dB) @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=ffmpeg; pkg_manager=apt; package=ffmpeg | + command=ffmpeg; pkg_manager=dnf; package=ffmpeg-free | + command=ffmpeg; pkg_manager=pacman; package=ffmpeg | + command=ffmpeg; pkg_manager=zypper; package=ffmpeg" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime='audio/|video/'") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(ffmpeg -hide_banner -y -i "$input_file" -filter:a "compand=attacks=0:points=-80/-115|-30.1/-80|-30/-30|20/20" -- "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Audio/Effect Normalize b/.local/share/nautilus/scripts/Audio/Effect Normalize new file mode 100755 index 0000000..1b2ed4c --- /dev/null +++ b/.local/share/nautilus/scripts/Audio/Effect Normalize @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=ffmpeg; pkg_manager=apt; package=ffmpeg | + command=ffmpeg; pkg_manager=dnf; package=ffmpeg-free | + command=ffmpeg; pkg_manager=pacman; package=ffmpeg | + command=ffmpeg; pkg_manager=zypper; package=ffmpeg" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime='audio/|video/'") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(ffmpeg -hide_banner -y -i "$input_file" -filter:a "loudnorm" -- "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Audio/Effect Truncate silence (-30 dB) b/.local/share/nautilus/scripts/Audio/Effect Truncate silence (-30 dB) new file mode 100755 index 0000000..6ded665 --- /dev/null +++ b/.local/share/nautilus/scripts/Audio/Effect Truncate silence (-30 dB) @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=ffmpeg; pkg_manager=apt; package=ffmpeg | + command=ffmpeg; pkg_manager=dnf; package=ffmpeg-free | + command=ffmpeg; pkg_manager=pacman; package=ffmpeg | + command=ffmpeg; pkg_manager=zypper; package=ffmpeg" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime='audio/|video/'") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(ffmpeg -hide_banner -y -i "$input_file" -filter:a "silenceremove=stop_periods=-1:stop_duration=1:stop_threshold=-30dB" -- "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Audio/List audio quality b/.local/share/nautilus/scripts/Audio/List audio quality new file mode 100755 index 0000000..6bfc4ad --- /dev/null +++ b/.local/share/nautilus/scripts/Audio/List audio quality @@ -0,0 +1,67 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=sox | + pkg_manager=apt; package=libsox-fmt-mp3" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_recursive=true; par_select_mime='audio/|video/'") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + + local std_output="" + std_output=$(_storage_text_read_all) + std_output=$(_text_sort "$std_output") + + _display_list_box "$std_output" "--column=Status;--column=File" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + + # Run the main process. + std_output=$(sox "$input_file" -n remix 1 sinc "19k-20k" -m stat 2>&1) + _check_output "$?" "$std_output" "$input_file" "" + + std_output=$(grep "^Mean.*norm" <<<"$std_output") + std_output=$(cut -d ":" -f 2 <<<"$std_output") + std_output=$(tr -d " " <<<"$std_output") + + local status="[excellent quality]" + if [[ -z "$std_output" ]]; then + status="[poor quality]" + elif [[ "$std_output" == "0.00000"* ]]; then + status="[medium quality]" + fi + + if [[ "$status" == "[medium quality]" ]]; then + std_output=$(sox "$input_file" -n remix 1 sinc "17k-18k" -m stat 2>&1) + _check_output "$?" "$std_output" "$input_file" "" + + std_output=$(grep "^Mean.*norm" <<<"$std_output") + std_output=$(cut -d ":" -f 2 <<<"$std_output") + std_output=$(tr -d " " <<<"$std_output") + + if [[ -z "$std_output" ]]; then + status="[poor quality]" + elif [[ "$std_output" == "0.00000"* ]]; then + status="[poor quality]" + fi + fi + + _storage_text_write_ln "$status$FIELD_SEPARATOR$(_text_remove_pwd "$input_file")" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Audio/Mix channels to mono b/.local/share/nautilus/scripts/Audio/Mix channels to mono new file mode 100755 index 0000000..0690b71 --- /dev/null +++ b/.local/share/nautilus/scripts/Audio/Mix channels to mono @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=ffmpeg; pkg_manager=apt; package=ffmpeg | + command=ffmpeg; pkg_manager=dnf; package=ffmpeg-free | + command=ffmpeg; pkg_manager=pacman; package=ffmpeg | + command=ffmpeg; pkg_manager=zypper; package=ffmpeg" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime='audio/|video/'") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(ffmpeg -hide_banner -y -i "$input_file" -ac 1 -- "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Audio/Mix two files ('wav' output) b/.local/share/nautilus/scripts/Audio/Mix two files ('wav' output) new file mode 100755 index 0000000..877641b --- /dev/null +++ b/.local/share/nautilus/scripts/Audio/Mix two files ('wav' output) @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=ffmpeg; pkg_manager=apt; package=ffmpeg | + command=ffmpeg; pkg_manager=dnf; package=ffmpeg-free | + command=ffmpeg; pkg_manager=pacman; package=ffmpeg | + command=ffmpeg; pkg_manager=zypper; package=ffmpeg" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime='audio/|video/'; par_min_items=2; par_max_items=2; par_sort_list=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + _main_task "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_files=$1 + local output_dir=$2 + local output_file="" + local std_output="" + local file_1="" + local file_2="" + + file_1=$(cut -d "$FIELD_SEPARATOR" -f 1 <<<"$input_files") + file_2=$(cut -d "$FIELD_SEPARATOR" -f 2 <<<"$input_files") + + # Run the main process. + output_file=$(_get_output_filename "Mixed audio.wav" "$output_dir" "par_extension_opt=preserve") + std_output=$(ffmpeg -hide_banner -y -i "$file_1" -i "$file_2" -filter_complex "amix=inputs=2:duration=longest" -- "$output_file" 2>&1) + _check_output "$?" "$std_output" "" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Audio/Produce a spectrogram b/.local/share/nautilus/scripts/Audio/Produce a spectrogram new file mode 100755 index 0000000..65abea6 --- /dev/null +++ b/.local/share/nautilus/scripts/Audio/Produce a spectrogram @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=sox | + pkg_manager=apt; package=libsox-fmt-mp3" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime='audio/|video/'") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=png") + std_output=$(sox "$input_file" -n "spectrogram" -c "" -o "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Audio/Strip metadata (recursive) b/.local/share/nautilus/scripts/Audio/Strip metadata (recursive) new file mode 100755 index 0000000..d7c2db4 --- /dev/null +++ b/.local/share/nautilus/scripts/Audio/Strip metadata (recursive) @@ -0,0 +1,48 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=ffmpeg; pkg_manager=apt; package=ffmpeg | + command=ffmpeg; pkg_manager=dnf; package=ffmpeg-free | + command=ffmpeg; pkg_manager=pacman; package=ffmpeg | + command=ffmpeg; pkg_manager=zypper; package=ffmpeg" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_recursive=true; par_select_mime='audio/|video/'; par_skip_extension=bak") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + local temp_file="" + + # Work on a temporary file. + temp_file=$(_get_temp_file)$(_get_filename_extension "$input_file") + + # Run the main process. + std_output=$(ffmpeg -hide_banner -y -i "$input_file" -map_metadata -1 -vn -c:a copy -- "$temp_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 + + # Move the temporary file to the output. + output_file=$input_file + _move_temp_file_to_output "$input_file" "$temp_file" "$output_file" + + # Remove the temporary files on each iteration (if not removed before). + rm -f -- "$temp_file" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Directories and files/Compare items b/.local/share/nautilus/scripts/Directories and files/Compare items new file mode 100755 index 0000000..9fe4908 --- /dev/null +++ b/.local/share/nautilus/scripts/Directories and files/Compare items @@ -0,0 +1,240 @@ +#!/usr/bin/env bash +# install_keyboard_shortcut=C + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + + # Execute initial checks. + _check_dependencies "" + input_files=$(_get_files "par_type=all; par_min_items=2; par_max_items=3; par_sort_list=true") + + # Run the main process. + _compare "$input_files" +} + +_compare() { + local input_files=$1 + + local file_1="" + local file_2="" + local file_3="" + file_1=$(cut -d "$FIELD_SEPARATOR" -f 1 <<<"$input_files") + file_2=$(cut -d "$FIELD_SEPARATOR" -f 2 <<<"$input_files") + file_3=$(cut -d "$FIELD_SEPARATOR" -f 3 <<<"$input_files") + + # Check if the items (directories or files) are identical. + local diff_1_2="" + local diff_1_3="" + diff_1_2=$(diff --brief --recursive -- "$file_1" "$file_2" 2>&1) + if [[ -z "$file_3" ]]; then + if [[ -z "$diff_1_2" ]]; then + _display_info_box "The two selected items are identical." + _exit_script + fi + else + diff_1_3=$(diff --brief --recursive -- "$file_1" "$file_3" 2>&1) + if [[ -z "$diff_1_2" ]] && [[ -z "$diff_1_3" ]]; then + _display_info_box "The three selected items are identical." + _exit_script + fi + fi + + # Define the command to execute according to file MIME type. + local command="" + local file_1_mime="" + file_1_mime=$(_get_file_mime "$file_1") + case $file_1_mime in + "application/pdf") command="diffpdf" ;; + "inode/directory") command="meld" ;; + "inode/x-empty") command="meld" ;; + "image/"*) command="compare" ;; + "text/"*) command="meld" ;; + *) + local file_1_encoding="" + file_1_encoding=$(_get_file_encoding "$file_1") + if [[ "$file_1_encoding" == "binary" ]]; then + command="meld_hexadecimal" + else + command="meld" + fi + ;; + esac + + if [[ "$command" == "meld"* ]]; then + case "${XDG_CURRENT_DESKTOP,,}" in + *"kde"* | *"lxqt"*) + command=${command//meld/kdiff3} + ;; + esac + fi + + # Check dependencies for the command. + local dependencies="" + case $command in + "compare") dependencies=" + command=compare; pkg_manager=apt; package=imagemagick | + command=compare; pkg_manager=dnf; package=ImageMagick | + command=compare; pkg_manager=pacman; package=imagemagick | + command=compare; pkg_manager=zypper; package=ImageMagick | + command=xdg-open; package=xdg-utils" ;; + "diffpdf") dependencies="command=diffpdf" ;; + "kdiff3") dependencies="command=kdiff3" ;; + "kdiff3_hexadecimal") dependencies="command=kdiff3 | command=xxd" ;; + "meld") dependencies="command=meld" ;; + "meld_hexadecimal") dependencies="command=meld | command=xxd" ;; + esac + _check_dependencies "$dependencies" + + # Run the main process. + case $command in + "compare") + if [[ -n "$file_3" ]]; then + _display_error_box "You must select only two image files to compare!" + _exit_script + fi + + # Check if both images have the same pixel values. + local pixel_error="" + pixel_error=$(compare -metric AE -- "$file_1" "$file_2" null: 2>&1) + if [[ "$pixel_error" == "0" ]]; then + _display_info_box "The two selected images are identical (same pixel values)." + _exit_script + fi + + # Get image dimensions. + local dimensions_1="" + local dimensions_2="" + dimensions_1=$(identify -format "%wx%h" "$file_1") + dimensions_2=$(identify -format "%wx%h" "$file_2") + + # Compare two images using a visual diff with the 'convert' command. + local temp_file="" + temp_file="$(_get_temp_file_dry).png" + if [[ "$dimensions_1" == "$dimensions_2" ]]; then + # Compare images with the same dimensions. + convert \ + '(' "$file_1" -flatten -grayscale Rec709Luminance ')' \ + '(' "$file_2" -flatten -grayscale Rec709Luminance ')' \ + '(' -clone 0-1 -compose darken -composite ')' \ + -channel RGB -combine "$temp_file" + else + # Compare images with different dimensions. + compare "$file_1" "$file_2" -compose src "$temp_file" + fi + + # Get the installed image viewer. + local image_viewer="" + image_viewer=$(_xdg_get_default_app "image/jpeg") + if [[ "$image_viewer" == *"eog" ]]; then + $image_viewer --new-instance -- "$temp_file" + else + $image_viewer -- "$temp_file" + fi + + ;; + "diffpdf") + if [[ -n "$file_3" ]]; then + _display_error_box "You must select only two PDFs to compare!" + _exit_script + fi + + diffpdf -- "$file_1" "$file_2" & + ;; + "meld" | "kdiff3") + if [[ -z "$file_3" ]]; then + $command -- "$file_1" "$file_2" & + else + $command -- "$file_1" "$file_2" "$file_3" & + fi + ;; + "meld_hexadecimal" | "kdiff3_hexadecimal") + if [[ -n "$file_3" ]]; then + _display_error_box "You must select only two files to hexadecimal compare!" + _exit_script + fi + + # Remove the prefix '_hexadecimal'. + command=${command//_hexadecimal/} + + # Get the file sizes. + local file_1_size="" + local file_2_size="" + local size_difference=0 + file_1_size=$(_get_file_size "$file_1") + file_2_size=$(_get_file_size "$file_2") + size_difference=$(_get_difference "$file_1_size" "$file_2_size") + + # If the files have different sizes, + # compute a column width for better comparison. + local cols=24 + if ((size_difference != 0)); then + cols=$(_get_ideal_cols "$size_difference") + fi + + # Convert files to hexadecimal text view. + local file_1_hex="" + local file_2_hex="" + file_1_hex="$TEMP_DIR_TASK/$(basename -- "$file_1")" + file_2_hex="$TEMP_DIR_TASK/$(basename -- "$file_2")" + xxd -c "$cols" "$file_1" "$file_1_hex" + xxd -c "$cols" "$file_2" "$file_2_hex" + + # Remove the addresses for better comparison. + sed -i "s|^[^:]*: ||g" "$file_1_hex" + sed -i "s|^[^:]*: ||g" "$file_2_hex" + + # Compare and edit the files. + $command -- "$file_1_hex" "$file_2_hex" + + # Convert to plain hexadecimal dump. + sed -i "s| .*||g; s| ||g" "$file_1_hex" + sed -i "s| .*||g; s| ||g" "$file_2_hex" + + # Save the files after possible modifications. + local file_1_modified="$file_1_hex.bin" + local file_2_modified="$file_2_hex.bin" + xxd -revert -plain "$file_1_hex" "$file_1_modified" + xxd -revert -plain "$file_2_hex" "$file_2_modified" + _move_temp_file_to_output "$file_1" "$file_1_modified" "$file_1" + _move_temp_file_to_output "$file_2" "$file_2_modified" "$file_2" + ;; + esac +} + +_get_ideal_cols() { + local size_difference=$1 + local cols=24 + + local i=0 + for ((i = 23; i >= 5; i--)); do + if ((size_difference % i == 0)); then + cols=$i + break + fi + done + + printf "%s" "$cols" +} + +_get_difference() { + local num_1=$1 + local num_2=$2 + + # Calculate the positive difference. + if ((num_1 > num_2)); then + printf "%s" "$((num_1 - num_2))" + else + printf "%s" "$((num_2 - num_1))" + fi +} + +_get_file_size() { + stat --format="%s" "$1" 2>/dev/null +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Directories and files/Compare with diff b/.local/share/nautilus/scripts/Directories and files/Compare with diff new file mode 100755 index 0000000..9a32d7d --- /dev/null +++ b/.local/share/nautilus/scripts/Directories and files/Compare with diff @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local std_output="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=all; par_min_items=2; par_max_items=2; par_sort_list=true") + + # Run the main process. + local file_1="" + local file_2="" + + file_1=$(cut -d "$FIELD_SEPARATOR" -f 1 <<<"$input_files") + file_2=$(cut -d "$FIELD_SEPARATOR" -f 2 <<<"$input_files") + + [[ -d "$file_1" ]] && file_1+="/" + [[ -d "$file_2" ]] && file_2+="/" + + std_output=$(diff --no-dereference --brief --recursive -- "$file_1" "$file_2" 2>&1) + std_output=$(_text_remove_pwd "$std_output") + std_output=$(_text_sort "$std_output") + + if [[ -z "$std_output" ]]; then + std_output="(No differences)" + fi + + _display_text_box "$std_output" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Directories and files/Create link (hard link) b/.local/share/nautilus/scripts/Directories and files/Create link (hard link) new file mode 100755 index 0000000..0df77e5 --- /dev/null +++ b/.local/share/nautilus/scripts/Directories and files/Create link (hard link) @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=file") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve; par_prefix='Hard link to'") + std_output=$(ln -- "$input_file" "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Directories and files/Create link (symbolic link) b/.local/share/nautilus/scripts/Directories and files/Create link (symbolic link) new file mode 100755 index 0000000..a87d924 --- /dev/null +++ b/.local/share/nautilus/scripts/Directories and files/Create link (symbolic link) @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=all") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve; par_prefix='Link to'") + std_output=$(ln -s -- "$input_file" "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Directories and files/List duplicate files b/.local/share/nautilus/scripts/Directories and files/List duplicate files new file mode 100755 index 0000000..c449495 --- /dev/null +++ b/.local/share/nautilus/scripts/Directories and files/List duplicate files @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +# shellcheck disable=SC2001 +# install_keyboard_shortcut=U + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local std_output="" + local temp_file="" + + # Execute initial checks. + _check_dependencies "command=rdfind" + _display_wait_box "2" + input_files=$(_get_files "par_type=all; par_get_pwd=true") + + # Work on a temporary file. + temp_file=$(_get_temp_file) + + # NOTE: The 'rdfind' does not support ' -- ' in the command line. + + # Run the main process. + # shellcheck disable=SC2086 + rdfind -dryrun true -removeidentinode false -outputname "$temp_file" $input_files &>/dev/null + std_output=$(grep "DUPTYPE" <"$temp_file") + std_output=$(sed "s|DUPTYPE_FIRST_OCCURRENCE|\nDUPTYPE_FIRST_OCCURRENCE|" <<<"$std_output") + std_output=$(cut -d ' ' -f 8- <<<"$std_output") + std_output=$(grep -v "/\.git/" <<<"$std_output") + std_output=$(sed -z "s|^\n*\([^\n]\)|\1|g; s|\n\{3,\}|\n\n|g" <<<"$std_output") + std_output=$(_text_remove_pwd "$std_output") + std_output=$(sed "s|//|/|" <<<"$std_output") + std_output=$(sed "s|^\(..*\)$|'\1'|" <<<"$std_output") + + # Print a string in each group of duplicate files. + if [[ -n "$std_output" ]]; then + local msg_duplicate="Duplicate files:" + std_output="$msg_duplicate"$'\n'"$std_output" + std_output=$(sed -z "s|\n\n|\n\n$msg_duplicate\n|g" <<<"$std_output") + fi + + rm -f -- "$temp_file" + + _display_text_box "$std_output" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Directories and files/List empty directories b/.local/share/nautilus/scripts/Directories and files/List empty directories new file mode 100755 index 0000000..0e28749 --- /dev/null +++ b/.local/share/nautilus/scripts/Directories and files/List empty directories @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +# install_keyboard_shortcut=E + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local std_output="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=directory; par_get_pwd=true") + + # Run the main process. + # shellcheck disable=SC2086 + std_output=$(find $input_files -type d -empty ! -path "$IGNORE_FIND_PATH" -printf "%p\n" 2>/dev/null) + std_output=$(_text_remove_pwd "$std_output") + + _display_list_box "$std_output" "--column=Directory" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Directories and files/List file information b/.local/share/nautilus/scripts/Directories and files/List file information new file mode 100755 index 0000000..c150675 --- /dev/null +++ b/.local/share/nautilus/scripts/Directories and files/List file information @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +# install_keyboard_shortcut=Y + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_recursive=true; par_get_pwd=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + + local std_output="" + std_output=$(_storage_text_read_all) + std_output=$(_text_sort "$std_output") + + _display_text_box "$std_output" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + + # Run the main process. + std_output=$(file --separator "$FIELD_SEPARATOR" --no-pad -- "$input_file") + std_output=$(_text_remove_pwd "$std_output") + # shellcheck disable=SC2001 + std_output=$(sed "s|\(.*\)$FIELD_SEPARATOR *\(.*\)|\2: '\1'|" <<<"$std_output") + + _storage_text_write_ln "$std_output" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Directories and files/List file mime b/.local/share/nautilus/scripts/Directories and files/List file mime new file mode 100755 index 0000000..bd7c880 --- /dev/null +++ b/.local/share/nautilus/scripts/Directories and files/List file mime @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +# install_keyboard_shortcut=1 + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_recursive=true; par_get_pwd=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + + local std_output="" + std_output=$(_storage_text_read_all) + std_output=$(_text_sort "$std_output") + + _display_list_box "$std_output" "--column=Mime;--column=File" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + local file_mime="" + + file_mime=$(file --brief --mime-type -- "$input_file" 2>/dev/null) + + if [[ -z "$file_mime" ]]; then + return + fi + + if [[ "$file_mime" == "cannot"* ]]; then + return + fi + + # Run the main process. + std_output="$file_mime$FIELD_SEPARATOR$input_file" + std_output=$(_text_remove_pwd "$std_output") + + _storage_text_write_ln "$std_output" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Directories and files/List hard links b/.local/share/nautilus/scripts/Directories and files/List hard links new file mode 100755 index 0000000..34d727f --- /dev/null +++ b/.local/share/nautilus/scripts/Directories and files/List hard links @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local std_output="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=all; par_get_pwd=true") + + # Run the main process. + std_output=$(find "$input_files" -type f -links +1 -printf "%i %p\n") + std_output=$(_text_sort "$std_output") + std_output=$(awk 'NR==1 {prev=$1} $1!=prev {print "\nHard links:"; prev=$1} {print $0}' <<<"$std_output") + + if [[ -n "$std_output" ]]; then + std_output="Hard links:"$'\n'"$std_output" + fi + + _display_text_box "$std_output" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Directories and files/List hidden items b/.local/share/nautilus/scripts/Directories and files/List hidden items new file mode 100755 index 0000000..8756aad --- /dev/null +++ b/.local/share/nautilus/scripts/Directories and files/List hidden items @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +# install_keyboard_shortcut=H + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local std_output="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=all; par_get_pwd=true") + + # Run the main process. + # shellcheck disable=SC2086 + std_output=$(find $input_files ! -path "$IGNORE_FIND_PATH" -regextype posix-extended -regex ".*/\.[^/]*" -printf "%p\n" 2>/dev/null) + std_output=$(_text_remove_pwd "$std_output") + + _display_list_box "$std_output" "--column=Item" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Directories and files/List item properties b/.local/share/nautilus/scripts/Directories and files/List item properties new file mode 100755 index 0000000..5d640bf --- /dev/null +++ b/.local/share/nautilus/scripts/Directories and files/List item properties @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=all; par_recursive=true; par_get_pwd=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + + local std_output="" + std_output=$(_storage_text_read_all) + std_output=$(_text_sort "$std_output") + + _display_list_box "$std_output" "--column=Size;--column=Modified;--column=Created;--column=Type;--column=File" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + + # Run the main process. + std_output=$(stat --format="%s$FIELD_SEPARATOR%y$FIELD_SEPARATOR%w$FIELD_SEPARATOR%F" -- "$input_file" 2>/dev/null) + # shellcheck disable=SC2001 + std_output=$(sed "s|\([0-9]\{4\}-[0-1][0-9]-[0-3][0-9]\)[^$FIELD_SEPARATOR]*|\1|g" <<<"$std_output") + + _storage_text_write_ln "$std_output$FIELD_SEPARATOR$(_text_remove_pwd "$input_file")" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Directories and files/List largest directories b/.local/share/nautilus/scripts/Directories and files/List largest directories new file mode 100755 index 0000000..f5369a0 --- /dev/null +++ b/.local/share/nautilus/scripts/Directories and files/List largest directories @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +# install_keyboard_shortcut=9 + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=directory; par_get_pwd=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + + local std_output="" + std_output=$(_storage_text_read_all) + std_output=$(sort -h -r <<<"$std_output") # Sort the result. + std_output=$(head -n 15 <<<"$std_output") + + _display_list_box "$std_output" "--column=Size;--column=File" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + + # Run the main process. + std_output=$(du -h -- "$input_file" 2>/dev/null) + std_output=$(_text_remove_pwd "$std_output") + std_output=$(grep -v "\.$" <<<"$std_output") + # shellcheck disable=SC2001 + std_output=$(sed "s|\([^ ]*\)\t\(.*\)|\1$FIELD_SEPARATOR\2|g" <<<"$std_output") + + _storage_text_write_ln "$std_output" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Directories and files/List largest files b/.local/share/nautilus/scripts/Directories and files/List largest files new file mode 100755 index 0000000..ee5162e --- /dev/null +++ b/.local/share/nautilus/scripts/Directories and files/List largest files @@ -0,0 +1,43 @@ +#!/usr/bin/env bash +# install_keyboard_shortcut=0 + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_recursive=true; par_get_pwd=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + + local std_output="" + std_output=$(_storage_text_read_all) + std_output=$(sort -h -r <<<"$std_output") # Sort the result. + std_output=$(head -n 15 <<<"$std_output") + + _display_list_box "$std_output" "--column=Size;--column=File" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + + # Run the main process. + std_output=$(du -h -- "$input_file" 2>/dev/null) + std_output=$(_text_remove_pwd "$std_output") + # shellcheck disable=SC2001 + std_output=$(sed "s|\([^ ]*\)\t\(.*\)|\1$FIELD_SEPARATOR\2|g" <<<"$std_output") + + _storage_text_write_ln "$std_output" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Directories and files/Open item location b/.local/share/nautilus/scripts/Directories and files/Open item location new file mode 100755 index 0000000..7a530d2 --- /dev/null +++ b/.local/share/nautilus/scripts/Directories and files/Open item location @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# install_keyboard_shortcut=O + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + + # Execute initial checks. + _check_dependencies "command=xdg-open; package=xdg-utils" + input_files=$(_get_files "par_type=all; par_max_items=20; par_get_pwd=true") + + # Run the main process. + _open_items_locations "$input_files" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF combine, split/Combine multiple PDFs b/.local/share/nautilus/scripts/Document PDF/PDF combine, split/Combine multiple PDFs new file mode 100755 index 0000000..b9b6f0f --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF combine, split/Combine multiple PDFs @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=pdfunite; pkg_manager=apt; package=poppler-utils | + command=pdfunite; pkg_manager=dnf; package=poppler-utils | + command=pdfunite; pkg_manager=pacman; package=poppler | + command=pdfunite; pkg_manager=zypper; package=poppler-tools" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=application/pdf; par_min_items=2; par_sort_list=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + _main_task "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_files=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "Combined documents.pdf" "$output_dir" "par_extension_opt=preserve") + # shellcheck disable=SC2086 + std_output=$(pdfunite -- $input_files "$output_file" 2>&1) + _check_output "$?" "$std_output" "" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF combine, split/Split into single-page PDFs b/.local/share/nautilus/scripts/Document PDF/PDF combine, split/Split into single-page PDFs new file mode 100755 index 0000000..97f0ab8 --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF combine, split/Split into single-page PDFs @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=pdfseparate; pkg_manager=apt; package=poppler-utils | + command=pdfseparate; pkg_manager=dnf; package=poppler-utils | + command=pdfseparate; pkg_manager=pacman; package=poppler | + command=pdfseparate; pkg_manager=zypper; package=poppler-tools" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=application/pdf") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=%04d.pdf") + std_output=$(pdfseparate "$input_file" -- "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF encrypt, decrypt/Decrypt (remove a password) b/.local/share/nautilus/scripts/Document PDF/PDF encrypt, decrypt/Decrypt (remove a password) new file mode 100755 index 0000000..d6d6ce0 --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF encrypt, decrypt/Decrypt (remove a password) @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=qpdf" + _display_wait_box "0" + input_files=$(_get_files "par_type=file; par_select_mime=application/pdf") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + TEMP_DATA_TASK=$(_display_password_box_define) || _exit_script + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + # NOTE: Older 'qpdf' versions do not support ' -- ' in the command line. + std_output=$(qpdf --decrypt --password="$TEMP_DATA_TASK" "$input_file" "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF encrypt, decrypt/Decrypt (remove a security) b/.local/share/nautilus/scripts/Document PDF/PDF encrypt, decrypt/Decrypt (remove a security) new file mode 100755 index 0000000..cb1e69a --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF encrypt, decrypt/Decrypt (remove a security) @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=qpdf" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=application/pdf") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + # NOTE: Older 'qpdf' versions do not support ' -- ' in the command line. + std_output=$(qpdf --decrypt "$input_file" "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF encrypt, decrypt/Encrypt (set a password) b/.local/share/nautilus/scripts/Document PDF/PDF encrypt, decrypt/Encrypt (set a password) new file mode 100755 index 0000000..5f7223d --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF encrypt, decrypt/Encrypt (set a password) @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=qpdf" + _display_wait_box "0" + input_files=$(_get_files "par_type=file; par_select_mime=application/pdf") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + TEMP_DATA_TASK=$(_display_password_box_define) || _exit_script + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(qpdf --encrypt "$TEMP_DATA_TASK" "$TEMP_DATA_TASK" 256 -- "$input_file" "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF encrypt, decrypt/List encrypted PDFs b/.local/share/nautilus/scripts/Document PDF/PDF encrypt, decrypt/List encrypted PDFs new file mode 100755 index 0000000..557b36e --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF encrypt, decrypt/List encrypted PDFs @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + + # Execute initial checks. + _check_dependencies " + command=pdfinfo; pkg_manager=apt; package=poppler-utils | + command=pdfinfo; pkg_manager=dnf; package=poppler-utils | + command=pdfinfo; pkg_manager=pacman; package=poppler | + command=pdfinfo; pkg_manager=zypper; package=poppler-tools" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_recursive=true; par_get_pwd=true; par_select_mime=application/pdf") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "" + + local std_output="" + std_output=$(_storage_text_read_all) + std_output=$(_text_sort "$std_output") + + _display_list_box "$std_output" "--column=Protection;--column=File" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + + # Run the main process. + std_output=$(pdfinfo -- "$input_file" 2>&1) + + # Save the result only for 'encrypted' PDFs. + if [[ "$std_output" == *"yes ("* ]]; then + std_output=$(grep --only-matching "(print.*)" <<<"$std_output") + # shellcheck disable=SC2001 + std_output=$(sed "s|^(\(.*\))$|\1|g" <<<"$std_output") + _storage_text_write_ln "$std_output$FIELD_SEPARATOR$(_text_remove_pwd "$input_file")" + elif [[ "$std_output" == *"Incorrect password"* ]]; then + _storage_text_write_ln "password protection$FIELD_SEPARATOR$(_text_remove_pwd "$input_file")" + fi +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF multiple-page layout/Landscape 2 pages in 1 (1x2) b/.local/share/nautilus/scripts/Document PDF/PDF multiple-page layout/Landscape 2 pages in 1 (1x2) new file mode 100755 index 0000000..b4bb425 --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF multiple-page layout/Landscape 2 pages in 1 (1x2) @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=pdfjam; pkg_manager=apt; package=texlive-extra-utils | + command=pdfjam; pkg_manager=dnf; package=texlive-pdfjam | + command=pdfjam; pkg_manager=pacman; package=texlive-binextra | + command=pdfjam; pkg_manager=zypper; package=texlive-pdfjam-bin" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=application/pdf") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(pdfjam --nup "1x2" --landscape --outfile "$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF multiple-page layout/Landscape 2 pages in 1 (2x1) b/.local/share/nautilus/scripts/Document PDF/PDF multiple-page layout/Landscape 2 pages in 1 (2x1) new file mode 100755 index 0000000..bad7778 --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF multiple-page layout/Landscape 2 pages in 1 (2x1) @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=pdfjam; pkg_manager=apt; package=texlive-extra-utils | + command=pdfjam; pkg_manager=dnf; package=texlive-pdfjam | + command=pdfjam; pkg_manager=pacman; package=texlive-binextra | + command=pdfjam; pkg_manager=zypper; package=texlive-pdfjam-bin" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=application/pdf") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(pdfjam --nup "2x1" --landscape --outfile "$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF multiple-page layout/Landscape 4 pages in 1 (2x2) b/.local/share/nautilus/scripts/Document PDF/PDF multiple-page layout/Landscape 4 pages in 1 (2x2) new file mode 100755 index 0000000..8e96e42 --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF multiple-page layout/Landscape 4 pages in 1 (2x2) @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=pdfjam; pkg_manager=apt; package=texlive-extra-utils | + command=pdfjam; pkg_manager=dnf; package=texlive-pdfjam | + command=pdfjam; pkg_manager=pacman; package=texlive-binextra | + command=pdfjam; pkg_manager=zypper; package=texlive-pdfjam-bin" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=application/pdf") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(pdfjam --nup "2x2" --landscape --outfile "$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF multiple-page layout/Landscape 8 pages in 1 (2x4) b/.local/share/nautilus/scripts/Document PDF/PDF multiple-page layout/Landscape 8 pages in 1 (2x4) new file mode 100755 index 0000000..d15e0f9 --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF multiple-page layout/Landscape 8 pages in 1 (2x4) @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=pdfjam; pkg_manager=apt; package=texlive-extra-utils | + command=pdfjam; pkg_manager=dnf; package=texlive-pdfjam | + command=pdfjam; pkg_manager=pacman; package=texlive-binextra | + command=pdfjam; pkg_manager=zypper; package=texlive-pdfjam-bin" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=application/pdf") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(pdfjam --nup "2x4" --landscape --outfile "$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF multiple-page layout/Landscape 8 pages in 1 (4x2) b/.local/share/nautilus/scripts/Document PDF/PDF multiple-page layout/Landscape 8 pages in 1 (4x2) new file mode 100755 index 0000000..1e4ac94 --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF multiple-page layout/Landscape 8 pages in 1 (4x2) @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=pdfjam; pkg_manager=apt; package=texlive-extra-utils | + command=pdfjam; pkg_manager=dnf; package=texlive-pdfjam | + command=pdfjam; pkg_manager=pacman; package=texlive-binextra | + command=pdfjam; pkg_manager=zypper; package=texlive-pdfjam-bin" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=application/pdf") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(pdfjam --nup "4x2" --landscape --outfile "$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF multiple-page layout/Portrait 2 pages in 1 (1x2) b/.local/share/nautilus/scripts/Document PDF/PDF multiple-page layout/Portrait 2 pages in 1 (1x2) new file mode 100755 index 0000000..a21bba7 --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF multiple-page layout/Portrait 2 pages in 1 (1x2) @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=pdfjam; pkg_manager=apt; package=texlive-extra-utils | + command=pdfjam; pkg_manager=dnf; package=texlive-pdfjam | + command=pdfjam; pkg_manager=pacman; package=texlive-binextra | + command=pdfjam; pkg_manager=zypper; package=texlive-pdfjam-bin" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=application/pdf") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(pdfjam --nup "1x2" --no-landscape --outfile "$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF multiple-page layout/Portrait 2 pages in 1 (2x1) b/.local/share/nautilus/scripts/Document PDF/PDF multiple-page layout/Portrait 2 pages in 1 (2x1) new file mode 100755 index 0000000..65704b7 --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF multiple-page layout/Portrait 2 pages in 1 (2x1) @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=pdfjam; pkg_manager=apt; package=texlive-extra-utils | + command=pdfjam; pkg_manager=dnf; package=texlive-pdfjam | + command=pdfjam; pkg_manager=pacman; package=texlive-binextra | + command=pdfjam; pkg_manager=zypper; package=texlive-pdfjam-bin" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=application/pdf") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(pdfjam --nup "2x1" --no-landscape --outfile "$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF multiple-page layout/Portrait 4 pages in 1 (2x2) b/.local/share/nautilus/scripts/Document PDF/PDF multiple-page layout/Portrait 4 pages in 1 (2x2) new file mode 100755 index 0000000..63e1bd8 --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF multiple-page layout/Portrait 4 pages in 1 (2x2) @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=pdfjam; pkg_manager=apt; package=texlive-extra-utils | + command=pdfjam; pkg_manager=dnf; package=texlive-pdfjam | + command=pdfjam; pkg_manager=pacman; package=texlive-binextra | + command=pdfjam; pkg_manager=zypper; package=texlive-pdfjam-bin" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=application/pdf") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(pdfjam --nup "2x2" --no-landscape --outfile "$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF multiple-page layout/Portrait 8 pages in 1 (2x4) b/.local/share/nautilus/scripts/Document PDF/PDF multiple-page layout/Portrait 8 pages in 1 (2x4) new file mode 100755 index 0000000..11039c2 --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF multiple-page layout/Portrait 8 pages in 1 (2x4) @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=pdfjam; pkg_manager=apt; package=texlive-extra-utils | + command=pdfjam; pkg_manager=dnf; package=texlive-pdfjam | + command=pdfjam; pkg_manager=pacman; package=texlive-binextra | + command=pdfjam; pkg_manager=zypper; package=texlive-pdfjam-bin" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=application/pdf") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(pdfjam --nup "2x4" --no-landscape --outfile "$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF multiple-page layout/Portrait 8 pages in 1 (4x2) b/.local/share/nautilus/scripts/Document PDF/PDF multiple-page layout/Portrait 8 pages in 1 (4x2) new file mode 100755 index 0000000..e4487e9 --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF multiple-page layout/Portrait 8 pages in 1 (4x2) @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=pdfjam; pkg_manager=apt; package=texlive-extra-utils | + command=pdfjam; pkg_manager=dnf; package=texlive-pdfjam | + command=pdfjam; pkg_manager=pacman; package=texlive-binextra | + command=pdfjam; pkg_manager=zypper; package=texlive-pdfjam-bin" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=application/pdf") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(pdfjam --nup "4x2" --no-landscape --outfile "$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF optimize, shrink/Linearize (optimize) b/.local/share/nautilus/scripts/Document PDF/PDF optimize, shrink/Linearize (optimize) new file mode 100755 index 0000000..73960eb --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF optimize, shrink/Linearize (optimize) @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=qpdf" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=application/pdf") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + # NOTE: Older 'qpdf' versions do not support ' -- ' in the command line. + std_output=$(qpdf --stream-data=compress --linearize "$input_file" "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF optimize, shrink/List non-linearized PDFs b/.local/share/nautilus/scripts/Document PDF/PDF optimize, shrink/List non-linearized PDFs new file mode 100755 index 0000000..3c69c04 --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF optimize, shrink/List non-linearized PDFs @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + + # Execute initial checks. + _check_dependencies " + command=pdfinfo; pkg_manager=apt; package=poppler-utils | + command=pdfinfo; pkg_manager=dnf; package=poppler-utils | + command=pdfinfo; pkg_manager=pacman; package=poppler | + command=pdfinfo; pkg_manager=zypper; package=poppler-tools" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_recursive=true; par_get_pwd=true; par_select_mime=application/pdf") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "" + + local std_output="" + std_output=$(_storage_text_read_all) + std_output=$(_text_sort "$std_output") + + _display_list_box "$std_output" "--column=File" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local temp_file="" + + # Save the result only for 'not linearized (not optimized)' PDFs. + if pdfinfo "$input_file" | grep "Optimized:" | grep --quiet "no"; then + _storage_text_write_ln "$(_text_remove_pwd "$input_file")" + fi +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF optimize, shrink/Shrink (150 dpi, e-book) b/.local/share/nautilus/scripts/Document PDF/PDF optimize, shrink/Shrink (150 dpi, e-book) new file mode 100755 index 0000000..a701224 --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF optimize, shrink/Shrink (150 dpi, e-book) @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=gs; package=ghostscript" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=application/pdf") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(gs -q -dNOPAUSE -dBATCH -dFastWebView -sDEVICE=pdfwrite -dPDFSETTINGS=/ebook -sOutputFile="$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF optimize, shrink/Shrink (300 dpi, printer) b/.local/share/nautilus/scripts/Document PDF/PDF optimize, shrink/Shrink (300 dpi, printer) new file mode 100755 index 0000000..2247235 --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF optimize, shrink/Shrink (300 dpi, printer) @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=gs; package=ghostscript" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=application/pdf") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(gs -q -dNOPAUSE -dBATCH -dFastWebView -sDEVICE=pdfwrite -dPDFSETTINGS=/printer -sOutputFile="$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF paper size/Paper size to A3 b/.local/share/nautilus/scripts/Document PDF/PDF paper size/Paper size to A3 new file mode 100755 index 0000000..d4d5ba6 --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF paper size/Paper size to A3 @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=pdfjam; pkg_manager=apt; package=texlive-extra-utils | + command=pdfjam; pkg_manager=dnf; package=texlive-pdfjam | + command=pdfjam; pkg_manager=pacman; package=texlive-binextra | + command=pdfjam; pkg_manager=zypper; package=texlive-pdfjam-bin" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=application/pdf") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(pdfjam --papersize "{297mm,420mm}" --outfile "$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF paper size/Paper size to A4 b/.local/share/nautilus/scripts/Document PDF/PDF paper size/Paper size to A4 new file mode 100755 index 0000000..96d159a --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF paper size/Paper size to A4 @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=pdfjam; pkg_manager=apt; package=texlive-extra-utils | + command=pdfjam; pkg_manager=dnf; package=texlive-pdfjam | + command=pdfjam; pkg_manager=pacman; package=texlive-binextra | + command=pdfjam; pkg_manager=zypper; package=texlive-pdfjam-bin" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=application/pdf") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(pdfjam --papersize "{210mm,297mm}" --outfile "$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF paper size/Paper size to A5 b/.local/share/nautilus/scripts/Document PDF/PDF paper size/Paper size to A5 new file mode 100755 index 0000000..336a373 --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF paper size/Paper size to A5 @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=pdfjam; pkg_manager=apt; package=texlive-extra-utils | + command=pdfjam; pkg_manager=dnf; package=texlive-pdfjam | + command=pdfjam; pkg_manager=pacman; package=texlive-binextra | + command=pdfjam; pkg_manager=zypper; package=texlive-pdfjam-bin" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=application/pdf") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(pdfjam --papersize "{148mm,210mm}" --outfile "$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF paper size/Paper size to US Legal b/.local/share/nautilus/scripts/Document PDF/PDF paper size/Paper size to US Legal new file mode 100755 index 0000000..8d60600 --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF paper size/Paper size to US Legal @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=pdfjam; pkg_manager=apt; package=texlive-extra-utils | + command=pdfjam; pkg_manager=dnf; package=texlive-pdfjam | + command=pdfjam; pkg_manager=pacman; package=texlive-binextra | + command=pdfjam; pkg_manager=zypper; package=texlive-pdfjam-bin" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=application/pdf") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(pdfjam --papersize "{8.5in,14in}" --outfile "$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF paper size/Paper size to US Letter b/.local/share/nautilus/scripts/Document PDF/PDF paper size/Paper size to US Letter new file mode 100755 index 0000000..0c07ca3 --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF paper size/Paper size to US Letter @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=pdfjam; pkg_manager=apt; package=texlive-extra-utils | + command=pdfjam; pkg_manager=dnf; package=texlive-pdfjam | + command=pdfjam; pkg_manager=pacman; package=texlive-binextra | + command=pdfjam; pkg_manager=zypper; package=texlive-pdfjam-bin" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=application/pdf") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(pdfjam --papersize "{8.5in,11in}" --outfile "$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF rotate/PDF Rotate (180 deg) b/.local/share/nautilus/scripts/Document PDF/PDF rotate/PDF Rotate (180 deg) new file mode 100755 index 0000000..532e314 --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF rotate/PDF Rotate (180 deg) @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=qpdf" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=application/pdf") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + # NOTE: Older 'qpdf' versions do not support ' -- ' in the command line. + std_output=$(qpdf --rotate=180:1-z "$input_file" "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF rotate/PDF Rotate (270 deg) b/.local/share/nautilus/scripts/Document PDF/PDF rotate/PDF Rotate (270 deg) new file mode 100755 index 0000000..20c0916 --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF rotate/PDF Rotate (270 deg) @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=qpdf" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=application/pdf") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + # NOTE: Older 'qpdf' versions do not support ' -- ' in the command line. + std_output=$(qpdf --rotate=270:1-z "$input_file" "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF rotate/PDF Rotate (90 deg) b/.local/share/nautilus/scripts/Document PDF/PDF rotate/PDF Rotate (90 deg) new file mode 100755 index 0000000..04b08b8 --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF rotate/PDF Rotate (90 deg) @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=qpdf" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=application/pdf") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + # NOTE: Older 'qpdf' versions do not support ' -- ' in the command line. + std_output=$(qpdf --rotate=90:1-z "$input_file" "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF text recognition (OCR)/List non-searchable PDFs b/.local/share/nautilus/scripts/Document PDF/PDF text recognition (OCR)/List non-searchable PDFs new file mode 100755 index 0000000..1b3533e --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF text recognition (OCR)/List non-searchable PDFs @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + + # Execute initial checks. + _check_dependencies " + command=pdffonts; pkg_manager=apt; package=poppler-utils | + command=pdffonts; pkg_manager=dnf; package=poppler-utils | + command=pdffonts; pkg_manager=pacman; package=poppler | + command=pdffonts; pkg_manager=zypper; package=poppler-tools" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_recursive=true; par_get_pwd=true; par_select_mime=application/pdf") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "" + + local std_output="" + std_output=$(_storage_text_read_all) + std_output=$(_text_sort "$std_output") + + _display_list_box "$std_output" "--column=File" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local temp_file="" + + # Save the result only for 'without fonts' PDFs. + if ! pdffonts "$input_file" | sed -n 3p | grep --quiet "."; then + _storage_text_write_ln "$(_text_remove_pwd "$input_file")" + fi +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF text recognition (OCR)/Text OCR (in English) b/.local/share/nautilus/scripts/Document PDF/PDF text recognition (OCR)/Text OCR (in English) new file mode 100755 index 0000000..3eadda1 --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF text recognition (OCR)/Text OCR (in English) @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + TEMP_DATA_TASK="eng" + _check_dependencies " + command=ocrmypdf | + pkg_manager=apt; package=tesseract-ocr-$TEMP_DATA_TASK | + pkg_manager=dnf; package=tesseract-langpack-$TEMP_DATA_TASK | + pkg_manager=pacman; package=tesseract-data-$TEMP_DATA_TASK | + pkg_manager=zypper; package=tesseract-ocr-traineddata-$TEMP_DATA_TASK" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=application/pdf") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(ocrmypdf --l "$TEMP_DATA_TASK" --output-type pdfa --skip-text --jobs "$(_get_max_procs)" -- "$input_file" "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF text recognition (OCR)/Text OCR (in French) b/.local/share/nautilus/scripts/Document PDF/PDF text recognition (OCR)/Text OCR (in French) new file mode 100755 index 0000000..f611eba --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF text recognition (OCR)/Text OCR (in French) @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + TEMP_DATA_TASK="fra" + _check_dependencies " + command=ocrmypdf | + pkg_manager=apt; package=tesseract-ocr-$TEMP_DATA_TASK | + pkg_manager=dnf; package=tesseract-langpack-$TEMP_DATA_TASK | + pkg_manager=pacman; package=tesseract-data-$TEMP_DATA_TASK | + pkg_manager=zypper; package=tesseract-ocr-traineddata-$TEMP_DATA_TASK" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=application/pdf") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(ocrmypdf --l "$TEMP_DATA_TASK" --output-type pdfa --skip-text --jobs "$(_get_max_procs)" -- "$input_file" "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF text recognition (OCR)/Text OCR (in German) b/.local/share/nautilus/scripts/Document PDF/PDF text recognition (OCR)/Text OCR (in German) new file mode 100755 index 0000000..86546d9 --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF text recognition (OCR)/Text OCR (in German) @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + TEMP_DATA_TASK="deu" + _check_dependencies " + command=ocrmypdf | + pkg_manager=apt; package=tesseract-ocr-$TEMP_DATA_TASK | + pkg_manager=dnf; package=tesseract-langpack-$TEMP_DATA_TASK | + pkg_manager=pacman; package=tesseract-data-$TEMP_DATA_TASK | + pkg_manager=zypper; package=tesseract-ocr-traineddata-$TEMP_DATA_TASK" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=application/pdf") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(ocrmypdf --l "$TEMP_DATA_TASK" --output-type pdfa --skip-text --jobs "$(_get_max_procs)" -- "$input_file" "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF text recognition (OCR)/Text OCR (in Italian) b/.local/share/nautilus/scripts/Document PDF/PDF text recognition (OCR)/Text OCR (in Italian) new file mode 100755 index 0000000..27e6723 --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF text recognition (OCR)/Text OCR (in Italian) @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + TEMP_DATA_TASK="ita" + _check_dependencies " + command=ocrmypdf | + pkg_manager=apt; package=tesseract-ocr-$TEMP_DATA_TASK | + pkg_manager=dnf; package=tesseract-langpack-$TEMP_DATA_TASK | + pkg_manager=pacman; package=tesseract-data-$TEMP_DATA_TASK | + pkg_manager=zypper; package=tesseract-ocr-traineddata-$TEMP_DATA_TASK" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=application/pdf") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(ocrmypdf --l "$TEMP_DATA_TASK" --output-type pdfa --skip-text --jobs "$(_get_max_procs)" -- "$input_file" "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF text recognition (OCR)/Text OCR (in Portuguese) b/.local/share/nautilus/scripts/Document PDF/PDF text recognition (OCR)/Text OCR (in Portuguese) new file mode 100755 index 0000000..4aa9c0c --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF text recognition (OCR)/Text OCR (in Portuguese) @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + TEMP_DATA_TASK="por" + _check_dependencies " + command=ocrmypdf | + pkg_manager=apt; package=tesseract-ocr-$TEMP_DATA_TASK | + pkg_manager=dnf; package=tesseract-langpack-$TEMP_DATA_TASK | + pkg_manager=pacman; package=tesseract-data-$TEMP_DATA_TASK | + pkg_manager=zypper; package=tesseract-ocr-traineddata-$TEMP_DATA_TASK" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=application/pdf") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(ocrmypdf --l "$TEMP_DATA_TASK" --output-type pdfa --skip-text --jobs "$(_get_max_procs)" -- "$input_file" "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF text recognition (OCR)/Text OCR (in Russian) b/.local/share/nautilus/scripts/Document PDF/PDF text recognition (OCR)/Text OCR (in Russian) new file mode 100755 index 0000000..cda39e7 --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF text recognition (OCR)/Text OCR (in Russian) @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + TEMP_DATA_TASK="rus" + _check_dependencies " + command=ocrmypdf | + pkg_manager=apt; package=tesseract-ocr-$TEMP_DATA_TASK | + pkg_manager=dnf; package=tesseract-langpack-$TEMP_DATA_TASK | + pkg_manager=pacman; package=tesseract-data-$TEMP_DATA_TASK | + pkg_manager=zypper; package=tesseract-ocr-traineddata-$TEMP_DATA_TASK" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=application/pdf") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(ocrmypdf --l "$TEMP_DATA_TASK" --output-type pdfa --skip-text --jobs "$(_get_max_procs)" -- "$input_file" "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF text recognition (OCR)/Text OCR (in Spanish) b/.local/share/nautilus/scripts/Document PDF/PDF text recognition (OCR)/Text OCR (in Spanish) new file mode 100755 index 0000000..34b2a65 --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF text recognition (OCR)/Text OCR (in Spanish) @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + TEMP_DATA_TASK="spa" + _check_dependencies " + command=ocrmypdf | + pkg_manager=apt; package=tesseract-ocr-$TEMP_DATA_TASK | + pkg_manager=dnf; package=tesseract-langpack-$TEMP_DATA_TASK | + pkg_manager=pacman; package=tesseract-data-$TEMP_DATA_TASK | + pkg_manager=zypper; package=tesseract-ocr-traineddata-$TEMP_DATA_TASK" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=application/pdf") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(ocrmypdf --l "$TEMP_DATA_TASK" --output-type pdfa --skip-text --jobs "$(_get_max_procs)" -- "$input_file" "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF tools/Convert to 'PDFA-2b' b/.local/share/nautilus/scripts/Document PDF/PDF tools/Convert to 'PDFA-2b' new file mode 100755 index 0000000..f9f53ef --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF tools/Convert to 'PDFA-2b' @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=gs; package=ghostscript" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=application/pdf") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(gs -q -dNOPAUSE -dBATCH -dPDFA=2 -dPDFACompatibilityPolicy=1 -sColorConversionStrategy=UseDeviceIndependentColor -sDEVICE=pdfwrite -sOutputFile="$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document PDF/PDF tools/Extract images b/.local/share/nautilus/scripts/Document PDF/PDF tools/Extract images new file mode 100755 index 0000000..664393f --- /dev/null +++ b/.local/share/nautilus/scripts/Document PDF/PDF tools/Extract images @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=pdfimages; pkg_manager=apt; package=poppler-utils | + command=pdfimages; pkg_manager=dnf; package=poppler-utils | + command=pdfimages; pkg_manager=pacman; package=poppler | + command=pdfimages; pkg_manager=zypper; package=poppler-tools" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=application/pdf") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=strip") + std_output=$(pdfimages -all "$input_file" -- "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document/Convert to 'docx' b/.local/share/nautilus/scripts/Document/Convert to 'docx' new file mode 100755 index 0000000..5f40138 --- /dev/null +++ b/.local/share/nautilus/scripts/Document/Convert to 'docx' @@ -0,0 +1,110 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + input_files=$(_get_files "par_type=file; par_validate_conflict=true") + + local dependencies="" + dependencies=$(_get_dependencies "$input_files") + _check_dependencies "$dependencies" + _display_wait_box "2" + output_dir=$(_get_output_dir "par_use_same_dir=true") + + export -f _get_command _run_command + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + + # Run the main process. + local command="" + command=$(_get_command "$input_file") + _run_command "$input_file" "$command" "$output_dir" +} + +_get_dependencies() { + local input_files=$1 + local dependencies="" + + # Check dependencies for each file. + for input_file in $input_files; do + local command="" + command=$(_get_command "$input_file") + + case $command in + "libreoffice_writer") + if ! _command_exists "libreoffice.writer" && ! _command_exists "libreoffice-writer"; then + dependencies+="package=libreoffice-writer" + fi + ;; + "pandoc") dependencies+="command=pandoc" ;; + esac + dependencies+=$'\n' + done + + printf "%s" "$dependencies" +} + +_get_command() { + local input_file=$1 + local command="" + + case "${input_file,,}" in + *.doc | *.docx) command="libreoffice_writer" ;; + *.htm | *.html) command="libreoffice_writer" ;; + *.odf | *.fodf) command="libreoffice_writer" ;; + *.odt | *.fodt) command="libreoffice_writer" ;; + *.rtf) command="libreoffice_writer" ;; + *) command="pandoc" ;; + esac + + printf "%s" "$command" +} + +_run_command() { + local input_file=$1 + local command=$2 + local output_dir=$3 + local output_format="docx" + + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=$output_format") + + # Run the main process. + case $command in + "libreoffice_writer") + # NOTE: Workaround to fix the bug 37531 in LibreOffice. + # See the: https://bugs.documentfoundation.org/show_bug.cgi?id=37531 + local temp_file="" + temp_file=$(_get_temp_file_dry) + + # NOTE: LibreOffice does not support ' -- ' in the command line. + # NOTE: LibreOffice does not support defining the output file manually. + std_output=$(libreoffice --headless --convert-to "$output_format" "-env:UserInstallation=file://$temp_file" --outdir "$output_dir" "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" + + # Remove the temporary file. + rm -f -- "$temp_file" + ;; + "pandoc") + std_output=$(pandoc --standalone -o "$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" + ;; + esac +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document/Convert to 'epub' b/.local/share/nautilus/scripts/Document/Convert to 'epub' new file mode 100755 index 0000000..a8a2401 --- /dev/null +++ b/.local/share/nautilus/scripts/Document/Convert to 'epub' @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=pandoc" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_validate_conflict=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=epub") + std_output=$(pandoc --standalone -o "$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document/Convert to 'markdown' b/.local/share/nautilus/scripts/Document/Convert to 'markdown' new file mode 100755 index 0000000..1c25ee6 --- /dev/null +++ b/.local/share/nautilus/scripts/Document/Convert to 'markdown' @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=pandoc" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_validate_conflict=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=md") + std_output=$(pandoc -t gfm --wrap=none -s -o "$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document/Convert to 'odp' b/.local/share/nautilus/scripts/Document/Convert to 'odp' new file mode 100755 index 0000000..5cd5946 --- /dev/null +++ b/.local/share/nautilus/scripts/Document/Convert to 'odp' @@ -0,0 +1,108 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + input_files=$(_get_files "par_type=file; par_validate_conflict=true") + + local dependencies="" + dependencies=$(_get_dependencies "$input_files") + _check_dependencies "$dependencies" + _display_wait_box "2" + output_dir=$(_get_output_dir "par_use_same_dir=true") + + export -f _get_command _run_command + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + + # Run the main process. + local command="" + command=$(_get_command "$input_file") + _run_command "$input_file" "$command" "$output_dir" +} + +_get_dependencies() { + local input_files=$1 + local dependencies="" + + # Check dependencies for each file. + for input_file in $input_files; do + local command="" + command=$(_get_command "$input_file") + + case $command in + "libreoffice_impress") + if ! _command_exists "libreoffice.impress" && ! _command_exists "libreoffice-impress"; then + dependencies+="package=libreoffice-impress" + fi + ;; + "pandoc") dependencies+="command=pandoc" ;; + esac + dependencies+=$'\n' + done + + printf "%s" "$dependencies" +} + +_get_command() { + local input_file=$1 + local command="" + + case "${input_file,,}" in + *.odg | *.fodg) command="libreoffice_impress" ;; + *.odp | *.fodp) command="libreoffice_impress" ;; + *.ppt | *.pptx) command="libreoffice_impress" ;; + *) command="pandoc" ;; + esac + + printf "%s" "$command" +} + +_run_command() { + local input_file=$1 + local command=$2 + local output_dir=$3 + local output_format="odp" + + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=$output_format") + + # Run the main process. + case $command in + "libreoffice_impress") + # NOTE: Workaround to fix the bug 37531 in LibreOffice. + # See the: https://bugs.documentfoundation.org/show_bug.cgi?id=37531 + local temp_file="" + temp_file=$(_get_temp_file_dry) + + # NOTE: LibreOffice does not support ' -- ' in the command line. + # NOTE: LibreOffice does not support defining the output file manually. + std_output=$(libreoffice --headless --convert-to "$output_format" "-env:UserInstallation=file://$temp_file" --outdir "$output_dir" "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" + + # Remove the temporary file. + rm -f -- "$temp_file" + ;; + "pandoc") + std_output=$(pandoc --standalone -o "$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" + ;; + esac +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document/Convert to 'ods' b/.local/share/nautilus/scripts/Document/Convert to 'ods' new file mode 100755 index 0000000..e9e3afd --- /dev/null +++ b/.local/share/nautilus/scripts/Document/Convert to 'ods' @@ -0,0 +1,108 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + input_files=$(_get_files "par_type=file; par_validate_conflict=true") + + local dependencies="" + dependencies=$(_get_dependencies "$input_files") + _check_dependencies "$dependencies" + _display_wait_box "2" + output_dir=$(_get_output_dir "par_use_same_dir=true") + + export -f _get_command _run_command + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + + # Run the main process. + local command="" + command=$(_get_command "$input_file") + _run_command "$input_file" "$command" "$output_dir" +} + +_get_dependencies() { + local input_files=$1 + local dependencies="" + + # Check dependencies for each file. + for input_file in $input_files; do + local command="" + command=$(_get_command "$input_file") + + case $command in + "libreoffice_calc") + if ! _command_exists "libreoffice.calc" && ! _command_exists "libreoffice-calc"; then + dependencies+="package=libreoffice-calc" + fi + ;; + "pandoc") dependencies+="command=pandoc" ;; + esac + dependencies+=$'\n' + done + + printf "%s" "$dependencies" +} + +_get_command() { + local input_file=$1 + local command="" + + case "${input_file,,}" in + *.ods | *.fods) command="libreoffice_calc" ;; + *.xls | *.xlsx) command="libreoffice_calc" ;; + *.csv) command="libreoffice_calc" ;; + *) command="pandoc" ;; + esac + + printf "%s" "$command" +} + +_run_command() { + local input_file=$1 + local command=$2 + local output_dir=$3 + local output_format="ods" + + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=$output_format") + + # Run the main process. + case $command in + "libreoffice_calc") + # NOTE: Workaround to fix the bug 37531 in LibreOffice. + # See the: https://bugs.documentfoundation.org/show_bug.cgi?id=37531 + local temp_file="" + temp_file=$(_get_temp_file_dry) + + # NOTE: LibreOffice does not support ' -- ' in the command line. + # NOTE: LibreOffice does not support defining the output file manually. + std_output=$(libreoffice --headless --convert-to "$output_format" "-env:UserInstallation=file://$temp_file" --outdir "$output_dir" "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" + + # Remove the temporary file. + rm -f -- "$temp_file" + ;; + "pandoc") + std_output=$(pandoc --standalone -o "$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" + ;; + esac +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document/Convert to 'odt' b/.local/share/nautilus/scripts/Document/Convert to 'odt' new file mode 100755 index 0000000..49d8c51 --- /dev/null +++ b/.local/share/nautilus/scripts/Document/Convert to 'odt' @@ -0,0 +1,110 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + input_files=$(_get_files "par_type=file; par_validate_conflict=true") + + local dependencies="" + dependencies=$(_get_dependencies "$input_files") + _check_dependencies "$dependencies" + _display_wait_box "2" + output_dir=$(_get_output_dir "par_use_same_dir=true") + + export -f _get_command _run_command + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + + # Run the main process. + local command="" + command=$(_get_command "$input_file") + _run_command "$input_file" "$command" "$output_dir" +} + +_get_dependencies() { + local input_files=$1 + local dependencies="" + + # Check dependencies for each file. + for input_file in $input_files; do + local command="" + command=$(_get_command "$input_file") + + case $command in + "libreoffice_writer") + if ! _command_exists "libreoffice.writer" && ! _command_exists "libreoffice-writer"; then + dependencies+="package=libreoffice-writer" + fi + ;; + "pandoc") dependencies+="command=pandoc" ;; + esac + dependencies+=$'\n' + done + + printf "%s" "$dependencies" +} + +_get_command() { + local input_file=$1 + local command="" + + case "${input_file,,}" in + *.doc | *.docx) command="libreoffice_writer" ;; + *.htm | *.html) command="libreoffice_writer" ;; + *.odf | *.fodf) command="libreoffice_writer" ;; + *.odt | *.fodt) command="libreoffice_writer" ;; + *.rtf) command="libreoffice_writer" ;; + *) command="pandoc" ;; + esac + + printf "%s" "$command" +} + +_run_command() { + local input_file=$1 + local command=$2 + local output_dir=$3 + local output_format="odt" + + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=$output_format") + + # Run the main process. + case $command in + "libreoffice_writer") + # NOTE: Workaround to fix the bug 37531 in LibreOffice. + # See the: https://bugs.documentfoundation.org/show_bug.cgi?id=37531 + local temp_file="" + temp_file=$(_get_temp_file_dry) + + # NOTE: LibreOffice does not support ' -- ' in the command line. + # NOTE: LibreOffice does not support defining the output file manually. + std_output=$(libreoffice --headless --convert-to "$output_format" "-env:UserInstallation=file://$temp_file" --outdir "$output_dir" "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" + + # Remove the temporary file. + rm -f -- "$temp_file" + ;; + "pandoc") + std_output=$(pandoc --standalone -o "$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" + ;; + esac +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document/Convert to 'pdf' b/.local/share/nautilus/scripts/Document/Convert to 'pdf' new file mode 100755 index 0000000..4503c1f --- /dev/null +++ b/.local/share/nautilus/scripts/Document/Convert to 'pdf' @@ -0,0 +1,224 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + input_files=$(_get_files "par_type=file; par_validate_conflict=true") + + local dependencies="" + dependencies=$(_get_dependencies "$input_files") + _check_dependencies "$dependencies" + _display_wait_box "2" + output_dir=$(_get_output_dir "par_use_same_dir=true") + + export -f _get_command _run_command + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + + # Run the main process. + local command="" + command=$(_get_command "$input_file") + _run_command "$input_file" "$command" "$output_dir" +} + +_get_dependencies() { + local input_files=$1 + local dependencies="" + + # Check dependencies for each file. + for input_file in $input_files; do + local command="" + command=$(_get_command "$input_file") + + case $command in + "convert") + dependencies+=" + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + ;; + "inkscape") dependencies+="command=inkscape" ;; + "latexmk") + dependencies+=" + command=latexmk | + pkg_manager=apt; package=texlive | + pkg_manager=apt; package=texlive-fonts-extra | + pkg_manager=apt; package=texlive-latex-extra | + pkg_manager=apt; package=texlive-publishers | + pkg_manager=apt; package=texlive-science | + pkg_manager=apt; package=texlive-xetex | + pkg_manager=dnf; package=texlive-scheme-basic | + pkg_manager=dnf; package=texlive-mdwtools | + pkg_manager=pacman; package=texlive-basic | + pkg_manager=pacman; package=texlive-binextra | + pkg_manager=pacman; package=texlive-fontsextra | + pkg_manager=pacman; package=texlive-latex | + pkg_manager=pacman; package=texlive-latexextra | + pkg_manager=pacman; package=texlive-mathscience | + pkg_manager=pacman; package=texlive-publishers | + pkg_manager=pacman; package=texlive-xetex | + pkg_manager=zypper; package=texlive | + pkg_manager=zypper; package=texlive-mathdesign | + pkg_manager=zypper; package=texlive-subeqnarray" + ;; + "libreoffice_calc") + if ! _command_exists "libreoffice.calc" && ! _command_exists "libreoffice-calc"; then + dependencies+="package=libreoffice-calc" + fi + ;; + "libreoffice_impress") + if ! _command_exists "libreoffice.impress" && ! _command_exists "libreoffice-impress"; then + dependencies+="package=libreoffice-impress" + fi + ;; + "libreoffice_writer") + if ! _command_exists "libreoffice.writer" && ! _command_exists "libreoffice-writer"; then + dependencies+="package=libreoffice-writer" + fi + ;; + "pandoc_latex") + dependencies+=" + command=pandoc | + pkg_manager=apt; package=texlive | + pkg_manager=apt; package=texlive-fonts-extra | + pkg_manager=apt; package=texlive-latex-extra | + pkg_manager=apt; package=texlive-publishers | + pkg_manager=apt; package=texlive-science | + pkg_manager=apt; package=texlive-xetex | + pkg_manager=dnf; package=texlive-scheme-basic | + pkg_manager=dnf; package=texlive-mdwtools | + pkg_manager=pacman; package=texlive-basic | + pkg_manager=pacman; package=texlive-binextra | + pkg_manager=pacman; package=texlive-fontsextra | + pkg_manager=pacman; package=texlive-latex | + pkg_manager=pacman; package=texlive-latexextra | + pkg_manager=pacman; package=texlive-mathscience | + pkg_manager=pacman; package=texlive-publishers | + pkg_manager=pacman; package=texlive-xetex | + pkg_manager=zypper; package=texlive | + pkg_manager=zypper; package=texlive-mathdesign | + pkg_manager=zypper; package=texlive-subeqnarray" + ;; + "pandoc") dependencies+="command=pandoc" ;; + esac + dependencies+=$'\n' + done + + printf "%s" "$dependencies" +} + +_get_command() { + local input_file=$1 + local command="" + + case "${input_file,,}" in + *.bmp | *.gif | *.jpeg | *.jpg | *.png | *.tif | *.tiff | *.webp) command="convert" ;; + *.doc | *.docx) command="libreoffice_writer" ;; + *.htm | *.html) command="libreoffice_writer" ;; + *.md | *.markdown) command="pandoc_latex" ;; + *.odf | *.fodf) command="libreoffice_writer" ;; + *.odg | *.fodg) command="libreoffice_impress" ;; + *.odp | *.fodp) command="libreoffice_impress" ;; + *.ods | *.fods) command="libreoffice_calc" ;; + *.odt | *.fodt) command="libreoffice_writer" ;; + *.ppt | *.pptx) command="libreoffice_impress" ;; + *.rtf) command="libreoffice_writer" ;; + *.svg | *.svgz) command="inkscape" ;; + *.tex) command="latexmk" ;; + *.txt) command="pandoc_latex" ;; + *.xls | *.xlsx) command="libreoffice_calc" ;; + *) command="pandoc" ;; + esac + + printf "%s" "$command" +} + +_run_command() { + local input_file=$1 + local command=$2 + local output_dir=$3 + local output_format="pdf" + + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=$output_format") + + # Run the main process. + case $command in + "convert") + std_output=$(convert "$input_file" "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 + ;; + "inkscape") + local inkscape_version="" + local inkscape_version_old="1.0" + inkscape_version=$(inkscape --version | cut -d " " -f 2) + if [[ "$inkscape_version" == $(echo -e "$inkscape_version\n$inkscape_version_old" | sort -V | head -n1) ]]; then + # Old Inkscape version. + std_output=$(inkscape --without-gui --export-area-drawing --file="$input_file" --export-pdf="$output_file" 2>&1) + else + # New Inkscape version. + std_output=$(inkscape --export-area-drawing --export-filename="$output_file" -- "$input_file" 2>&1) + fi + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 + ;; + "latexmk") + # Use a local temporary directory to work. + local filename="" + local temp_dir_output="" + filename=$(basename -- "$input_file") # Remove the path. + filename=$(_strip_filename_extension "$filename") # Remove the extension. + temp_dir_output=$(_get_temp_dir_local "$output_dir" "$filename") + + output_file_temp=$(_get_output_filename "$input_file" "$temp_dir_output" "par_extension_opt=replace; par_extension=$output_format") + + std_output=$(latexmk -f -pdf -interaction=nonstopmode -output-directory="$temp_dir_output" "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file_temp" + + std_output=$(_move_file "rename" "$output_file_temp" "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" + + # Remove the temporary directory. + rm -rf -- "$temp_dir_output" + ;; + "libreoffice_calc" | "libreoffice_impress" | "libreoffice_writer") + # NOTE: Workaround to fix the bug 37531 in LibreOffice. + # See the: https://bugs.documentfoundation.org/show_bug.cgi?id=37531 + local temp_file="" + temp_file=$(_get_temp_file_dry) + + # NOTE: LibreOffice does not support ' -- ' in the command line. + # NOTE: LibreOffice does not support defining the output file manually. + std_output=$(libreoffice --headless --convert-to "$output_format" "-env:UserInstallation=file://$temp_file" --outdir "$output_dir" "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" + + # Remove the temporary file. + rm -f -- "$temp_file" + ;; + "pandoc_latex") + std_output=$(pandoc -V "geometry:margin=1.5cm" -V "geometry:a4paper" -V "fontfamily:charter" --standalone -o "$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" + ;; + "pandoc") + std_output=$(pandoc --standalone -o "$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" + ;; + esac +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document/Convert to 'pptx' b/.local/share/nautilus/scripts/Document/Convert to 'pptx' new file mode 100755 index 0000000..aa44d9e --- /dev/null +++ b/.local/share/nautilus/scripts/Document/Convert to 'pptx' @@ -0,0 +1,108 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + input_files=$(_get_files "par_type=file; par_validate_conflict=true") + + local dependencies="" + dependencies=$(_get_dependencies "$input_files") + _check_dependencies "$dependencies" + _display_wait_box "2" + output_dir=$(_get_output_dir "par_use_same_dir=true") + + export -f _get_command _run_command + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + + # Run the main process. + local command="" + command=$(_get_command "$input_file") + _run_command "$input_file" "$command" "$output_dir" +} + +_get_dependencies() { + local input_files=$1 + local dependencies="" + + # Check dependencies for each file. + for input_file in $input_files; do + local command="" + command=$(_get_command "$input_file") + + case $command in + "libreoffice_impress") + if ! _command_exists "libreoffice.impress" && ! _command_exists "libreoffice-impress"; then + dependencies+="package=libreoffice-impress" + fi + ;; + "pandoc") dependencies+="command=pandoc" ;; + esac + dependencies+=$'\n' + done + + printf "%s" "$dependencies" +} + +_get_command() { + local input_file=$1 + local command="" + + case "${input_file,,}" in + *.odg | *.fodg) command="libreoffice_impress" ;; + *.odp | *.fodp) command="libreoffice_impress" ;; + *.ppt | *.pptx) command="libreoffice_impress" ;; + *) command="pandoc" ;; + esac + + printf "%s" "$command" +} + +_run_command() { + local input_file=$1 + local command=$2 + local output_dir=$3 + local output_format="pptx" + + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=$output_format") + + # Run the main process. + case $command in + "libreoffice_impress") + # NOTE: Workaround to fix the bug 37531 in LibreOffice. + # See the: https://bugs.documentfoundation.org/show_bug.cgi?id=37531 + local temp_file="" + temp_file=$(_get_temp_file_dry) + + # NOTE: LibreOffice does not support ' -- ' in the command line. + # NOTE: LibreOffice does not support defining the output file manually. + std_output=$(libreoffice --headless --convert-to "$output_format" "-env:UserInstallation=file://$temp_file" --outdir "$output_dir" "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" + + # Remove the temporary file. + rm -f -- "$temp_file" + ;; + "pandoc") + std_output=$(pandoc --standalone -o "$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" + ;; + esac +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document/Convert to 'txt' b/.local/share/nautilus/scripts/Document/Convert to 'txt' new file mode 100755 index 0000000..09670bc --- /dev/null +++ b/.local/share/nautilus/scripts/Document/Convert to 'txt' @@ -0,0 +1,122 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + input_files=$(_get_files "par_type=file; par_validate_conflict=true") + + local dependencies="" + dependencies=$(_get_dependencies "$input_files") + _check_dependencies "$dependencies" + _display_wait_box "2" + output_dir=$(_get_output_dir "par_use_same_dir=true") + + export -f _get_command _run_command + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + + # Run the main process. + local command="" + command=$(_get_command "$input_file") + _run_command "$input_file" "$command" "$output_dir" +} + +_get_dependencies() { + local input_files=$1 + local dependencies="" + + # Check dependencies for each file. + for input_file in $input_files; do + local command="" + command=$(_get_command "$input_file") + + case $command in + "libreoffice_writer") + if ! _command_exists "libreoffice.writer" && ! _command_exists "libreoffice-writer"; then + dependencies+="package=libreoffice-writer" + fi + ;; + "pandoc") dependencies+="command=pandoc" ;; + "pdftotext") + dependencies+=" + command=pdftotext; pkg_manager=apt; package=poppler-utils | + command=pdftotext; pkg_manager=dnf; package=poppler-utils | + command=pdftotext; pkg_manager=pacman; package=poppler | + command=pdftotext; pkg_manager=zypper; package=poppler-tools" + ;; + esac + dependencies+=$'\n' + done + + printf "%s" "$dependencies" +} + +_get_command() { + local input_file=$1 + local command="" + + case "${input_file,,}" in + *.doc | *.docx) command="libreoffice_writer" ;; + *.htm | *.html) command="libreoffice_writer" ;; + *.odf | *.fodf) command="libreoffice_writer" ;; + *.odt | *.fodt) command="libreoffice_writer" ;; + *.pdf) command="pdftotext" ;; + *.rtf) command="libreoffice_writer" ;; + *) command="pandoc" ;; + esac + + printf "%s" "$command" +} + +_run_command() { + local input_file=$1 + local command=$2 + local output_dir=$3 + local output_format="txt" + + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=$output_format") + + # Run the main process. + case $command in + "libreoffice_writer") + # NOTE: Workaround to fix the bug 37531 in LibreOffice. + # See the: https://bugs.documentfoundation.org/show_bug.cgi?id=37531 + local temp_file="" + temp_file=$(_get_temp_file_dry) + + # NOTE: LibreOffice does not support ' -- ' in the command line. + # NOTE: LibreOffice does not support defining the output file manually. + std_output=$(libreoffice --headless --convert-to "$output_format" "-env:UserInstallation=file://$temp_file" --outdir "$output_dir" "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" + + # Remove the temporary file. + rm -f -- "$temp_file" + ;; + "pandoc") + std_output=$(pandoc --standalone -o "$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" + ;; + "pdftotext") + std_output=$(pdftotext "$input_file" -- "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" + ;; + esac +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Document/Convert to 'xlsx' b/.local/share/nautilus/scripts/Document/Convert to 'xlsx' new file mode 100755 index 0000000..77f42f6 --- /dev/null +++ b/.local/share/nautilus/scripts/Document/Convert to 'xlsx' @@ -0,0 +1,108 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + input_files=$(_get_files "par_type=file; par_validate_conflict=true") + + local dependencies="" + dependencies=$(_get_dependencies "$input_files") + _check_dependencies "$dependencies" + _display_wait_box "2" + output_dir=$(_get_output_dir "par_use_same_dir=true") + + export -f _get_command _run_command + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + + # Run the main process. + local command="" + command=$(_get_command "$input_file") + _run_command "$input_file" "$command" "$output_dir" +} + +_get_dependencies() { + local input_files=$1 + local dependencies="" + + # Check dependencies for each file. + for input_file in $input_files; do + local command="" + command=$(_get_command "$input_file") + + case $command in + "libreoffice_calc") + if ! _command_exists "libreoffice.calc" && ! _command_exists "libreoffice-calc"; then + dependencies+="package=libreoffice-calc" + fi + ;; + "pandoc") dependencies+="command=pandoc" ;; + esac + dependencies+=$'\n' + done + + printf "%s" "$dependencies" +} + +_get_command() { + local input_file=$1 + local command="" + + case "${input_file,,}" in + *.ods | *.fods) command="libreoffice_calc" ;; + *.xls | *.xlsx) command="libreoffice_calc" ;; + *.csv) command="libreoffice_calc" ;; + *) command="pandoc" ;; + esac + + printf "%s" "$command" +} + +_run_command() { + local input_file=$1 + local command=$2 + local output_dir=$3 + local output_format="xlsx" + + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=$output_format") + + # Run the main process. + case $command in + "libreoffice_calc") + # NOTE: Workaround to fix the bug 37531 in LibreOffice. + # See the: https://bugs.documentfoundation.org/show_bug.cgi?id=37531 + local temp_file="" + temp_file=$(_get_temp_file_dry) + + # NOTE: LibreOffice does not support ' -- ' in the command line. + # NOTE: LibreOffice does not support defining the output file manually. + std_output=$(libreoffice --headless --convert-to "$output_format" "-env:UserInstallation=file://$temp_file" --outdir "$output_dir" "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" + + # Remove the temporary file. + rm -f -- "$temp_file" + ;; + "pandoc") + std_output=$(pandoc --standalone -o "$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" + ;; + esac +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/File encryption/GPG Decrypt b/.local/share/nautilus/scripts/File encryption/GPG Decrypt new file mode 100755 index 0000000..1f9c54e --- /dev/null +++ b/.local/share/nautilus/scripts/File encryption/GPG Decrypt @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=gpg; pkg_manager=apt; package=gpg | + command=gpg; pkg_manager=dnf; package=gnupg2 | + command=gpg; pkg_manager=pacman; package=gnupg | + command=gpg; pkg_manager=zypper; package=gpg2" + input_files=$(_get_files "par_type=file; par_select_mime='application/octet-stream|application/pgp|application/pgp-encrypted|text/plain'") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=strip") + std_output=$(gpg --batch --yes --decrypt --output "$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/File encryption/GPG Encrypt with password b/.local/share/nautilus/scripts/File encryption/GPG Encrypt with password new file mode 100755 index 0000000..47acf0c --- /dev/null +++ b/.local/share/nautilus/scripts/File encryption/GPG Encrypt with password @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=gpg; pkg_manager=apt; package=gpg | + command=gpg; pkg_manager=dnf; package=gnupg2 | + command=gpg; pkg_manager=pacman; package=gnupg | + command=gpg; pkg_manager=zypper; package=gpg2" + _display_wait_box "0" + input_files=$(_get_files "par_type=file") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + TEMP_DATA_TASK=$(_display_password_box_define) || _exit_script + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=append; par_extension=gpg") + std_output=$(gpg --batch --yes --symmetric --passphrase "$TEMP_DATA_TASK" --for-your-eyes-only --s2k-count 1015808 --s2k-digest-algo SHA256 --compress-algo zlib --cipher-algo AES256 --output "$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/File encryption/GPG Encrypt with password (ASCII out) b/.local/share/nautilus/scripts/File encryption/GPG Encrypt with password (ASCII out) new file mode 100755 index 0000000..aee67d5 --- /dev/null +++ b/.local/share/nautilus/scripts/File encryption/GPG Encrypt with password (ASCII out) @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=gpg; pkg_manager=apt; package=gpg | + command=gpg; pkg_manager=dnf; package=gnupg2 | + command=gpg; pkg_manager=pacman; package=gnupg | + command=gpg; pkg_manager=zypper; package=gpg2" + _display_wait_box "0" + input_files=$(_get_files "par_type=file") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + TEMP_DATA_TASK=$(_display_password_box_define) || _exit_script + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=append; par_extension=asc") + std_output=$(gpg --batch --yes --symmetric --passphrase "$TEMP_DATA_TASK" --for-your-eyes-only --armor --s2k-count 1015808 --s2k-digest-algo SHA256 --compress-algo zlib --cipher-algo AES256 --output "$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/File encryption/GPG Encrypt with public key b/.local/share/nautilus/scripts/File encryption/GPG Encrypt with public key new file mode 100755 index 0000000..c01be39 --- /dev/null +++ b/.local/share/nautilus/scripts/File encryption/GPG Encrypt with public key @@ -0,0 +1,63 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=gpg; pkg_manager=apt; package=gpg | + command=gpg; pkg_manager=dnf; package=gnupg2 | + command=gpg; pkg_manager=pacman; package=gnupg | + command=gpg; pkg_manager=zypper; package=gpg2" + input_files=$(_get_files "par_type=file") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + local users="" + users=$(gpg --list-public-keys --with-colons | grep "^uid" | cut -d ':' -f 10 2>/dev/null) + if [[ -z "$users" ]]; then + _display_error_box "Failed: no public keys imported!" + _exit_script + fi + + # shellcheck disable=SC2086 + if _command_exists "zenity"; then + users=$(tr "\n" "$FIELD_SEPARATOR" <<<"$users") + TEMP_DATA_TASK=$(zenity --list --title="Select a user" --text="Select a user from the list below." --column="User" --height=300 --width=600 $users 2>/dev/null) || _exit_script + elif _command_exists "kdialog"; then + # shellcheck disable=SC2001 + users=$(sed "s|\(.*\)|\1:\1:off|g" <<<"$users") + users=$(tr ":\n" "$FIELD_SEPARATOR" <<<"$users") + TEMP_DATA_TASK=$(kdialog --title "Select a user" --geometry "600x300" --radiolist "Select a user from the list below." $users 2>/dev/null) || _exit_script + fi + + if [[ -z "$TEMP_DATA_TASK" ]]; then + _display_error_box "Failed: you must select a user!" + _exit_script + fi + + _display_wait_box "2" + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=append; par_extension=gpg") + std_output=$(gpg --batch --yes --encrypt --recipient "$TEMP_DATA_TASK" --for-your-eyes-only --s2k-count 1015808 --s2k-digest-algo SHA256 --compress-algo zlib --cipher-algo AES256 --output "$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/File encryption/GPG Encrypt with public key (ASCII out) b/.local/share/nautilus/scripts/File encryption/GPG Encrypt with public key (ASCII out) new file mode 100755 index 0000000..4d5d8a2 --- /dev/null +++ b/.local/share/nautilus/scripts/File encryption/GPG Encrypt with public key (ASCII out) @@ -0,0 +1,63 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=gpg; pkg_manager=apt; package=gpg | + command=gpg; pkg_manager=dnf; package=gnupg2 | + command=gpg; pkg_manager=pacman; package=gnupg | + command=gpg; pkg_manager=zypper; package=gpg2" + input_files=$(_get_files "par_type=file") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + local users="" + users=$(gpg --list-public-keys --with-colons | grep "^uid" | cut -d ':' -f 10 2>/dev/null) + if [[ -z "$users" ]]; then + _display_error_box "Failed: no public keys imported!" + _exit_script + fi + + # shellcheck disable=SC2086 + if _command_exists "zenity"; then + users=$(tr "\n" "$FIELD_SEPARATOR" <<<"$users") + TEMP_DATA_TASK=$(zenity --list --title="Select a user" --text="Select a user from the list below." --column="User" --height=300 --width=600 $users 2>/dev/null) || _exit_script + elif _command_exists "kdialog"; then + # shellcheck disable=SC2001 + users=$(sed "s|\(.*\)|\1:\1:off|g" <<<"$users") + users=$(tr ":\n" "$FIELD_SEPARATOR" <<<"$users") + TEMP_DATA_TASK=$(kdialog --title "Select a user" --geometry "600x300" --radiolist "Select a user from the list below." $users 2>/dev/null) || _exit_script + fi + + if [[ -z "$TEMP_DATA_TASK" ]]; then + _display_error_box "Failed: you must select a user!" + _exit_script + fi + + _display_wait_box "2" + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=append; par_extension=asc") + std_output=$(gpg --batch --yes --encrypt --recipient "$TEMP_DATA_TASK" --for-your-eyes-only --armor --s2k-count 1015808 --s2k-digest-algo SHA256 --compress-algo zlib --cipher-algo AES256 --output "$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/File encryption/GPG Import key b/.local/share/nautilus/scripts/File encryption/GPG Import key new file mode 100755 index 0000000..44b75a7 --- /dev/null +++ b/.local/share/nautilus/scripts/File encryption/GPG Import key @@ -0,0 +1,44 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=gpg; pkg_manager=apt; package=gpg | + command=gpg; pkg_manager=dnf; package=gnupg2 | + command=gpg; pkg_manager=pacman; package=gnupg | + command=gpg; pkg_manager=zypper; package=gpg2" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime='application/octet-stream|application/pgp-keys|text/plain'") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + local key_id="" + + # Get the ID from the key. + key_id=$(gpg --with-colons --import-options show-only --import "$input_file" | grep -m1 "^fpr" | cut -d ':' -f 10 2>/dev/null) + + # Import the key. + std_output=$(gpg --batch --yes --import "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 + + # Set the trust level to 'ultimate'. + std_output=$(printf "%s\n" "$key_id:6:" | gpg --batch --yes --import-ownertrust 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/File encryption/GPG Sign b/.local/share/nautilus/scripts/File encryption/GPG Sign new file mode 100755 index 0000000..4881b8a --- /dev/null +++ b/.local/share/nautilus/scripts/File encryption/GPG Sign @@ -0,0 +1,63 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=gpg; pkg_manager=apt; package=gpg | + command=gpg; pkg_manager=dnf; package=gnupg2 | + command=gpg; pkg_manager=pacman; package=gnupg | + command=gpg; pkg_manager=zypper; package=gpg2" + input_files=$(_get_files "par_type=file") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + local users="" + users=$(gpg --list-secret-keys --with-colons | grep "^uid" | cut -d ':' -f 10 2>/dev/null) + if [[ -z "$users" ]]; then + _display_error_box "Failed: no secret keys imported!" + _exit_script + fi + + # shellcheck disable=SC2086 + if _command_exists "zenity"; then + users=$(tr "\n" "$FIELD_SEPARATOR" <<<"$users") + TEMP_DATA_TASK=$(zenity --list --title="Select a user" --text="Select a user from the list below." --column="User" --height=300 --width=600 $users 2>/dev/null) || _exit_script + elif _command_exists "kdialog"; then + # shellcheck disable=SC2001 + users=$(sed "s|\(.*\)|\1:\1:off|g" <<<"$users") + users=$(tr ":\n" "$FIELD_SEPARATOR" <<<"$users") + TEMP_DATA_TASK=$(kdialog --title "Select a user" --geometry "600x300" --radiolist "Select a user from the list below." $users 2>/dev/null) || _exit_script + fi + + if [[ -z "$TEMP_DATA_TASK" ]]; then + _display_error_box "Failed: you must select a user!" + _exit_script + fi + + _display_wait_box "2" + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=append; par_extension=gpg") + std_output=$(gpg --batch --yes --sign --local-user "$TEMP_DATA_TASK" --output "$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/File encryption/GPG Sign (ASCII out) b/.local/share/nautilus/scripts/File encryption/GPG Sign (ASCII out) new file mode 100755 index 0000000..9926e0a --- /dev/null +++ b/.local/share/nautilus/scripts/File encryption/GPG Sign (ASCII out) @@ -0,0 +1,63 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=gpg; pkg_manager=apt; package=gpg | + command=gpg; pkg_manager=dnf; package=gnupg2 | + command=gpg; pkg_manager=pacman; package=gnupg | + command=gpg; pkg_manager=zypper; package=gpg2" + input_files=$(_get_files "par_type=file") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + local users="" + users=$(gpg --list-secret-keys --with-colons | grep "^uid" | cut -d ':' -f 10 2>/dev/null) + if [[ -z "$users" ]]; then + _display_error_box "Failed: no secret keys imported!" + _exit_script + fi + + # shellcheck disable=SC2086 + if _command_exists "zenity"; then + users=$(tr "\n" "$FIELD_SEPARATOR" <<<"$users") + TEMP_DATA_TASK=$(zenity --list --title="Select a user" --text="Select a user from the list below." --column="User" --height=300 --width=600 $users 2>/dev/null) || _exit_script + elif _command_exists "kdialog"; then + # shellcheck disable=SC2001 + users=$(sed "s|\(.*\)|\1:\1:off|g" <<<"$users") + users=$(tr ":\n" "$FIELD_SEPARATOR" <<<"$users") + TEMP_DATA_TASK=$(kdialog --title "Select a user" --geometry "600x300" --radiolist "Select a user from the list below." $users 2>/dev/null) || _exit_script + fi + + if [[ -z "$TEMP_DATA_TASK" ]]; then + _display_error_box "Failed: you must select a user!" + _exit_script + fi + + _display_wait_box "2" + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=append; par_extension=asc") + std_output=$(gpg --batch --yes --clearsign --local-user "$TEMP_DATA_TASK" --output "$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/File encryption/GPG Sign (detached signature) b/.local/share/nautilus/scripts/File encryption/GPG Sign (detached signature) new file mode 100755 index 0000000..b6b8461 --- /dev/null +++ b/.local/share/nautilus/scripts/File encryption/GPG Sign (detached signature) @@ -0,0 +1,63 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=gpg; pkg_manager=apt; package=gpg | + command=gpg; pkg_manager=dnf; package=gnupg2 | + command=gpg; pkg_manager=pacman; package=gnupg | + command=gpg; pkg_manager=zypper; package=gpg2" + input_files=$(_get_files "par_type=file") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + local users="" + users=$(gpg --list-secret-keys --with-colons | grep "^uid" | cut -d ':' -f 10 2>/dev/null) + if [[ -z "$users" ]]; then + _display_error_box "Failed: no secret keys imported!" + _exit_script + fi + + # shellcheck disable=SC2086 + if _command_exists "zenity"; then + users=$(tr "\n" "$FIELD_SEPARATOR" <<<"$users") + TEMP_DATA_TASK=$(zenity --list --title="Select a user" --text="Select a user from the list below." --column="User" --height=300 --width=600 $users 2>/dev/null) || _exit_script + elif _command_exists "kdialog"; then + # shellcheck disable=SC2001 + users=$(sed "s|\(.*\)|\1:\1:off|g" <<<"$users") + users=$(tr ":\n" "$FIELD_SEPARATOR" <<<"$users") + TEMP_DATA_TASK=$(kdialog --title "Select a user" --geometry "600x300" --radiolist "Select a user from the list below." $users 2>/dev/null) || _exit_script + fi + + if [[ -z "$TEMP_DATA_TASK" ]]; then + _display_error_box "Failed: you must select a user!" + _exit_script + fi + + _display_wait_box "2" + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=append; par_extension=sig") + std_output=$(gpg --batch --yes --detach-sign --local-user "$TEMP_DATA_TASK" --output "$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/File encryption/GPG Verify signature b/.local/share/nautilus/scripts/File encryption/GPG Verify signature new file mode 100755 index 0000000..c2f3ec2 --- /dev/null +++ b/.local/share/nautilus/scripts/File encryption/GPG Verify signature @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + + # Execute initial checks. + _check_dependencies " + command=gpg; pkg_manager=apt; package=gpg | + command=gpg; pkg_manager=dnf; package=gnupg2 | + command=gpg; pkg_manager=pacman; package=gnupg | + command=gpg; pkg_manager=zypper; package=gpg2" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime='application/octet-stream|application/pgp|application/pgp-encrypted|application/pgp-signature|text/PGP|text/plain'") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "" + + local output_dir="" + std_output=$(_storage_text_read_all) + + _display_text_box "$std_output" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + + # Run the main process. + std_output=$(gpg --yes --verify -- "$input_file" 2>&1) + + _storage_text_write_ln "\"$(_text_remove_pwd "$input_file")\""$'\n'"$std_output"$'\n' +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/File permissions/List permissions and owners b/.local/share/nautilus/scripts/File permissions/List permissions and owners new file mode 100755 index 0000000..d11722e --- /dev/null +++ b/.local/share/nautilus/scripts/File permissions/List permissions and owners @@ -0,0 +1,40 @@ +#!/usr/bin/env bash +# install_keyboard_shortcut=P + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=all; par_recursive=true; par_get_pwd=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + + local std_output="" + std_output=$(_storage_text_read_all) + std_output=$(_text_sort "$std_output") + + _display_list_box "$std_output" "--column=Octal;--column=User;--column=Group;--column=Type;--column=File" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + + # Run the main process. + std_output=$(stat --format="%a$FIELD_SEPARATOR%U$FIELD_SEPARATOR%G$FIELD_SEPARATOR%F$FIELD_SEPARATOR%n" -- "$input_file" 2>/dev/null) + std_output=$(_text_remove_pwd "$std_output") + + _storage_text_write_ln "$std_output" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/File permissions/Reset permissions (recursive) b/.local/share/nautilus/scripts/File permissions/Reset permissions (recursive) new file mode 100755 index 0000000..a2b9e4e --- /dev/null +++ b/.local/share/nautilus/scripts/File permissions/Reset permissions (recursive) @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=all") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + local new_pemission="" + + # Run the main process. + new_pemission=$(printf "%04o" "$((0666 - $(umask)))") + std_output=$(find "$input_file" ! -path "$IGNORE_FIND_PATH" -type f -exec chmod "$new_pemission" -- {} \+ 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 + + new_pemission=$(printf "%04o" "$((0777 - $(umask)))") + std_output=$(find "$input_file" ! -path "$IGNORE_FIND_PATH" -type d -exec chmod "$new_pemission" -- {} \+ 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/File permissions/Set executable b/.local/share/nautilus/scripts/File permissions/Set executable new file mode 100755 index 0000000..541e90c --- /dev/null +++ b/.local/share/nautilus/scripts/File permissions/Set executable @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=file") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + + # Run the main process. + std_output=$(chmod +x -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/File permissions/Set executable for '.sh' (recursive) b/.local/share/nautilus/scripts/File permissions/Set executable for '.sh' (recursive) new file mode 100755 index 0000000..db6627c --- /dev/null +++ b/.local/share/nautilus/scripts/File permissions/Set executable for '.sh' (recursive) @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_recursive=true; par_select_extension=sh") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + + # Run the main process. + std_output=$(chmod +x -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Forensic/File carving (foremost) b/.local/share/nautilus/scripts/Forensic/File carving (foremost) new file mode 100755 index 0000000..2001a13 --- /dev/null +++ b/.local/share/nautilus/scripts/Forensic/File carving (foremost) @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=foremost" + _display_wait_box "2" + input_files=$(_get_files "par_type=file") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + + # Run the main process. + output_dir="$(_strip_filename_extension "$input_file")-output" + std_output=$(foremost -t all -i "$input_file" -o "$output_dir" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Forensic/File carving (photorec) b/.local/share/nautilus/scripts/Forensic/File carving (photorec) new file mode 100755 index 0000000..3b1d0ef --- /dev/null +++ b/.local/share/nautilus/scripts/Forensic/File carving (photorec) @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=photorec; pkg_manager=apt; package=testdisk | + command=photorec; pkg_manager=dnf; package=testdisk | + command=photorec; pkg_manager=pacman; package=testdisk | + command=photorec; pkg_manager=zypper; package=photorec" + _display_wait_box "2" + input_files=$(_get_files "par_type=file") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + + # Run the main process. + output_dir="$(_strip_filename_extension "$input_file")-output" + std_output=$(photorec /d "$output_dir" /cmd "$input_file" partition_none,fileopt,everything,enable,search 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Forensic/Secure remove (shred) b/.local/share/nautilus/scripts/Forensic/Secure remove (shred) new file mode 100755 index 0000000..a9ff56e --- /dev/null +++ b/.local/share/nautilus/scripts/Forensic/Secure remove (shred) @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + input_files=$(_get_files "par_type=file") + + local std_output="" + std_output=$(_convert_filenames_to_text "$input_files") + std_output=$(_text_remove_pwd "$std_output") + + if ! _display_question_box "Are you sure you want to permanently remove the selected files?"; then + _exit_script + fi + + _display_wait_box "2" + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + + # Run the main process. + std_output=$(shred --force --zero --remove -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Hash and checksum/List CRC32 b/.local/share/nautilus/scripts/Hash and checksum/List CRC32 new file mode 100755 index 0000000..808f033 --- /dev/null +++ b/.local/share/nautilus/scripts/Hash and checksum/List CRC32 @@ -0,0 +1,51 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=rhash" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_recursive=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + + local std_output="" + std_output=$(_storage_text_read_all) + std_output=$(_text_sort "$std_output") + # shellcheck disable=SC2001 + std_output=$(sed "s|\(.*\)$FIELD_SEPARATOR\(.*\)|\2$FIELD_SEPARATOR\1|g" <<<"$std_output") + + _display_list_box "$std_output" "--column=CRC32;--column=File" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + local nl_escaped="\\\n" + + # Run the main process. + std_output=$(rhash --printf="%c %p\n" -- "$input_file" 2>/dev/null) + std_output=$(_text_remove_pwd "$std_output") + + # Convert filenames with '\n'. + if [[ "$std_output" == *$'\n'* ]]; then + std_output=$(sed -z "s|\n|$nl_escaped|g; s|$nl_escaped$||g" <<<"$std_output") + std_output="\\$std_output" + fi + + # shellcheck disable=SC2001 + std_output=$(sed "s|\([^ ]*\)\s*\(.*\)|\2$FIELD_SEPARATOR\1|g" <<<"$std_output") + + _storage_text_write_ln "$std_output" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Hash and checksum/List MD5 b/.local/share/nautilus/scripts/Hash and checksum/List MD5 new file mode 100755 index 0000000..28e4e13 --- /dev/null +++ b/.local/share/nautilus/scripts/Hash and checksum/List MD5 @@ -0,0 +1,44 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_recursive=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + + local std_output="" + std_output=$(_storage_text_read_all) + std_output=$(_text_sort "$std_output") + # shellcheck disable=SC2001 + std_output=$(sed "s|\(.*\)$FIELD_SEPARATOR\(.*\)|\2$FIELD_SEPARATOR\1|g" <<<"$std_output") + + _display_list_box "$std_output" "--column=MD5;--column=File" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + + # Run the main process. + std_output=$(md5sum -- "$input_file" 2>/dev/null) + std_output=$(_text_remove_pwd "$std_output") + + # shellcheck disable=SC2001 + std_output=$(sed "s|\([^ ]*\)\s*\(.*\)|\2$FIELD_SEPARATOR\1|g" <<<"$std_output") + + _storage_text_write_ln "$std_output" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Hash and checksum/List SHA-1 b/.local/share/nautilus/scripts/Hash and checksum/List SHA-1 new file mode 100755 index 0000000..5e30bd9 --- /dev/null +++ b/.local/share/nautilus/scripts/Hash and checksum/List SHA-1 @@ -0,0 +1,44 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_recursive=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + + local std_output="" + std_output=$(_storage_text_read_all) + std_output=$(_text_sort "$std_output") + # shellcheck disable=SC2001 + std_output=$(sed "s|\(.*\)$FIELD_SEPARATOR\(.*\)|\2$FIELD_SEPARATOR\1|g" <<<"$std_output") + + _display_list_box "$std_output" "--column=SHA-1;--column=File" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + + # Run the main process. + std_output=$(sha1sum -- "$input_file" 2>/dev/null) + std_output=$(_text_remove_pwd "$std_output") + + # shellcheck disable=SC2001 + std_output=$(sed "s|\([^ ]*\)\s*\(.*\)|\2$FIELD_SEPARATOR\1|g" <<<"$std_output") + + _storage_text_write_ln "$std_output" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Hash and checksum/List SHA-256 b/.local/share/nautilus/scripts/Hash and checksum/List SHA-256 new file mode 100755 index 0000000..e1736d3 --- /dev/null +++ b/.local/share/nautilus/scripts/Hash and checksum/List SHA-256 @@ -0,0 +1,44 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_recursive=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + + local std_output="" + std_output=$(_storage_text_read_all) + std_output=$(_text_sort "$std_output") + # shellcheck disable=SC2001 + std_output=$(sed "s|\(.*\)$FIELD_SEPARATOR\(.*\)|\2$FIELD_SEPARATOR\1|g" <<<"$std_output") + + _display_list_box "$std_output" "--column=SHA-256;--column=File" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + + # Run the main process. + std_output=$(sha256sum -- "$input_file" 2>/dev/null) + std_output=$(_text_remove_pwd "$std_output") + + # shellcheck disable=SC2001 + std_output=$(sed "s|\([^ ]*\)\s*\(.*\)|\2$FIELD_SEPARATOR\1|g" <<<"$std_output") + + _storage_text_write_ln "$std_output" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Hash and checksum/List SHA-512 b/.local/share/nautilus/scripts/Hash and checksum/List SHA-512 new file mode 100755 index 0000000..e95f884 --- /dev/null +++ b/.local/share/nautilus/scripts/Hash and checksum/List SHA-512 @@ -0,0 +1,44 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_recursive=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + + local std_output="" + std_output=$(_storage_text_read_all) + std_output=$(_text_sort "$std_output") + # shellcheck disable=SC2001 + std_output=$(sed "s|\(.*\)$FIELD_SEPARATOR\(.*\)|\2$FIELD_SEPARATOR\1|g" <<<"$std_output") + + _display_list_box "$std_output" "--column=SHA-512;--column=File" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + + # Run the main process. + std_output=$(sha512sum -- "$input_file" 2>/dev/null) + std_output=$(_text_remove_pwd "$std_output") + + # shellcheck disable=SC2001 + std_output=$(sed "s|\([^ ]*\)\s*\(.*\)|\2$FIELD_SEPARATOR\1|g" <<<"$std_output") + + _storage_text_write_ln "$std_output" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Hash and checksum/List all hashes b/.local/share/nautilus/scripts/Hash and checksum/List all hashes new file mode 100755 index 0000000..1212a41 --- /dev/null +++ b/.local/share/nautilus/scripts/Hash and checksum/List all hashes @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=rhash" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_recursive=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + + local std_output="" + std_output=$(_storage_text_read_all) + + _display_text_box "$std_output" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + + # Run the main process. + std_output=$(rhash --printf="%p:\nCRC32: %c\nMD5: %m\nSHA-1: %h\nSHA-224: %{sha-224}\nSHA-256: %{sha-256}\nSHA-384: %{sha-384}\nSHA-512: %{sha-512}\n " -- "$input_file" 2>/dev/null) + std_output=$(_text_remove_pwd "$std_output") + + _storage_text_write_ln "$std_output" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Hash and checksum/Produce 'md5sum.txt' b/.local/share/nautilus/scripts/Hash and checksum/Produce 'md5sum.txt' new file mode 100755 index 0000000..bf81a5c --- /dev/null +++ b/.local/share/nautilus/scripts/Hash and checksum/Produce 'md5sum.txt' @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_recursive=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + + local output_file="" + output_file=$(_get_output_filename "md5sum.txt" "$output_dir" "par_extension_opt=preserve") + + local std_output="" + std_output=$(_storage_text_read_all) + std_output=$(_text_sort "$std_output") + # shellcheck disable=SC2001 + std_output=$(sed "s|\(.*\)$FIELD_SEPARATOR\(.*\)|\2 \1|g" <<<"$std_output") + printf "%s" "$std_output" >"$output_file" + + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + + # Run the main process. + std_output=$(md5sum -- "$input_file" 2>/dev/null) + std_output=$(_text_remove_pwd "$std_output") + + # shellcheck disable=SC2001 + std_output=$(sed "s|\([^ ]*\)\s*\(.*\)|\2$FIELD_SEPARATOR\1|g" <<<"$std_output") + + _storage_text_write_ln "$std_output" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Hash and checksum/Produce 'sha1sum.txt' b/.local/share/nautilus/scripts/Hash and checksum/Produce 'sha1sum.txt' new file mode 100755 index 0000000..da15088 --- /dev/null +++ b/.local/share/nautilus/scripts/Hash and checksum/Produce 'sha1sum.txt' @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_recursive=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + + local output_file="" + output_file=$(_get_output_filename "sha1sum.txt" "$output_dir" "par_extension_opt=preserve") + + local std_output="" + std_output=$(_storage_text_read_all) + std_output=$(_text_sort "$std_output") + # shellcheck disable=SC2001 + std_output=$(sed "s|\(.*\)$FIELD_SEPARATOR\(.*\)|\2 \1|g" <<<"$std_output") + printf "%s" "$std_output" >"$output_file" + + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + + # Run the main process. + std_output=$(sha1sum -- "$input_file" 2>/dev/null) + std_output=$(_text_remove_pwd "$std_output") + + # shellcheck disable=SC2001 + std_output=$(sed "s|\([^ ]*\)\s*\(.*\)|\2$FIELD_SEPARATOR\1|g" <<<"$std_output") + + _storage_text_write_ln "$std_output" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Hash and checksum/Produce 'sha256sum.txt' b/.local/share/nautilus/scripts/Hash and checksum/Produce 'sha256sum.txt' new file mode 100755 index 0000000..752747d --- /dev/null +++ b/.local/share/nautilus/scripts/Hash and checksum/Produce 'sha256sum.txt' @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_recursive=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + + local output_file="" + output_file=$(_get_output_filename "sha256sum.txt" "$output_dir" "par_extension_opt=preserve") + + local std_output="" + std_output=$(_storage_text_read_all) + std_output=$(_text_sort "$std_output") + # shellcheck disable=SC2001 + std_output=$(sed "s|\(.*\)$FIELD_SEPARATOR\(.*\)|\2 \1|g" <<<"$std_output") + printf "%s" "$std_output" >"$output_file" + + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + + # Run the main process. + std_output=$(sha256sum -- "$input_file" 2>/dev/null) + std_output=$(_text_remove_pwd "$std_output") + + # shellcheck disable=SC2001 + std_output=$(sed "s|\([^ ]*\)\s*\(.*\)|\2$FIELD_SEPARATOR\1|g" <<<"$std_output") + + _storage_text_write_ln "$std_output" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Hash and checksum/Produce 'sha512sum.txt' b/.local/share/nautilus/scripts/Hash and checksum/Produce 'sha512sum.txt' new file mode 100755 index 0000000..244da2e --- /dev/null +++ b/.local/share/nautilus/scripts/Hash and checksum/Produce 'sha512sum.txt' @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_recursive=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + + local output_file="" + output_file=$(_get_output_filename "sha512sum.txt" "$output_dir" "par_extension_opt=preserve") + + local std_output="" + std_output=$(_storage_text_read_all) + std_output=$(_text_sort "$std_output") + # shellcheck disable=SC2001 + std_output=$(sed "s|\(.*\)$FIELD_SEPARATOR\(.*\)|\2 \1|g" <<<"$std_output") + printf "%s" "$std_output" >"$output_file" + + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + + # Run the main process. + std_output=$(sha512sum -- "$input_file" 2>/dev/null) + std_output=$(_text_remove_pwd "$std_output") + + # shellcheck disable=SC2001 + std_output=$(sed "s|\([^ ]*\)\s*\(.*\)|\2$FIELD_SEPARATOR\1|g" <<<"$std_output") + + _storage_text_write_ln "$std_output" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Hash and checksum/Verify 'md5sum.txt' b/.local/share/nautilus/scripts/Hash and checksum/Verify 'md5sum.txt' new file mode 100755 index 0000000..42ed8e6 --- /dev/null +++ b/.local/share/nautilus/scripts/Hash and checksum/Verify 'md5sum.txt' @@ -0,0 +1,81 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_max_items=1; par_select_mime=text/plain") + + # Allows the symbol "'" in filenames (inside 'xargs'). + checksum_file=$(sed -z "s|'|'\\\''|g" <"$input_files") + + # Export variables to be used inside new shells (when using 'xargs'). + export TEMP_DIR_STORAGE_TEXT + + # Export functions to be used inside new shells (when using 'xargs'). + export -f \ + _storage_text_write \ + _storage_text_write_ln \ + _verify_checksum + + printf "%s" "$checksum_file" | xargs \ + --no-run-if-empty \ + --delimiter=$'\n' \ + --max-procs="$(_get_max_procs)" \ + --replace="{}" \ + bash -c "_verify_checksum '{}'" + + local std_output="" + std_output=$(_storage_text_read_all) + std_output=$(_text_sort "$std_output") + + if [[ -z "$std_output" ]]; then + std_output="No errors found." + fi + + _display_text_box "$std_output" +} + +_verify_checksum() { + local line=$1 + local saved_checksum="" + local saved_file="" + local current_output="" + local current_checksum="" + + saved_checksum=$(printf "%s" "$line" | cut -d " " -f1) + saved_file=$(printf "%s" "$line" | cut -d " " -f3-) + + # Replace % to %% with the 'printf' command. + saved_file=${saved_file//%/%%} + + # Some checksums start with '\', for filenames with '\n' or '\'. + # shellcheck disable=SC2059 + saved_file_decoded=$(printf "$saved_file") + + # If the file does not exist, report and skip the check. + if [[ ! -e "$saved_file_decoded" ]]; then + _storage_text_write_ln "[ERROR] No such file: $saved_file" + return 1 + fi + + current_output=$(md5sum -- "$saved_file_decoded" 2>/dev/null) + current_checksum=$(printf "%s" "$current_output" | cut -d " " -f1) + + # Compare the checksum. + if [[ "$saved_checksum" != "$current_checksum" ]]; then + _storage_text_write_ln "[ERROR] Mismatch checksum for the file: $saved_file. Saved: $saved_checksum. Current: $current_checksum." + return 1 + fi + + return 0 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Hash and checksum/Verify 'sha1sum.txt' b/.local/share/nautilus/scripts/Hash and checksum/Verify 'sha1sum.txt' new file mode 100755 index 0000000..0108d92 --- /dev/null +++ b/.local/share/nautilus/scripts/Hash and checksum/Verify 'sha1sum.txt' @@ -0,0 +1,81 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_max_items=1; par_select_mime=text/plain") + + # Allows the symbol "'" in filenames (inside 'xargs'). + checksum_file=$(sed -z "s|'|'\\\''|g" <"$input_files") + + # Export variables to be used inside new shells (when using 'xargs'). + export TEMP_DIR_STORAGE_TEXT + + # Export functions to be used inside new shells (when using 'xargs'). + export -f \ + _storage_text_write \ + _storage_text_write_ln \ + _verify_checksum + + printf "%s" "$checksum_file" | xargs \ + --no-run-if-empty \ + --delimiter=$'\n' \ + --max-procs="$(_get_max_procs)" \ + --replace="{}" \ + bash -c "_verify_checksum '{}'" + + local std_output="" + std_output=$(_storage_text_read_all) + std_output=$(_text_sort "$std_output") + + if [[ -z "$std_output" ]]; then + std_output="No errors found." + fi + + _display_text_box "$std_output" +} + +_verify_checksum() { + local line=$1 + local saved_checksum="" + local saved_file="" + local current_output="" + local current_checksum="" + + saved_checksum=$(printf "%s" "$line" | cut -d " " -f1) + saved_file=$(printf "%s" "$line" | cut -d " " -f3-) + + # Replace % to %% with the 'printf' command. + saved_file=${saved_file//%/%%} + + # Some checksums start with '\', for filenames with '\n' or '\'. + # shellcheck disable=SC2059 + saved_file_decoded=$(printf "$saved_file") + + # If the file does not exist, report and skip the check. + if [[ ! -e "$saved_file_decoded" ]]; then + _storage_text_write_ln "[ERROR] No such file: $saved_file" + return 1 + fi + + current_output=$(sha1sum -- "$saved_file_decoded" 2>/dev/null) + current_checksum=$(printf "%s" "$current_output" | cut -d " " -f1) + + # Compare the checksum. + if [[ "$saved_checksum" != "$current_checksum" ]]; then + _storage_text_write_ln "[ERROR] Mismatch checksum for the file: $saved_file. Saved: $saved_checksum. Current: $current_checksum." + return 1 + fi + + return 0 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Hash and checksum/Verify 'sha256sum.txt' b/.local/share/nautilus/scripts/Hash and checksum/Verify 'sha256sum.txt' new file mode 100755 index 0000000..5ef9e1a --- /dev/null +++ b/.local/share/nautilus/scripts/Hash and checksum/Verify 'sha256sum.txt' @@ -0,0 +1,81 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_max_items=1; par_select_mime=text/plain") + + # Allows the symbol "'" in filenames (inside 'xargs'). + checksum_file=$(sed -z "s|'|'\\\''|g" <"$input_files") + + # Export variables to be used inside new shells (when using 'xargs'). + export TEMP_DIR_STORAGE_TEXT + + # Export functions to be used inside new shells (when using 'xargs'). + export -f \ + _storage_text_write \ + _storage_text_write_ln \ + _verify_checksum + + printf "%s" "$checksum_file" | xargs \ + --no-run-if-empty \ + --delimiter=$'\n' \ + --max-procs="$(_get_max_procs)" \ + --replace="{}" \ + bash -c "_verify_checksum '{}'" + + local std_output="" + std_output=$(_storage_text_read_all) + std_output=$(_text_sort "$std_output") + + if [[ -z "$std_output" ]]; then + std_output="No errors found." + fi + + _display_text_box "$std_output" +} + +_verify_checksum() { + local line=$1 + local saved_checksum="" + local saved_file="" + local current_output="" + local current_checksum="" + + saved_checksum=$(printf "%s" "$line" | cut -d " " -f1) + saved_file=$(printf "%s" "$line" | cut -d " " -f3-) + + # Replace % to %% with the 'printf' command. + saved_file=${saved_file//%/%%} + + # Some checksums start with '\', for filenames with '\n' or '\'. + # shellcheck disable=SC2059 + saved_file_decoded=$(printf "$saved_file") + + # If the file does not exist, report and skip the check. + if [[ ! -e "$saved_file_decoded" ]]; then + _storage_text_write_ln "[ERROR] No such file: $saved_file" + return 1 + fi + + current_output=$(sha256sum -- "$saved_file_decoded" 2>/dev/null) + current_checksum=$(printf "%s" "$current_output" | cut -d " " -f1) + + # Compare the checksum. + if [[ "$saved_checksum" != "$current_checksum" ]]; then + _storage_text_write_ln "[ERROR] Mismatch checksum for the file: $saved_file. Saved: $saved_checksum. Current: $current_checksum." + return 1 + fi + + return 0 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Hash and checksum/Verify 'sha512sum.txt' b/.local/share/nautilus/scripts/Hash and checksum/Verify 'sha512sum.txt' new file mode 100755 index 0000000..ef32310 --- /dev/null +++ b/.local/share/nautilus/scripts/Hash and checksum/Verify 'sha512sum.txt' @@ -0,0 +1,81 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_max_items=1; par_select_mime=text/plain") + + # Allows the symbol "'" in filenames (inside 'xargs'). + checksum_file=$(sed -z "s|'|'\\\''|g" <"$input_files") + + # Export variables to be used inside new shells (when using 'xargs'). + export TEMP_DIR_STORAGE_TEXT + + # Export functions to be used inside new shells (when using 'xargs'). + export -f \ + _storage_text_write \ + _storage_text_write_ln \ + _verify_checksum + + printf "%s" "$checksum_file" | xargs \ + --no-run-if-empty \ + --delimiter=$'\n' \ + --max-procs="$(_get_max_procs)" \ + --replace="{}" \ + bash -c "_verify_checksum '{}'" + + local std_output="" + std_output=$(_storage_text_read_all) + std_output=$(_text_sort "$std_output") + + if [[ -z "$std_output" ]]; then + std_output="No errors found." + fi + + _display_text_box "$std_output" +} + +_verify_checksum() { + local line=$1 + local saved_checksum="" + local saved_file="" + local current_output="" + local current_checksum="" + + saved_checksum=$(printf "%s" "$line" | cut -d " " -f1) + saved_file=$(printf "%s" "$line" | cut -d " " -f3-) + + # Replace % to %% with the 'printf' command. + saved_file=${saved_file//%/%%} + + # Some checksums start with '\', for filenames with '\n' or '\'. + # shellcheck disable=SC2059 + saved_file_decoded=$(printf "$saved_file") + + # If the file does not exist, report and skip the check. + if [[ ! -e "$saved_file_decoded" ]]; then + _storage_text_write_ln "[ERROR] No such file: $saved_file" + return 1 + fi + + current_output=$(sha512sum -- "$saved_file_decoded" 2>/dev/null) + current_checksum=$(printf "%s" "$current_output" | cut -d " " -f1) + + # Compare the checksum. + if [[ "$saved_checksum" != "$current_checksum" ]]; then + _storage_text_write_ln "[ERROR] Mismatch checksum for the file: $saved_file. Saved: $saved_checksum. Current: $current_checksum." + return 1 + fi + + return 0 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image SVG/Convert 'svg' to 'svgz' (compress) b/.local/share/nautilus/scripts/Image SVG/Convert 'svg' to 'svgz' (compress) new file mode 100755 index 0000000..70cc0fd --- /dev/null +++ b/.local/share/nautilus/scripts/Image SVG/Convert 'svg' to 'svgz' (compress) @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=gzip" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime='image/svg+xml'") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=svgz") + std_output=$(gzip "$input_file" --no-name -c >"$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image SVG/Convert 'svgz' to 'svg' (decompress) b/.local/share/nautilus/scripts/Image SVG/Convert 'svgz' to 'svg' (decompress) new file mode 100755 index 0000000..35e69a9 --- /dev/null +++ b/.local/share/nautilus/scripts/Image SVG/Convert 'svgz' to 'svg' (decompress) @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=gzip" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime='application/gzip'") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=svg") + std_output=$(gzip -S gz -d "$input_file" -c >"$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image SVG/Export 'svg' to 'eps' b/.local/share/nautilus/scripts/Image SVG/Export 'svg' to 'eps' new file mode 100755 index 0000000..055bb4f --- /dev/null +++ b/.local/share/nautilus/scripts/Image SVG/Export 'svg' to 'eps' @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=inkscape" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime='image/svg+xml|application/gzip'") + output_dir=$(_get_output_dir "par_use_same_dir=true; par_validate_conflict=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=eps") + + local inkscape_version="" + local inkscape_version_old="1.0" + inkscape_version=$(inkscape --version | cut -d " " -f 2) + if [[ "$inkscape_version" == $(echo -e "$inkscape_version\n$inkscape_version_old" | sort -V | head -n1) ]]; then + # Old Inkscape version. + std_output=$(inkscape --without-gui --export-area-drawing --file="$input_file" --export-eps="$output_file" 2>&1) + else + # New Inkscape version. + std_output=$(inkscape --export-area-drawing --export-filename="$output_file" -- "$input_file" 2>&1) + fi + + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image SVG/Export 'svg' to 'pdf' b/.local/share/nautilus/scripts/Image SVG/Export 'svg' to 'pdf' new file mode 100755 index 0000000..fa9f2a4 --- /dev/null +++ b/.local/share/nautilus/scripts/Image SVG/Export 'svg' to 'pdf' @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=inkscape" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime='image/svg+xml|application/gzip'") + output_dir=$(_get_output_dir "par_use_same_dir=true; par_validate_conflict=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=pdf") + + local inkscape_version="" + local inkscape_version_old="1.0" + inkscape_version=$(inkscape --version | cut -d " " -f 2) + if [[ "$inkscape_version" == $(echo -e "$inkscape_version\n$inkscape_version_old" | sort -V | head -n1) ]]; then + # Old Inkscape version. + std_output=$(inkscape --without-gui --export-area-drawing --file="$input_file" --export-pdf="$output_file" 2>&1) + else + # New Inkscape version. + std_output=$(inkscape --export-area-drawing --export-filename="$output_file" -- "$input_file" 2>&1) + fi + + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image SVG/Export 'svg' to 'png' (1024 px) b/.local/share/nautilus/scripts/Image SVG/Export 'svg' to 'png' (1024 px) new file mode 100755 index 0000000..82d45d3 --- /dev/null +++ b/.local/share/nautilus/scripts/Image SVG/Export 'svg' to 'png' (1024 px) @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=inkscape" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime='image/svg+xml|application/gzip'") + output_dir=$(_get_output_dir "par_use_same_dir=true; par_validate_conflict=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=png") + + local inkscape_version="" + local inkscape_version_old="1.0" + inkscape_version=$(inkscape --version | cut -d " " -f 2) + if [[ "$inkscape_version" == $(echo -e "$inkscape_version\n$inkscape_version_old" | sort -V | head -n1) ]]; then + # Old Inkscape version. + std_output=$(inkscape --without-gui --export-area-drawing --file="$input_file" --export-height=1024 --export-png="$output_file" 2>&1) + else + # New Inkscape version. + std_output=$(inkscape --export-area-drawing --export-height=1024 --export-filename="$output_file" -- "$input_file" 2>&1) + fi + + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image SVG/Export 'svg' to 'png' (256 px) b/.local/share/nautilus/scripts/Image SVG/Export 'svg' to 'png' (256 px) new file mode 100755 index 0000000..af50a66 --- /dev/null +++ b/.local/share/nautilus/scripts/Image SVG/Export 'svg' to 'png' (256 px) @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=inkscape" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime='image/svg+xml|application/gzip'") + output_dir=$(_get_output_dir "par_use_same_dir=true; par_validate_conflict=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=png") + + local inkscape_version="" + local inkscape_version_old="1.0" + inkscape_version=$(inkscape --version | cut -d " " -f 2) + if [[ "$inkscape_version" == $(echo -e "$inkscape_version\n$inkscape_version_old" | sort -V | head -n1) ]]; then + # Old Inkscape version. + std_output=$(inkscape --without-gui --export-area-drawing --file="$input_file" --export-height=256 --export-png="$output_file" 2>&1) + else + # New Inkscape version. + std_output=$(inkscape --export-area-drawing --export-height=256 --export-filename="$output_file" -- "$input_file" 2>&1) + fi + + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image SVG/Export 'svg' to 'png' (512 px) b/.local/share/nautilus/scripts/Image SVG/Export 'svg' to 'png' (512 px) new file mode 100755 index 0000000..402659e --- /dev/null +++ b/.local/share/nautilus/scripts/Image SVG/Export 'svg' to 'png' (512 px) @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=inkscape" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime='image/svg+xml|application/gzip'") + output_dir=$(_get_output_dir "par_use_same_dir=true; par_validate_conflict=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=png") + + local inkscape_version="" + local inkscape_version_old="1.0" + inkscape_version=$(inkscape --version | cut -d " " -f 2) + if [[ "$inkscape_version" == $(echo -e "$inkscape_version\n$inkscape_version_old" | sort -V | head -n1) ]]; then + # Old Inkscape version. + std_output=$(inkscape --without-gui --export-area-drawing --file="$input_file" --export-height=512 --export-png="$output_file" 2>&1) + else + # New Inkscape version. + std_output=$(inkscape --export-area-drawing --export-height=512 --export-filename="$output_file" -- "$input_file" 2>&1) + fi + + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image SVG/Replace fonts to 'Charter' b/.local/share/nautilus/scripts/Image SVG/Replace fonts to 'Charter' new file mode 100755 index 0000000..b9b4ae9 --- /dev/null +++ b/.local/share/nautilus/scripts/Image SVG/Replace fonts to 'Charter' @@ -0,0 +1,62 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime='image/svg+xml'") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + local temp_file="" + local new_font="Charter" + + __key_remove() { + local file=$1 + local key=$2 + + sed -i "s|$key:[^;\"]*;*||g; s|;\"|\"|g" "$file" + } + + __key_set_value() { + local file=$1 + local key=$2 + local value=$3 + + sed -i "s|$key:[^;\"]*\([;\"]\)|$key:$value\1|g" "$file" + } + + # Work on a temporary file. + temp_file=$(_get_temp_file) + std_output=$(cp --archive -- "$input_file" "$temp_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 + + # Run the main process. + __key_remove "$temp_file" "font-stretch" + __key_set_value "$temp_file" "font-family" "$new_font" + __key_set_value "$temp_file" "-inkscape-font-specification" "$new_font" + _check_output "$?" "$std_output" "$input_file" "" || return 1 + + # Move the temporary file to the output. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + _move_temp_file_to_output "$input_file" "$temp_file" "$output_file" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image SVG/Replace fonts to 'Helvetica' b/.local/share/nautilus/scripts/Image SVG/Replace fonts to 'Helvetica' new file mode 100755 index 0000000..d18e715 --- /dev/null +++ b/.local/share/nautilus/scripts/Image SVG/Replace fonts to 'Helvetica' @@ -0,0 +1,62 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime='image/svg+xml'") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + local temp_file="" + local new_font="Helvetica" + + __key_remove() { + local file=$1 + local key=$2 + + sed -i "s|$key:[^;\"]*;*||g; s|;\"|\"|g" "$file" + } + + __key_set_value() { + local file=$1 + local key=$2 + local value=$3 + + sed -i "s|$key:[^;\"]*\([;\"]\)|$key:$value\1|g" "$file" + } + + # Work on a temporary file. + temp_file=$(_get_temp_file) + std_output=$(cp --archive -- "$input_file" "$temp_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 + + # Run the main process. + __key_remove "$temp_file" "font-stretch" + __key_set_value "$temp_file" "font-family" "$new_font" + __key_set_value "$temp_file" "-inkscape-font-specification" "$new_font" + _check_output "$?" "$std_output" "$input_file" "" || return 1 + + # Move the temporary file to the output. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + _move_temp_file_to_output "$input_file" "$temp_file" "$output_file" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image SVG/Replace fonts to 'Times' b/.local/share/nautilus/scripts/Image SVG/Replace fonts to 'Times' new file mode 100755 index 0000000..c5642f9 --- /dev/null +++ b/.local/share/nautilus/scripts/Image SVG/Replace fonts to 'Times' @@ -0,0 +1,62 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime='image/svg+xml'") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + local temp_file="" + local new_font="Times" + + __key_remove() { + local file=$1 + local key=$2 + + sed -i "s|$key:[^;\"]*;*||g; s|;\"|\"|g" "$file" + } + + __key_set_value() { + local file=$1 + local key=$2 + local value=$3 + + sed -i "s|$key:[^;\"]*\([;\"]\)|$key:$value\1|g" "$file" + } + + # Work on a temporary file. + temp_file=$(_get_temp_file) + std_output=$(cp --archive -- "$input_file" "$temp_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 + + # Run the main process. + __key_remove "$temp_file" "font-stretch" + __key_set_value "$temp_file" "font-family" "$new_font" + __key_set_value "$temp_file" "-inkscape-font-specification" "$new_font" + _check_output "$?" "$std_output" "$input_file" "" || return 1 + + # Move the temporary file to the output. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + _move_temp_file_to_output "$input_file" "$temp_file" "$output_file" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Colors/Colorspace to Gray b/.local/share/nautilus/scripts/Image/Colors/Colorspace to Gray new file mode 100755 index 0000000..50f2ee6 --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Colors/Colorspace to Gray @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(convert "$input_file" -colorspace gray -type palette "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Colors/Desaturate (average) b/.local/share/nautilus/scripts/Image/Colors/Desaturate (average) new file mode 100755 index 0000000..0c9efab --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Colors/Desaturate (average) @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(convert "$input_file" -grayscale average "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Colors/Desaturate (luma) b/.local/share/nautilus/scripts/Image/Colors/Desaturate (luma) new file mode 100755 index 0000000..258d5b1 --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Colors/Desaturate (luma) @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(convert "$input_file" -grayscale rec709luma "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Colors/Generate multiple Hue b/.local/share/nautilus/scripts/Image/Colors/Generate multiple Hue new file mode 100755 index 0000000..654a776 --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Colors/Generate multiple Hue @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + local suffix=1 + for ((i = 100 + 30; i < 300; i += 30)); do + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve; par_suffix='($suffix)'") + std_output=$(convert "$input_file" -define modulate:colorspace=HSB -modulate "100,100,$i" "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 + suffix=$((suffix + 1)) + done +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Combine, split/Combine into a 'gif' b/.local/share/nautilus/scripts/Image/Combine, split/Combine into a 'gif' new file mode 100755 index 0000000..b14d90e --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Combine, split/Combine into a 'gif' @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/; par_min_items=2; par_sort_list=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + _main_task "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_files=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "Animated image.gif" "$output_dir" "par_extension_opt=preserve") + # shellcheck disable=SC2086 + std_output=$(convert -delay 100 -loop 0 $input_files "$output_file" 2>&1) + _check_output "$?" "$std_output" "" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Combine, split/Combine into a 'pdf' b/.local/share/nautilus/scripts/Image/Combine, split/Combine into a 'pdf' new file mode 100755 index 0000000..b4ba74f --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Combine, split/Combine into a 'pdf' @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/; par_min_items=2; par_sort_list=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + _main_task "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_files=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "Combined images.pdf" "$output_dir" "par_extension_opt=preserve") + # shellcheck disable=SC2086 + std_output=$(convert $input_files "$output_file" 2>&1) + _check_output "$?" "$std_output" "" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Combine, split/Concatenate (horizontally) b/.local/share/nautilus/scripts/Image/Combine, split/Concatenate (horizontally) new file mode 100755 index 0000000..8a77de3 --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Combine, split/Concatenate (horizontally) @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/; par_min_items=2; par_sort_list=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + _main_task "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_files=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "Concatenated images.png" "$output_dir" "par_extension_opt=preserve") + # shellcheck disable=SC2086 + std_output=$(convert $input_files +append +repage "$output_file" 2>&1) + _check_output "$?" "$std_output" "" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Combine, split/Concatenate (vertically) b/.local/share/nautilus/scripts/Image/Combine, split/Concatenate (vertically) new file mode 100755 index 0000000..8bb5d5a --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Combine, split/Concatenate (vertically) @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/; par_min_items=2; par_sort_list=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + _main_task "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_files=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "Concatenated images.png" "$output_dir" "par_extension_opt=preserve") + # shellcheck disable=SC2086 + std_output=$(convert $input_files -append +repage "$output_file" 2>&1) + _check_output "$?" "$std_output" "" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Combine, split/Split into 2 (horizontally) b/.local/share/nautilus/scripts/Image/Combine, split/Split into 2 (horizontally) new file mode 100755 index 0000000..b4d9297 --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Combine, split/Split into 2 (horizontally) @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(convert "$input_file" -crop 100%x50% +repage "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Combine, split/Split into 2 (vertically) b/.local/share/nautilus/scripts/Image/Combine, split/Split into 2 (vertically) new file mode 100755 index 0000000..7bd11f9 --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Combine, split/Split into 2 (vertically) @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(convert "$input_file" -crop 50%x100% +repage "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Combine, split/Split into 4 b/.local/share/nautilus/scripts/Image/Combine, split/Split into 4 new file mode 100755 index 0000000..745cecb --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Combine, split/Split into 4 @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(convert "$input_file" -crop 50%x50% +repage "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Convert/Convert to 'bmp' b/.local/share/nautilus/scripts/Image/Convert/Convert to 'bmp' new file mode 100755 index 0000000..130020c --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Convert/Convert to 'bmp' @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/; par_validate_conflict=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=bmp") + std_output=$(convert "$input_file" "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Convert/Convert to 'gif' b/.local/share/nautilus/scripts/Image/Convert/Convert to 'gif' new file mode 100755 index 0000000..d8705e5 --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Convert/Convert to 'gif' @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/; par_validate_conflict=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=gif") + std_output=$(convert "$input_file" "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Convert/Convert to 'jpg' b/.local/share/nautilus/scripts/Image/Convert/Convert to 'jpg' new file mode 100755 index 0000000..f06e508 --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Convert/Convert to 'jpg' @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/; par_validate_conflict=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=jpg") + std_output=$(convert "$input_file" "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Convert/Convert to 'png' b/.local/share/nautilus/scripts/Image/Convert/Convert to 'png' new file mode 100755 index 0000000..027338e --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Convert/Convert to 'png' @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/; par_validate_conflict=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=png") + std_output=$(convert "$input_file" "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Convert/Convert to 'tif' b/.local/share/nautilus/scripts/Image/Convert/Convert to 'tif' new file mode 100755 index 0000000..4478c0a --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Convert/Convert to 'tif' @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/; par_validate_conflict=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=tif") + std_output=$(convert "$input_file" "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Convert/Convert to 'webp' b/.local/share/nautilus/scripts/Image/Convert/Convert to 'webp' new file mode 100755 index 0000000..9f6cc29 --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Convert/Convert to 'webp' @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/; par_validate_conflict=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=webp") + std_output=$(convert "$input_file" -auto-orient "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Convert/Export to 'pdf' b/.local/share/nautilus/scripts/Image/Convert/Export to 'pdf' new file mode 100755 index 0000000..d310150 --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Convert/Export to 'pdf' @@ -0,0 +1,106 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + input_files=$(_get_files "par_type=file; par_select_mime=image/; par_validate_conflict=true") + + local dependencies="" + dependencies=$(_get_dependencies "$input_files") + _check_dependencies "$dependencies" + _display_wait_box "2" + output_dir=$(_get_output_dir "par_use_same_dir=true") + + export -f _get_command _run_command + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + + # Run the main process. + local command="" + command=$(_get_command "$input_file") + _run_command "$input_file" "$command" "$output_dir" +} + +_get_dependencies() { + local input_files=$1 + local dependencies="" + + # Check dependencies for each file. + for input_file in $input_files; do + local command="" + command=$(_get_command "$input_file") + + case $command in + "convert") + dependencies+=" + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick" + ;; + "inkscape") dependencies+="command=inkscape" ;; + esac + dependencies+=$'\n' + done + + printf "%s" "$dependencies" +} + +_get_command() { + local input_file=$1 + local command="" + + case "${input_file,,}" in + *.svg | *.svgz) command="inkscape" ;; + *) command="convert" ;; + esac + + printf "%s" "$command" +} + +_run_command() { + local input_file=$1 + local command=$2 + local output_dir=$3 + local output_format="pdf" + + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=$output_format") + + # Run the main process. + case $command in + "convert") + std_output=$(convert "$input_file" "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 + ;; + "inkscape") + local inkscape_version="" + local inkscape_version_old="1.0" + inkscape_version=$(inkscape --version | cut -d " " -f 2) + if [[ "$inkscape_version" == $(echo -e "$inkscape_version\n$inkscape_version_old" | sort -V | head -n1) ]]; then + # Old Inkscape version. + std_output=$(inkscape --without-gui --export-area-drawing --file="$input_file" --export-pdf="$output_file" 2>&1) + else + # New Inkscape version. + std_output=$(inkscape --export-area-drawing --export-filename="$output_file" -- "$input_file" 2>&1) + fi + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 + ;; + esac +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Create icon/Create 'png' icon (128 px) b/.local/share/nautilus/scripts/Image/Create icon/Create 'png' icon (128 px) new file mode 100755 index 0000000..c0a0ccf --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Create icon/Create 'png' icon (128 px) @@ -0,0 +1,112 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + local temp_file1="" + local temp_file2="" + local temp_file3="" + local temp_file4="" + local icon_size="128" + + # Work on a temporary file. + temp_file1="$(_get_temp_file_dry).png" + temp_file2="$(_get_temp_file_dry).png" + temp_file3="$(_get_temp_file_dry).png" + temp_file4="$(_get_temp_file_dry).png" + + # Run the process (part 0) 'export svg'. + local filename_extension="" + local input_file_proc="" + filename_extension=$(_get_filename_extension "$input_file") + if [[ "${filename_extension,,}" == ".svg"* ]]; then + + local inkscape_version="" + local inkscape_version_old="1.0" + inkscape_version=$(inkscape --version | cut -d " " -f 2) + if [[ "$inkscape_version" == $(echo -e "$inkscape_version\n$inkscape_version_old" | sort -V | head -n1) ]]; then + # Old Inkscape version. + std_output=$(inkscape --without-gui --export-area-drawing --file="$input_file" --export-height=$((icon_size * 2)) --export-png="$temp_file4" 2>&1) + else + # New Inkscape version. + std_output=$(inkscape --export-area-drawing --export-height=$((icon_size * 2)) --export-filename="$temp_file4" -- "$input_file" 2>&1) + fi + _check_output "$?" "$std_output" "$input_file" "$temp_file4" || return 1 + + input_file_proc=$temp_file4 + else + input_file_proc=$input_file + fi + + # Run the process (part 1) 'get information of the image'. + local first_pixel_color="" + first_pixel_color=$(convert "$input_file_proc" -format "%[pixel:p{0,0}]" "info:" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 + + local last_pixel="" + last_pixel=$(identify -format "%[fx:w-1],0" "$input_file_proc" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 + + local last_pixel_color="" + last_pixel_color=$(convert "$input_file_proc" -format "%[pixel:p{$last_pixel}]" "info:") + _check_output "$?" "$std_output" "$input_file" "" || return 1 + + if [[ "$first_pixel_color" == "$last_pixel_color" ]]; then + # Run the process (part 2) 'automatic crop the content'. + std_output=$(convert "$input_file_proc" -trim +repage "$temp_file1" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$temp_file1" || return 1 + + # Run the process (part 3) 'extend to square'. + std_output=$(convert "$temp_file1" -set option:distort:viewport "%[fx:max(w,h)]x%[fx:max(w,h)]+%[fx:(w-max(w,h))/2]+%[fx:(h-max(w,h))/2]" -virtual-pixel transparent -filter point -distort SRT 0 -bordercolor "$first_pixel_color" -border 1 -fill "$first_pixel_color" -draw "color 0,0 floodfill" -shave 1 -draw "color 0,0 floodfill" +repage "$temp_file2" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$temp_file2" || return 1 + + # Run the process (part 4) 'extend 14%' to add a border. + local factor="1.14" + std_output=$(convert "$temp_file2" -set option:distort:viewport "%[fx:(w*$factor)]x%[fx:(h*$factor)]+%[fx:(w-(w*$factor))/2]+%[fx:(h-(h*$factor))/2]" -virtual-pixel transparent -filter point -distort SRT 0 -bordercolor "$first_pixel_color" -border 1 -fill "$first_pixel_color" -draw "color 0,0 floodfill" -shave 1 -draw "color 0,0 floodfill" +repage "$temp_file3" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$temp_file3" || return 1 + + input_file_proc=$temp_file3 + fi + + # Run the process (part 5) 'resize and crop the final image' to add a border. + std_output=$(convert "$input_file_proc" -resize "${icon_size}x${icon_size}^" -gravity center -crop ${icon_size}x${icon_size}+0+0 -strip +repage "$temp_file4" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$temp_file4" || return 1 + + # Move the temporary file to the output. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=png") + _move_temp_file_to_output "$input_file" "$temp_file4" "$output_file" + + # Remove the temporary files on each iteration (if not removed before). + rm -f -- "$temp_file1" + rm -f -- "$temp_file2" + rm -f -- "$temp_file3" + rm -f -- "$temp_file4" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Create icon/Create 'png' icon (256 px) b/.local/share/nautilus/scripts/Image/Create icon/Create 'png' icon (256 px) new file mode 100755 index 0000000..b7b5b8b --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Create icon/Create 'png' icon (256 px) @@ -0,0 +1,112 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + local temp_file1="" + local temp_file2="" + local temp_file3="" + local temp_file4="" + local icon_size="256" + + # Work on a temporary file. + temp_file1="$(_get_temp_file_dry).png" + temp_file2="$(_get_temp_file_dry).png" + temp_file3="$(_get_temp_file_dry).png" + temp_file4="$(_get_temp_file_dry).png" + + # Run the process (part 0) 'export svg'. + local filename_extension="" + local input_file_proc="" + filename_extension=$(_get_filename_extension "$input_file") + if [[ "${filename_extension,,}" == ".svg"* ]]; then + + local inkscape_version="" + local inkscape_version_old="1.0" + inkscape_version=$(inkscape --version | cut -d " " -f 2) + if [[ "$inkscape_version" == $(echo -e "$inkscape_version\n$inkscape_version_old" | sort -V | head -n1) ]]; then + # Old Inkscape version. + std_output=$(inkscape --without-gui --export-area-drawing --file="$input_file" --export-height=$((icon_size * 2)) --export-png="$temp_file4" 2>&1) + else + # New Inkscape version. + std_output=$(inkscape --export-area-drawing --export-height=$((icon_size * 2)) --export-filename="$temp_file4" -- "$input_file" 2>&1) + fi + _check_output "$?" "$std_output" "$input_file" "$temp_file4" || return 1 + + input_file_proc=$temp_file4 + else + input_file_proc=$input_file + fi + + # Run the process (part 1) 'get information of the image'. + local first_pixel_color="" + first_pixel_color=$(convert "$input_file_proc" -format "%[pixel:p{0,0}]" "info:" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 + + local last_pixel="" + last_pixel=$(identify -format "%[fx:w-1],0" "$input_file_proc" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 + + local last_pixel_color="" + last_pixel_color=$(convert "$input_file_proc" -format "%[pixel:p{$last_pixel}]" "info:") + _check_output "$?" "$std_output" "$input_file" "" || return 1 + + if [[ "$first_pixel_color" == "$last_pixel_color" ]]; then + # Run the process (part 2) 'automatic crop the content'. + std_output=$(convert "$input_file_proc" -trim +repage "$temp_file1" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$temp_file1" || return 1 + + # Run the process (part 3) 'extend to square'. + std_output=$(convert "$temp_file1" -set option:distort:viewport "%[fx:max(w,h)]x%[fx:max(w,h)]+%[fx:(w-max(w,h))/2]+%[fx:(h-max(w,h))/2]" -virtual-pixel transparent -filter point -distort SRT 0 -bordercolor "$first_pixel_color" -border 1 -fill "$first_pixel_color" -draw "color 0,0 floodfill" -shave 1 -draw "color 0,0 floodfill" +repage "$temp_file2" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$temp_file2" || return 1 + + # Run the process (part 4) 'extend 14%' to add a border. + local factor="1.14" + std_output=$(convert "$temp_file2" -set option:distort:viewport "%[fx:(w*$factor)]x%[fx:(h*$factor)]+%[fx:(w-(w*$factor))/2]+%[fx:(h-(h*$factor))/2]" -virtual-pixel transparent -filter point -distort SRT 0 -bordercolor "$first_pixel_color" -border 1 -fill "$first_pixel_color" -draw "color 0,0 floodfill" -shave 1 -draw "color 0,0 floodfill" +repage "$temp_file3" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$temp_file3" || return 1 + + input_file_proc=$temp_file3 + fi + + # Run the process (part 5) 'resize and crop the final image' to add a border. + std_output=$(convert "$input_file_proc" -resize "${icon_size}x${icon_size}^" -gravity center -crop ${icon_size}x${icon_size}+0+0 -strip +repage "$temp_file4" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$temp_file4" || return 1 + + # Move the temporary file to the output. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=png") + _move_temp_file_to_output "$input_file" "$temp_file4" "$output_file" + + # Remove the temporary files on each iteration (if not removed before). + rm -f -- "$temp_file1" + rm -f -- "$temp_file2" + rm -f -- "$temp_file3" + rm -f -- "$temp_file4" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Create icon/Create 'png' icon (512 px) b/.local/share/nautilus/scripts/Image/Create icon/Create 'png' icon (512 px) new file mode 100755 index 0000000..13faea2 --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Create icon/Create 'png' icon (512 px) @@ -0,0 +1,112 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + local temp_file1="" + local temp_file2="" + local temp_file3="" + local temp_file4="" + local icon_size="512" + + # Work on a temporary file. + temp_file1="$(_get_temp_file_dry).png" + temp_file2="$(_get_temp_file_dry).png" + temp_file3="$(_get_temp_file_dry).png" + temp_file4="$(_get_temp_file_dry).png" + + # Run the process (part 0) 'export svg'. + local filename_extension="" + local input_file_proc="" + filename_extension=$(_get_filename_extension "$input_file") + if [[ "${filename_extension,,}" == ".svg"* ]]; then + + local inkscape_version="" + local inkscape_version_old="1.0" + inkscape_version=$(inkscape --version | cut -d " " -f 2) + if [[ "$inkscape_version" == $(echo -e "$inkscape_version\n$inkscape_version_old" | sort -V | head -n1) ]]; then + # Old Inkscape version. + std_output=$(inkscape --without-gui --export-area-drawing --file="$input_file" --export-height=$((icon_size * 2)) --export-png="$temp_file4" 2>&1) + else + # New Inkscape version. + std_output=$(inkscape --export-area-drawing --export-height=$((icon_size * 2)) --export-filename="$temp_file4" -- "$input_file" 2>&1) + fi + _check_output "$?" "$std_output" "$input_file" "$temp_file4" || return 1 + + input_file_proc=$temp_file4 + else + input_file_proc=$input_file + fi + + # Run the process (part 1) 'get information of the image'. + local first_pixel_color="" + first_pixel_color=$(convert "$input_file_proc" -format "%[pixel:p{0,0}]" "info:" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 + + local last_pixel="" + last_pixel=$(identify -format "%[fx:w-1],0" "$input_file_proc" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 + + local last_pixel_color="" + last_pixel_color=$(convert "$input_file_proc" -format "%[pixel:p{$last_pixel}]" "info:") + _check_output "$?" "$std_output" "$input_file" "" || return 1 + + if [[ "$first_pixel_color" == "$last_pixel_color" ]]; then + # Run the process (part 2) 'automatic crop the content'. + std_output=$(convert "$input_file_proc" -trim +repage "$temp_file1" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$temp_file1" || return 1 + + # Run the process (part 3) 'extend to square'. + std_output=$(convert "$temp_file1" -set option:distort:viewport "%[fx:max(w,h)]x%[fx:max(w,h)]+%[fx:(w-max(w,h))/2]+%[fx:(h-max(w,h))/2]" -virtual-pixel transparent -filter point -distort SRT 0 -bordercolor "$first_pixel_color" -border 1 -fill "$first_pixel_color" -draw "color 0,0 floodfill" -shave 1 -draw "color 0,0 floodfill" +repage "$temp_file2" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$temp_file2" || return 1 + + # Run the process (part 4) 'extend 14%' to add a border. + local factor="1.14" + std_output=$(convert "$temp_file2" -set option:distort:viewport "%[fx:(w*$factor)]x%[fx:(h*$factor)]+%[fx:(w-(w*$factor))/2]+%[fx:(h-(h*$factor))/2]" -virtual-pixel transparent -filter point -distort SRT 0 -bordercolor "$first_pixel_color" -border 1 -fill "$first_pixel_color" -draw "color 0,0 floodfill" -shave 1 -draw "color 0,0 floodfill" +repage "$temp_file3" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$temp_file3" || return 1 + + input_file_proc=$temp_file3 + fi + + # Run the process (part 5) 'resize and crop the final image' to add a border. + std_output=$(convert "$input_file_proc" -resize "${icon_size}x${icon_size}^" -gravity center -crop ${icon_size}x${icon_size}+0+0 -strip +repage "$temp_file4" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$temp_file4" || return 1 + + # Move the temporary file to the output. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=png") + _move_temp_file_to_output "$input_file" "$temp_file4" "$output_file" + + # Remove the temporary files on each iteration (if not removed before). + rm -f -- "$temp_file1" + rm -f -- "$temp_file2" + rm -f -- "$temp_file3" + rm -f -- "$temp_file4" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Create icon/Create 'png' icon (64 px) b/.local/share/nautilus/scripts/Image/Create icon/Create 'png' icon (64 px) new file mode 100755 index 0000000..2b1fb89 --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Create icon/Create 'png' icon (64 px) @@ -0,0 +1,112 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + local temp_file1="" + local temp_file2="" + local temp_file3="" + local temp_file4="" + local icon_size="64" + + # Work on a temporary file. + temp_file1="$(_get_temp_file_dry).png" + temp_file2="$(_get_temp_file_dry).png" + temp_file3="$(_get_temp_file_dry).png" + temp_file4="$(_get_temp_file_dry).png" + + # Run the process (part 0) 'export svg'. + local filename_extension="" + local input_file_proc="" + filename_extension=$(_get_filename_extension "$input_file") + if [[ "${filename_extension,,}" == ".svg"* ]]; then + + local inkscape_version="" + local inkscape_version_old="1.0" + inkscape_version=$(inkscape --version | cut -d " " -f 2) + if [[ "$inkscape_version" == $(echo -e "$inkscape_version\n$inkscape_version_old" | sort -V | head -n1) ]]; then + # Old Inkscape version. + std_output=$(inkscape --without-gui --export-area-drawing --file="$input_file" --export-height=$((icon_size * 2)) --export-png="$temp_file4" 2>&1) + else + # New Inkscape version. + std_output=$(inkscape --export-area-drawing --export-height=$((icon_size * 2)) --export-filename="$temp_file4" -- "$input_file" 2>&1) + fi + _check_output "$?" "$std_output" "$input_file" "$temp_file4" || return 1 + + input_file_proc=$temp_file4 + else + input_file_proc=$input_file + fi + + # Run the process (part 1) 'get information of the image'. + local first_pixel_color="" + first_pixel_color=$(convert "$input_file_proc" -format "%[pixel:p{0,0}]" "info:" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 + + local last_pixel="" + last_pixel=$(identify -format "%[fx:w-1],0" "$input_file_proc" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 + + local last_pixel_color="" + last_pixel_color=$(convert "$input_file_proc" -format "%[pixel:p{$last_pixel}]" "info:") + _check_output "$?" "$std_output" "$input_file" "" || return 1 + + if [[ "$first_pixel_color" == "$last_pixel_color" ]]; then + # Run the process (part 2) 'automatic crop the content'. + std_output=$(convert "$input_file_proc" -trim +repage "$temp_file1" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$temp_file1" || return 1 + + # Run the process (part 3) 'extend to square'. + std_output=$(convert "$temp_file1" -set option:distort:viewport "%[fx:max(w,h)]x%[fx:max(w,h)]+%[fx:(w-max(w,h))/2]+%[fx:(h-max(w,h))/2]" -virtual-pixel transparent -filter point -distort SRT 0 -bordercolor "$first_pixel_color" -border 1 -fill "$first_pixel_color" -draw "color 0,0 floodfill" -shave 1 -draw "color 0,0 floodfill" +repage "$temp_file2" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$temp_file2" || return 1 + + # Run the process (part 4) 'extend 14%' to add a border. + local factor="1.14" + std_output=$(convert "$temp_file2" -set option:distort:viewport "%[fx:(w*$factor)]x%[fx:(h*$factor)]+%[fx:(w-(w*$factor))/2]+%[fx:(h-(h*$factor))/2]" -virtual-pixel transparent -filter point -distort SRT 0 -bordercolor "$first_pixel_color" -border 1 -fill "$first_pixel_color" -draw "color 0,0 floodfill" -shave 1 -draw "color 0,0 floodfill" +repage "$temp_file3" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$temp_file3" || return 1 + + input_file_proc=$temp_file3 + fi + + # Run the process (part 5) 'resize and crop the final image' to add a border. + std_output=$(convert "$input_file_proc" -resize "${icon_size}x${icon_size}^" -gravity center -crop ${icon_size}x${icon_size}+0+0 -strip +repage "$temp_file4" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$temp_file4" || return 1 + + # Move the temporary file to the output. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=png") + _move_temp_file_to_output "$input_file" "$temp_file4" "$output_file" + + # Remove the temporary files on each iteration (if not removed before). + rm -f -- "$temp_file1" + rm -f -- "$temp_file2" + rm -f -- "$temp_file3" + rm -f -- "$temp_file4" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Crop, resize/Automatic crop b/.local/share/nautilus/scripts/Image/Crop, resize/Automatic crop new file mode 100755 index 0000000..a2067fe --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Crop, resize/Automatic crop @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(convert "$input_file" -trim +repage "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Crop, resize/Automatic crop (15 pct) b/.local/share/nautilus/scripts/Image/Crop, resize/Automatic crop (15 pct) new file mode 100755 index 0000000..c47cc3f --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Crop, resize/Automatic crop (15 pct) @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(convert "$input_file" -fuzz 15% -trim +repage "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Crop, resize/Resize (25 pct) b/.local/share/nautilus/scripts/Image/Crop, resize/Resize (25 pct) new file mode 100755 index 0000000..ff43815 --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Crop, resize/Resize (25 pct) @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(convert "$input_file" -resize 25%x25% +repage "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Crop, resize/Resize (50 pct) b/.local/share/nautilus/scripts/Image/Crop, resize/Resize (50 pct) new file mode 100755 index 0000000..d8a47d8 --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Crop, resize/Resize (50 pct) @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(convert "$input_file" -resize 50%x50% +repage "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Crop, resize/Resize (75 pct) b/.local/share/nautilus/scripts/Image/Crop, resize/Resize (75 pct) new file mode 100755 index 0000000..d075995 --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Crop, resize/Resize (75 pct) @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(convert "$input_file" -resize 75%x75% +repage "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Crop, resize/Resize and crop (1920x1080) b/.local/share/nautilus/scripts/Image/Crop, resize/Resize and crop (1920x1080) new file mode 100755 index 0000000..41a7df3 --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Crop, resize/Resize and crop (1920x1080) @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(convert "$input_file" -resize "1920x1080^" -gravity center -crop 1920x1080+0+0 -strip +repage "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Flip, rotate/Flip (horizontally) b/.local/share/nautilus/scripts/Image/Flip, rotate/Flip (horizontally) new file mode 100755 index 0000000..382776f --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Flip, rotate/Flip (horizontally) @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(convert "$input_file" -transparent none -flop "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Flip, rotate/Flip (vertically) b/.local/share/nautilus/scripts/Image/Flip, rotate/Flip (vertically) new file mode 100755 index 0000000..0bb96c3 --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Flip, rotate/Flip (vertically) @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(convert "$input_file" -transparent none -flip "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Flip, rotate/Rotate (180 deg) b/.local/share/nautilus/scripts/Image/Flip, rotate/Rotate (180 deg) new file mode 100755 index 0000000..fdcf59c --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Flip, rotate/Rotate (180 deg) @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(convert "$input_file" -transparent none -rotate 180 +repage "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Flip, rotate/Rotate (270 deg) b/.local/share/nautilus/scripts/Image/Flip, rotate/Rotate (270 deg) new file mode 100755 index 0000000..c836226 --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Flip, rotate/Rotate (270 deg) @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(convert "$input_file" -transparent none -rotate 270 +repage "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Flip, rotate/Rotate (90 deg) b/.local/share/nautilus/scripts/Image/Flip, rotate/Rotate (90 deg) new file mode 100755 index 0000000..ac93088 --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Flip, rotate/Rotate (90 deg) @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(convert "$input_file" -transparent none -rotate 90 +repage "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Image similarity/Similarity (65 pct) b/.local/share/nautilus/scripts/Image/Image similarity/Similarity (65 pct) new file mode 100755 index 0000000..29b9e26 --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Image similarity/Similarity (65 pct) @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + + # Execute initial checks. + _check_dependencies "command=findimagedupes | command=xdg-open; package=xdg-utils" + _display_wait_box "0" + input_files=$(_get_files "par_type=file; par_recursive=true; par_select_mime=image/") + + # Get the installed image viewer. + local image_viewer="" + image_viewer=$(_xdg_get_default_app "image/jpeg") + + # Run the main process. + # shellcheck disable=SC2086 + findimagedupes --recurse --threshold=65% --program="$(which "$image_viewer")" -- $input_files 2>/dev/null + _display_result_box "" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Image similarity/Similarity (75 pct) b/.local/share/nautilus/scripts/Image/Image similarity/Similarity (75 pct) new file mode 100755 index 0000000..f5adb14 --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Image similarity/Similarity (75 pct) @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + + # Execute initial checks. + _check_dependencies "command=findimagedupes | command=xdg-open; package=xdg-utils" + _display_wait_box "0" + input_files=$(_get_files "par_type=file; par_recursive=true; par_select_mime=image/") + + # Get the installed image viewer. + local image_viewer="" + image_viewer=$(_xdg_get_default_app "image/jpeg") + + # Run the main process. + # shellcheck disable=SC2086 + findimagedupes --recurse --threshold=75% --program="$(which "$image_viewer")" -- $input_files 2>/dev/null + _display_result_box "" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Image similarity/Similarity (85 pct) b/.local/share/nautilus/scripts/Image/Image similarity/Similarity (85 pct) new file mode 100755 index 0000000..73fc988 --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Image similarity/Similarity (85 pct) @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + + # Execute initial checks. + _check_dependencies "command=findimagedupes | command=xdg-open; package=xdg-utils" + _display_wait_box "0" + input_files=$(_get_files "par_type=file; par_recursive=true; par_select_mime=image/") + + # Get the installed image viewer. + local image_viewer="" + image_viewer=$(_xdg_get_default_app "image/jpeg") + + # Run the main process. + # shellcheck disable=SC2086 + findimagedupes --recurse --threshold=85% --program="$(which "$image_viewer")" -- $input_files 2>/dev/null + _display_result_box "" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Image similarity/Similarity (95 pct) b/.local/share/nautilus/scripts/Image/Image similarity/Similarity (95 pct) new file mode 100755 index 0000000..ecdc6a2 --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Image similarity/Similarity (95 pct) @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + + # Execute initial checks. + _check_dependencies "command=findimagedupes | command=xdg-open; package=xdg-utils" + _display_wait_box "0" + input_files=$(_get_files "par_type=file; par_recursive=true; par_select_mime=image/") + + # Get the installed image viewer. + local image_viewer="" + image_viewer=$(_xdg_get_default_app "image/jpeg") + + # Run the main process. + # shellcheck disable=SC2086 + findimagedupes --recurse --threshold=95% --program="$(which "$image_viewer")" -- $input_files 2>/dev/null + _display_result_box "" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Optimize/Optimize 'jpg' (strip metadata) b/.local/share/nautilus/scripts/Image/Optimize/Optimize 'jpg' (strip metadata) new file mode 100755 index 0000000..b7cad57 --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Optimize/Optimize 'jpg' (strip metadata) @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=jpegoptim" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(jpegoptim --strip-all --dest="$output_dir" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Optimize/Optimize 'png' b/.local/share/nautilus/scripts/Image/Optimize/Optimize 'png' new file mode 100755 index 0000000..df18cdf --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Optimize/Optimize 'png' @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=optipng" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(optipng -out "$output_file" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Text recognition (OCR)/Image OCR (in English) b/.local/share/nautilus/scripts/Image/Text recognition (OCR)/Image OCR (in English) new file mode 100755 index 0000000..e0ce28f --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Text recognition (OCR)/Image OCR (in English) @@ -0,0 +1,50 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + TEMP_DATA_TASK="eng" + _check_dependencies " + pkg_manager=apt; package=tesseract-ocr-$TEMP_DATA_TASK | + pkg_manager=dnf; package=tesseract-langpack-$TEMP_DATA_TASK | + pkg_manager=pacman; package=tesseract-data-$TEMP_DATA_TASK | + pkg_manager=zypper; package=tesseract-ocr-traineddata-$TEMP_DATA_TASK" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/; par_validate_conflict=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + local temp_file="" + + # Work on a temporary file. + temp_file=$(_get_temp_file) + + # Run the main process. + std_output=$(tesseract "$input_file" "$temp_file" -l "$TEMP_DATA_TASK" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$temp_file.txt" || return 1 + + # Move the temporary file to the output. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=txt") + _move_temp_file_to_output "$input_file" "$temp_file.txt" "$output_file" + + # Remove the temporary files on each iteration (if not removed before). + rm -f -- "$temp_file" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Text recognition (OCR)/Image OCR (in French) b/.local/share/nautilus/scripts/Image/Text recognition (OCR)/Image OCR (in French) new file mode 100755 index 0000000..34cf82e --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Text recognition (OCR)/Image OCR (in French) @@ -0,0 +1,50 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + TEMP_DATA_TASK="fra" + _check_dependencies " + pkg_manager=apt; package=tesseract-ocr-$TEMP_DATA_TASK | + pkg_manager=dnf; package=tesseract-langpack-$TEMP_DATA_TASK | + pkg_manager=pacman; package=tesseract-data-$TEMP_DATA_TASK | + pkg_manager=zypper; package=tesseract-ocr-traineddata-$TEMP_DATA_TASK" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/; par_validate_conflict=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + local temp_file="" + + # Work on a temporary file. + temp_file=$(_get_temp_file) + + # Run the main process. + std_output=$(tesseract "$input_file" "$temp_file" -l "$TEMP_DATA_TASK" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$temp_file.txt" || return 1 + + # Move the temporary file to the output. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=txt") + _move_temp_file_to_output "$input_file" "$temp_file.txt" "$output_file" + + # Remove the temporary files on each iteration (if not removed before). + rm -f -- "$temp_file" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Text recognition (OCR)/Image OCR (in German) b/.local/share/nautilus/scripts/Image/Text recognition (OCR)/Image OCR (in German) new file mode 100755 index 0000000..481ffbf --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Text recognition (OCR)/Image OCR (in German) @@ -0,0 +1,50 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + TEMP_DATA_TASK="deu" + _check_dependencies " + pkg_manager=apt; package=tesseract-ocr-$TEMP_DATA_TASK | + pkg_manager=dnf; package=tesseract-langpack-$TEMP_DATA_TASK | + pkg_manager=pacman; package=tesseract-data-$TEMP_DATA_TASK | + pkg_manager=zypper; package=tesseract-ocr-traineddata-$TEMP_DATA_TASK" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/; par_validate_conflict=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + local temp_file="" + + # Work on a temporary file. + temp_file=$(_get_temp_file) + + # Run the main process. + std_output=$(tesseract "$input_file" "$temp_file" -l "$TEMP_DATA_TASK" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$temp_file.txt" || return 1 + + # Move the temporary file to the output. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=txt") + _move_temp_file_to_output "$input_file" "$temp_file.txt" "$output_file" + + # Remove the temporary files on each iteration (if not removed before). + rm -f -- "$temp_file" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Text recognition (OCR)/Image OCR (in Italian) b/.local/share/nautilus/scripts/Image/Text recognition (OCR)/Image OCR (in Italian) new file mode 100755 index 0000000..b6c09a6 --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Text recognition (OCR)/Image OCR (in Italian) @@ -0,0 +1,50 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + TEMP_DATA_TASK="ita" + _check_dependencies " + pkg_manager=apt; package=tesseract-ocr-$TEMP_DATA_TASK | + pkg_manager=dnf; package=tesseract-langpack-$TEMP_DATA_TASK | + pkg_manager=pacman; package=tesseract-data-$TEMP_DATA_TASK | + pkg_manager=zypper; package=tesseract-ocr-traineddata-$TEMP_DATA_TASK" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/; par_validate_conflict=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + local temp_file="" + + # Work on a temporary file. + temp_file=$(_get_temp_file) + + # Run the main process. + std_output=$(tesseract "$input_file" "$temp_file" -l "$TEMP_DATA_TASK" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$temp_file.txt" || return 1 + + # Move the temporary file to the output. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=txt") + _move_temp_file_to_output "$input_file" "$temp_file.txt" "$output_file" + + # Remove the temporary files on each iteration (if not removed before). + rm -f -- "$temp_file" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Text recognition (OCR)/Image OCR (in Portuguese) b/.local/share/nautilus/scripts/Image/Text recognition (OCR)/Image OCR (in Portuguese) new file mode 100755 index 0000000..380c388 --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Text recognition (OCR)/Image OCR (in Portuguese) @@ -0,0 +1,50 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + TEMP_DATA_TASK="por" + _check_dependencies " + pkg_manager=apt; package=tesseract-ocr-$TEMP_DATA_TASK | + pkg_manager=dnf; package=tesseract-langpack-$TEMP_DATA_TASK | + pkg_manager=pacman; package=tesseract-data-$TEMP_DATA_TASK | + pkg_manager=zypper; package=tesseract-ocr-traineddata-$TEMP_DATA_TASK" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/; par_validate_conflict=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + local temp_file="" + + # Work on a temporary file. + temp_file=$(_get_temp_file) + + # Run the main process. + std_output=$(tesseract "$input_file" "$temp_file" -l "$TEMP_DATA_TASK" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$temp_file.txt" || return 1 + + # Move the temporary file to the output. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=txt") + _move_temp_file_to_output "$input_file" "$temp_file.txt" "$output_file" + + # Remove the temporary files on each iteration (if not removed before). + rm -f -- "$temp_file" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Text recognition (OCR)/Image OCR (in Russian) b/.local/share/nautilus/scripts/Image/Text recognition (OCR)/Image OCR (in Russian) new file mode 100755 index 0000000..a38ab1f --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Text recognition (OCR)/Image OCR (in Russian) @@ -0,0 +1,50 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + TEMP_DATA_TASK="rus" + _check_dependencies " + pkg_manager=apt; package=tesseract-ocr-$TEMP_DATA_TASK | + pkg_manager=dnf; package=tesseract-langpack-$TEMP_DATA_TASK | + pkg_manager=pacman; package=tesseract-data-$TEMP_DATA_TASK | + pkg_manager=zypper; package=tesseract-ocr-traineddata-$TEMP_DATA_TASK" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/; par_validate_conflict=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + local temp_file="" + + # Work on a temporary file. + temp_file=$(_get_temp_file) + + # Run the main process. + std_output=$(tesseract "$input_file" "$temp_file" -l "$TEMP_DATA_TASK" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$temp_file.txt" || return 1 + + # Move the temporary file to the output. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=txt") + _move_temp_file_to_output "$input_file" "$temp_file.txt" "$output_file" + + # Remove the temporary files on each iteration (if not removed before). + rm -f -- "$temp_file" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Text recognition (OCR)/Image OCR (in Spanish) b/.local/share/nautilus/scripts/Image/Text recognition (OCR)/Image OCR (in Spanish) new file mode 100755 index 0000000..ec62c0d --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Text recognition (OCR)/Image OCR (in Spanish) @@ -0,0 +1,50 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + TEMP_DATA_TASK="spa" + _check_dependencies " + pkg_manager=apt; package=tesseract-ocr-$TEMP_DATA_TASK | + pkg_manager=dnf; package=tesseract-langpack-$TEMP_DATA_TASK | + pkg_manager=pacman; package=tesseract-data-$TEMP_DATA_TASK | + pkg_manager=zypper; package=tesseract-ocr-traineddata-$TEMP_DATA_TASK" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/; par_validate_conflict=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + local temp_file="" + + # Work on a temporary file. + temp_file=$(_get_temp_file) + + # Run the main process. + std_output=$(tesseract "$input_file" "$temp_file" -l "$TEMP_DATA_TASK" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$temp_file.txt" || return 1 + + # Move the temporary file to the output. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=txt") + _move_temp_file_to_output "$input_file" "$temp_file.txt" "$output_file" + + # Remove the temporary files on each iteration (if not removed before). + rm -f -- "$temp_file" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Transparency/Alpha to black b/.local/share/nautilus/scripts/Image/Transparency/Alpha to black new file mode 100755 index 0000000..77c18b1 --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Transparency/Alpha to black @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(convert "$input_file" -background black -layers flatten "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Transparency/Alpha to magenta b/.local/share/nautilus/scripts/Image/Transparency/Alpha to magenta new file mode 100755 index 0000000..fec5e43 --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Transparency/Alpha to magenta @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(convert "$input_file" -background magenta -layers flatten "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Transparency/Alpha to white b/.local/share/nautilus/scripts/Image/Transparency/Alpha to white new file mode 100755 index 0000000..58f024a --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Transparency/Alpha to white @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(convert "$input_file" -background white -layers flatten "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Transparency/Background to alpha b/.local/share/nautilus/scripts/Image/Transparency/Background to alpha new file mode 100755 index 0000000..da3fc56 --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Transparency/Background to alpha @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/; par_validate_conflict=true") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + local first_pixel_color="" + first_pixel_color=$(convert "$input_file""[1x1+0+0]" -format "%[pixel:p{0,0}]" "info:") + _check_output "$?" "$std_output" "$input_file" "" || return 1 + + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=png") + std_output=$(convert "$input_file" -alpha off -bordercolor "$first_pixel_color" -border 1 \( +clone -fill none -floodfill +0+0 "$first_pixel_color" -alpha extract -geometry 200% -blur 0x0.5 -morphology erode square:1 -geometry 50% \) -compose CopyOpacity -composite -shave 1 "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Transparency/Background to alpha (15 pct) b/.local/share/nautilus/scripts/Image/Transparency/Background to alpha (15 pct) new file mode 100755 index 0000000..0fbb7b6 --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Transparency/Background to alpha (15 pct) @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/; par_validate_conflict=true") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + local first_pixel_color="" + first_pixel_color=$(convert "$input_file""[1x1+0+0]" -format "%[pixel:p{0,0}]" "info:") + _check_output "$?" "$std_output" "$input_file" "" || return 1 + + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=png") + std_output=$(convert "$input_file" -alpha off -bordercolor "$first_pixel_color" -border 1 \( +clone -fuzz 15% -fill none -floodfill +0+0 "$first_pixel_color" -alpha extract -geometry 200% -blur 0x0.5 -morphology erode square:1 -geometry 50% \) -compose CopyOpacity -composite -shave 1 "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Transparency/Black to alpha b/.local/share/nautilus/scripts/Image/Transparency/Black to alpha new file mode 100755 index 0000000..e87d759 --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Transparency/Black to alpha @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/; par_validate_conflict=true") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=png") + std_output=$(convert "$input_file" -transparent black "$output_file" 2>&1) + _check_result "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Transparency/Black to alpha (15 pct) b/.local/share/nautilus/scripts/Image/Transparency/Black to alpha (15 pct) new file mode 100755 index 0000000..d0195db --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Transparency/Black to alpha (15 pct) @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/; par_validate_conflict=true") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=png") + std_output=$(convert "$input_file" -fuzz 10% -transparent black "$output_file" 2>&1) + _check_result "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Transparency/Magenta to alpha b/.local/share/nautilus/scripts/Image/Transparency/Magenta to alpha new file mode 100755 index 0000000..e232ac4 --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Transparency/Magenta to alpha @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/; par_validate_conflict=true") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=png") + std_output=$(convert "$input_file" -transparent magenta "$output_file" 2>&1) + _check_result "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Transparency/Magenta to alpha (15 pct) b/.local/share/nautilus/scripts/Image/Transparency/Magenta to alpha (15 pct) new file mode 100755 index 0000000..2904700 --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Transparency/Magenta to alpha (15 pct) @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/; par_validate_conflict=true") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=png") + std_output=$(convert "$input_file" -fuzz 10% -transparent magenta "$output_file" 2>&1) + _check_result "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Transparency/White to alpha b/.local/share/nautilus/scripts/Image/Transparency/White to alpha new file mode 100755 index 0000000..336fdbc --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Transparency/White to alpha @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/; par_validate_conflict=true") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=png") + std_output=$(convert "$input_file" -transparent white "$output_file" 2>&1) + _check_result "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Image/Transparency/White to alpha (15 pct) b/.local/share/nautilus/scripts/Image/Transparency/White to alpha (15 pct) new file mode 100755 index 0000000..4d50ea0 --- /dev/null +++ b/.local/share/nautilus/scripts/Image/Transparency/White to alpha (15 pct) @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=convert; pkg_manager=apt; package=imagemagick | + command=convert; pkg_manager=dnf; package=ImageMagick | + command=convert; pkg_manager=pacman; package=imagemagick | + command=convert; pkg_manager=zypper; package=ImageMagick" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=image/; par_validate_conflict=true") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=png") + std_output=$(convert "$input_file" -fuzz 10% -transparent white "$output_file" 2>&1) + _check_result "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Misc/Download (URLs in clipboard) b/.local/share/nautilus/scripts/Misc/Download (URLs in clipboard) new file mode 100755 index 0000000..76622ea --- /dev/null +++ b/.local/share/nautilus/scripts/Misc/Download (URLs in clipboard) @@ -0,0 +1,103 @@ +#!/usr/bin/env bash +# install_keyboard_shortcut=X + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local output_dir="" + + # Execute initial checks. + case "${XDG_SESSION_TYPE,,}" in + "x11") _check_dependencies "command=axel | command=xclip" ;; + "wayland") _check_dependencies "command=axel | command=wl-paste; package=wl-clipboard" ;; + *) + _display_error_box "Unknown session type!" + _exit_script + ;; + esac + + _display_wait_box "2" + output_dir=$(_get_working_directory_alternative) + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$(_get_urls_from_clipboard)" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + + # Run the main process. + std_output=$(axel --ipv4 --insecure --num-connections=10 --timeout=5 --output="$output_dir" -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_dir" || return 1 +} + +_get_urls_from_clipboard() { + local urls="" + + if [[ "${XDG_SESSION_TYPE,,}" == "x11" ]]; then + urls=$(xclip -quiet -selection clipboard -o) + elif [[ "${XDG_SESSION_TYPE,,}" == "wayland" ]]; then + urls=$(wl-paste) + fi + urls=$(grep --only-matching --perl-regexp "https?://\w+\.[^ '\"]+" <<<"$urls") + urls=$(sort -u <<<"$urls") + + if [[ -z "$urls" ]]; then + _display_error_box "There are no valid URLs in the clipboard!" + _exit_script + fi + + _convert_text_to_filenames "$urls" +} + +_get_working_directory_alternative() { + local working_directory="" + + # Try to use the information provided by the file manager. + if [[ -v "CAJA_SCRIPT_CURRENT_URI" ]]; then + working_directory=$CAJA_SCRIPT_CURRENT_URI + elif [[ -v "NEMO_SCRIPT_CURRENT_URI" ]]; then + working_directory=$NEMO_SCRIPT_CURRENT_URI + elif [[ -v "NAUTILUS_SCRIPT_CURRENT_URI" ]]; then + working_directory=$NAUTILUS_SCRIPT_CURRENT_URI + fi + + if [[ -n "$working_directory" ]] && [[ "$working_directory" == "file://"* ]]; then + working_directory=$(_text_uri_decode "$working_directory") + else + # Files selected in the search screen (or orther possible cases). + working_directory="" + fi + + if [[ -z "$working_directory" ]]; then + # NOTE: The working directory can be detected by using the directory name + # of the first input file. Some file managers do not send the working + # directory for the scripts, so it is not precise to use the 'pwd' command. + local item_1="" + local item_2="" + item_1=$(cut -d "$FIELD_SEPARATOR" -f 1 <<<"$INPUT_FILES") + item_2=$(cut -d "$FIELD_SEPARATOR" -f 2 <<<"$INPUT_FILES") + + if [[ -n "$item_1" ]]; then + if [[ -n "$item_2" ]] && [[ "$item_1" != "$item_2" ]]; then + working_directory=$(_get_filename_dir "$item_1") + elif [[ -f "$item_1" ]]; then + working_directory=$(_get_filename_dir "$item_1") + elif [[ -d "$item_1" ]]; then + working_directory=$(_get_filename_full_path "$item_1") + fi + else + working_directory=$(pwd) + fi + fi + + printf "%s" "$working_directory" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Misc/Git clone (URLs in clipboard) b/.local/share/nautilus/scripts/Misc/Git clone (URLs in clipboard) new file mode 100755 index 0000000..06284d6 --- /dev/null +++ b/.local/share/nautilus/scripts/Misc/Git clone (URLs in clipboard) @@ -0,0 +1,105 @@ +#!/usr/bin/env bash +# install_keyboard_shortcut=G + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local output_dir="" + + # Execute initial checks. + case "${XDG_SESSION_TYPE,,}" in + "x11") _check_dependencies "command=git | command=xclip" ;; + "wayland") _check_dependencies "command=git | command=wl-paste; package=wl-clipboard" ;; + *) + _display_error_box "Unknown session type!" + _exit_script + ;; + esac + + _display_wait_box "2" + output_dir=$(_get_working_directory_alternative) + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$(_get_urls_from_clipboard)" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + + cd "$output_dir" || return 1 + + # Run the main process. + std_output=$(git clone -q -- "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 +} + +_get_urls_from_clipboard() { + local urls="" + + if [[ "${XDG_SESSION_TYPE,,}" == "x11" ]]; then + urls=$(xclip -quiet -selection clipboard -o) + elif [[ "${XDG_SESSION_TYPE,,}" == "wayland" ]]; then + urls=$(wl-paste) + fi + urls=$(grep --only-matching --perl-regexp "((git|ssh|http(s)?)|(git@[\w\.]+))(.*)(\.git)" <<<"$urls") + urls=$(sort -u <<<"$urls") + + if [[ -z "$urls" ]]; then + _display_error_box "There are no valid Git URLs in the clipboard!" + _exit_script + fi + + _convert_text_to_filenames "$urls" +} + +_get_working_directory_alternative() { + local working_directory="" + + # Try to use the information provided by the file manager. + if [[ -v "CAJA_SCRIPT_CURRENT_URI" ]]; then + working_directory=$CAJA_SCRIPT_CURRENT_URI + elif [[ -v "NEMO_SCRIPT_CURRENT_URI" ]]; then + working_directory=$NEMO_SCRIPT_CURRENT_URI + elif [[ -v "NAUTILUS_SCRIPT_CURRENT_URI" ]]; then + working_directory=$NAUTILUS_SCRIPT_CURRENT_URI + fi + + if [[ -n "$working_directory" ]] && [[ "$working_directory" == "file://"* ]]; then + working_directory=$(_text_uri_decode "$working_directory") + else + # Files selected in the search screen (or orther possible cases). + working_directory="" + fi + + if [[ -z "$working_directory" ]]; then + # NOTE: The working directory can be detected by using the directory name + # of the first input file. Some file managers do not send the working + # directory for the scripts, so it is not precise to use the 'pwd' command. + local item_1="" + local item_2="" + item_1=$(cut -d "$FIELD_SEPARATOR" -f 1 <<<"$INPUT_FILES") + item_2=$(cut -d "$FIELD_SEPARATOR" -f 2 <<<"$INPUT_FILES") + + if [[ -n "$item_1" ]]; then + if [[ -n "$item_2" ]] && [[ "$item_1" != "$item_2" ]]; then + working_directory=$(_get_filename_dir "$item_1") + elif [[ -f "$item_1" ]]; then + working_directory=$(_get_filename_dir "$item_1") + elif [[ -d "$item_1" ]]; then + working_directory=$(_get_filename_full_path "$item_1") + fi + else + working_directory=$(pwd) + fi + fi + + printf "%s" "$working_directory" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Misc/Paste as hard link b/.local/share/nautilus/scripts/Misc/Paste as hard link new file mode 100755 index 0000000..a418e0a --- /dev/null +++ b/.local/share/nautilus/scripts/Misc/Paste as hard link @@ -0,0 +1,114 @@ +#!/usr/bin/env bash +# install_keyboard_shortcut=V + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local output_dir="" + + # Execute initial checks. + case "${XDG_SESSION_TYPE,,}" in + "x11") _check_dependencies "command=xclip" ;; + "wayland") _check_dependencies "command=wl-paste; package=wl-clipboard" ;; + *) + _display_error_box "Unknown session type!" + _exit_script + ;; + esac + + _display_wait_box "2" + output_dir=$(_get_working_directory_alternative) + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$(_get_urls_from_clipboard)" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + + cd "$output_dir" || return 1 + + if ! [[ -e "$input_file" ]]; then + return 1 + fi + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(cp -Ral -- "$input_file" "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_get_urls_from_clipboard() { + local urls="" + + if [[ "${XDG_SESSION_TYPE,,}" == "x11" ]]; then + urls=$(xclip -quiet -selection clipboard -o) + elif [[ "${XDG_SESSION_TYPE,,}" == "wayland" ]]; then + urls=$(wl-paste) + fi + urls=$(grep --only-matching --perl-regexp "^(file://|('\")?/)(.*)" <<<"$urls") + urls=$(sed "s|^['\"]||g; s|['\"]$||g" <<<"$urls") + urls=$(sort -u <<<"$urls") + + if [[ -z "$urls" ]]; then + _display_error_box "There are no valid paths in the clipboard!" + _exit_script + fi + + urls=$(_convert_text_to_filenames "$urls") + urls=$(_text_uri_decode "$urls") + + printf "%s" "$urls" +} + +_get_working_directory_alternative() { + local working_directory="" + + # Try to use the information provided by the file manager. + if [[ -v "CAJA_SCRIPT_CURRENT_URI" ]]; then + working_directory=$CAJA_SCRIPT_CURRENT_URI + elif [[ -v "NEMO_SCRIPT_CURRENT_URI" ]]; then + working_directory=$NEMO_SCRIPT_CURRENT_URI + elif [[ -v "NAUTILUS_SCRIPT_CURRENT_URI" ]]; then + working_directory=$NAUTILUS_SCRIPT_CURRENT_URI + fi + + if [[ -n "$working_directory" ]] && [[ "$working_directory" == "file://"* ]]; then + working_directory=$(_text_uri_decode "$working_directory") + else + # Files selected in the search screen (or orther possible cases). + working_directory="" + fi + + if [[ -z "$working_directory" ]]; then + # NOTE: The working directory can be detected by using the directory name + # of the first input file. Some file managers do not send the working + # directory for the scripts, so it is not precise to use the 'pwd' command. + local item_1="" + local item_2="" + item_1=$(cut -d "$FIELD_SEPARATOR" -f 1 <<<"$INPUT_FILES") + item_2=$(cut -d "$FIELD_SEPARATOR" -f 2 <<<"$INPUT_FILES") + + if [[ -n "$item_1" ]]; then + if [[ -n "$item_2" ]] && [[ "$item_1" != "$item_2" ]]; then + working_directory=$(_get_filename_dir "$item_1") + elif [[ -f "$item_1" ]]; then + working_directory=$(_get_filename_dir "$item_1") + elif [[ -d "$item_1" ]]; then + working_directory=$(_get_filename_full_path "$item_1") + fi + else + working_directory=$(pwd) + fi + fi + + printf "%s" "$working_directory" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Misc/Paste as symbolic link b/.local/share/nautilus/scripts/Misc/Paste as symbolic link new file mode 100755 index 0000000..d5739ef --- /dev/null +++ b/.local/share/nautilus/scripts/Misc/Paste as symbolic link @@ -0,0 +1,113 @@ +#!/usr/bin/env bash +# install_keyboard_shortcut=V + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local output_dir="" + + # Execute initial checks. + case "${XDG_SESSION_TYPE,,}" in + "x11") _check_dependencies "command=xclip" ;; + "wayland") _check_dependencies "command=wl-paste; package=wl-clipboard" ;; + *) + _display_error_box "Unknown session type!" + _exit_script + ;; + esac + + _display_wait_box "2" + output_dir=$(_get_working_directory_alternative) + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$(_get_urls_from_clipboard)" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + + cd "$output_dir" || return 1 + + if ! [[ -e "$input_file" ]]; then + return 1 + fi + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(ln -s -- "$input_file" "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_get_urls_from_clipboard() { + local urls="" + + if [[ "${XDG_SESSION_TYPE,,}" == "x11" ]]; then + urls=$(xclip -quiet -selection clipboard -o) + elif [[ "${XDG_SESSION_TYPE,,}" == "wayland" ]]; then + urls=$(wl-paste) + fi + urls=$(grep --only-matching --perl-regexp "^(file://|('\")?/)(.*)" <<<"$urls") + urls=$(sed "s|^['\"]||g; s|['\"]$||g" <<<"$urls") + urls=$(sort -u <<<"$urls") + + if [[ -z "$urls" ]]; then + _display_error_box "There are no valid paths in the clipboard!" + _exit_script + fi + + urls=$(_convert_text_to_filenames "$urls") + urls=$(_text_uri_decode "$urls") + printf "%s" "$urls" +} + +_get_working_directory_alternative() { + local working_directory="" + + # Try to use the information provided by the file manager. + if [[ -v "CAJA_SCRIPT_CURRENT_URI" ]]; then + working_directory=$CAJA_SCRIPT_CURRENT_URI + elif [[ -v "NEMO_SCRIPT_CURRENT_URI" ]]; then + working_directory=$NEMO_SCRIPT_CURRENT_URI + elif [[ -v "NAUTILUS_SCRIPT_CURRENT_URI" ]]; then + working_directory=$NAUTILUS_SCRIPT_CURRENT_URI + fi + + if [[ -n "$working_directory" ]] && [[ "$working_directory" == "file://"* ]]; then + working_directory=$(_text_uri_decode "$working_directory") + else + # Files selected in the search screen (or orther possible cases). + working_directory="" + fi + + if [[ -z "$working_directory" ]]; then + # NOTE: The working directory can be detected by using the directory name + # of the first input file. Some file managers do not send the working + # directory for the scripts, so it is not precise to use the 'pwd' command. + local item_1="" + local item_2="" + item_1=$(cut -d "$FIELD_SEPARATOR" -f 1 <<<"$INPUT_FILES") + item_2=$(cut -d "$FIELD_SEPARATOR" -f 2 <<<"$INPUT_FILES") + + if [[ -n "$item_1" ]]; then + if [[ -n "$item_2" ]] && [[ "$item_1" != "$item_2" ]]; then + working_directory=$(_get_filename_dir "$item_1") + elif [[ -f "$item_1" ]]; then + working_directory=$(_get_filename_dir "$item_1") + elif [[ -d "$item_1" ]]; then + working_directory=$(_get_filename_full_path "$item_1") + fi + else + working_directory=$(pwd) + fi + fi + + printf "%s" "$working_directory" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Misc/Print documents b/.local/share/nautilus/scripts/Misc/Print documents new file mode 100755 index 0000000..d0b0ec2 --- /dev/null +++ b/.local/share/nautilus/scripts/Misc/Print documents @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=lp; package=cups-client" + _display_wait_box "2" + input_files=$(_get_files "par_type=file") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + + # Run the main process. + std_output=$(lp "$input_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Open with/Code Editor b/.local/share/nautilus/scripts/Open with/Code Editor new file mode 100755 index 0000000..6965e8a --- /dev/null +++ b/.local/share/nautilus/scripts/Open with/Code Editor @@ -0,0 +1,48 @@ +#!/usr/bin/env bash +# shellcheck disable=SC2086 +# install_keyboard_shortcut=F3 + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + + # Execute initial checks. + _check_dependencies "" + input_files=$(_get_files "par_type=all; par_max_items=20; par_get_pwd=true") + _unset_global_variables_file_manager + + # Check if the first file is a binary file. + local file_1="" + file_1=$(cut -d "$FIELD_SEPARATOR" -f 1 <<<"$input_files") + if ! [[ -d "$file_1" ]]; then + if [[ "$(_get_file_encoding "$file_1")" == "binary" ]] && [[ -s "$file_1" ]]; then + case "${XDG_CURRENT_DESKTOP,,}" in + *"kde"* | *"lxqt"*) + _check_dependencies "command=okteta" + okteta -- $input_files & + ;; + *) + _check_dependencies "command=ghex" + ghex -- $input_files & + ;; + esac + exit 0 + fi + fi + + # Run the main process. + if _command_exists "code"; then + code -- $input_files & + elif _command_exists "geany"; then + geany -- $input_files & + else + _check_dependencies "command=xdg-open; package=xdg-utils" + $(_xdg_get_default_app "text/plain") -- $input_files & + fi +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Open with/Disk Usage Analyzer b/.local/share/nautilus/scripts/Open with/Disk Usage Analyzer new file mode 100755 index 0000000..93d52b9 --- /dev/null +++ b/.local/share/nautilus/scripts/Open with/Disk Usage Analyzer @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +# install_keyboard_shortcut=F7 + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + + # Execute initial checks. + case "${XDG_CURRENT_DESKTOP,,}" in + *"kde"* | *"lxqt"*) + _check_dependencies "command=filelight" + ;; + *) + _check_dependencies "command=baobab" + ;; + esac + input_files=$(_get_files "par_type=directory; par_max_items=20; par_get_pwd=true") + _unset_global_variables_file_manager + + _open_app "$input_files" +} + +_open_app() { + local input_files=$1 + local input_file="" + + for input_file in $input_files; do + # Run the main process. + if _command_exists "baobab"; then + baobab -- "$input_file" & + elif _command_exists "filelight"; then + filelight -- "$input_file" & + fi + done +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Open with/Terminal b/.local/share/nautilus/scripts/Open with/Terminal new file mode 100755 index 0000000..30cf364 --- /dev/null +++ b/.local/share/nautilus/scripts/Open with/Terminal @@ -0,0 +1,59 @@ +#!/usr/bin/env bash +# install_keyboard_shortcut=F4 + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + + # Execute initial checks. + _check_dependencies "" + input_files=$(_get_files "par_type=directory; par_max_items=20; par_get_pwd=true") + _unset_global_variables_file_manager + + _open_app "$input_files" +} + +_open_app() { + local input_files=$1 + local input_file="" + + for input_file in $input_files; do + # Run the main process. + cd "$input_file" || exit 1 + if _command_exists "alacritty"; then + alacritty & + elif _command_exists "kitty"; then + kitty & + elif _command_exists "terminology"; then + terminology & + elif _command_exists "terminator"; then + terminator & + elif _command_exists "kgx"; then + kgx & + elif _command_exists "gnome-terminal"; then + gnome-terminal & + elif _command_exists "konsole"; then + konsole & + elif _command_exists "mate-terminal"; then + mate-terminal & + elif _command_exists "xfce4-terminal"; then + xfce4-terminal & + elif _command_exists "qterminal"; then + qterminal & + elif _command_exists "deepin-terminal"; then + deepin-terminal & + elif _command_exists "termit"; then + termit & + elif _command_exists "uxterm"; then + uxterm & + elif _command_exists "xterm"; then + xterm & + fi + done +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Plain text/Convert '4 spaces' to 'tabs' b/.local/share/nautilus/scripts/Plain text/Convert '4 spaces' to 'tabs' new file mode 100755 index 0000000..47189c0 --- /dev/null +++ b/.local/share/nautilus/scripts/Plain text/Convert '4 spaces' to 'tabs' @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime='text/|application/json'") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + local temp_file="" + + # Work on a temporary file. + temp_file=$(_get_temp_file) + + # Run the main process. + std_output=$(unexpand --tabs=4 -- "$input_file" >"$temp_file") + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 + + # Move the temporary file to the output. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + _move_temp_file_to_output "$input_file" "$temp_file" "$output_file" + + # Remove the temporary files on each iteration (if not removed before). + rm -f -- "$temp_file" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Plain text/Convert 'tabs' to '4 spaces' b/.local/share/nautilus/scripts/Plain text/Convert 'tabs' to '4 spaces' new file mode 100755 index 0000000..ddfe918 --- /dev/null +++ b/.local/share/nautilus/scripts/Plain text/Convert 'tabs' to '4 spaces' @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime='text/|application/json'") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + local temp_file="" + + # Work on a temporary file. + temp_file=$(_get_temp_file) + + # Run the main process. + std_output=$(expand --tabs=4 -- "$input_file" >"$temp_file") + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 + + # Move the temporary file to the output. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + _move_temp_file_to_output "$input_file" "$temp_file" "$output_file" + + # Remove the temporary files on each iteration (if not removed before). + rm -f -- "$temp_file" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Plain text/Encode to ASCII (translit.) b/.local/share/nautilus/scripts/Plain text/Encode to ASCII (translit.) new file mode 100755 index 0000000..28aae2c --- /dev/null +++ b/.local/share/nautilus/scripts/Plain text/Encode to ASCII (translit.) @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=iconv; package=libc-bin" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime='text/|application/json'") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + local temp_file="" + + # Work on a temporary file. + temp_file=$(_get_temp_file) + + # Run the main process. + std_output=$(iconv -f "$(_get_file_encoding "$input_file")" "$input_file" -t ascii//TRANSLIT -o "$temp_file") + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 + + # Move the temporary file to the output. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + _move_temp_file_to_output "$input_file" "$temp_file" "$output_file" + + # Remove the temporary files on each iteration (if not removed before). + rm -f -- "$temp_file" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Plain text/Encode to ISO-8859-1 b/.local/share/nautilus/scripts/Plain text/Encode to ISO-8859-1 new file mode 100755 index 0000000..fb07f06 --- /dev/null +++ b/.local/share/nautilus/scripts/Plain text/Encode to ISO-8859-1 @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=iconv; package=libc-bin" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime='text/|application/json'") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + local temp_file="" + + # Work on a temporary file. + temp_file=$(_get_temp_file) + + # Run the main process. + std_output=$(iconv -f "$(_get_file_encoding "$input_file")" "$input_file" -t iso-8859-1 -o "$temp_file") + _check_output "$?" "$std_output" "$input_file" "" || return 1 + + # Move the temporary file to the output. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + _move_temp_file_to_output "$input_file" "$temp_file" "$output_file" + + # Remove the temporary files on each iteration (if not removed before). + rm -f -- "$temp_file" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Plain text/Encode to UTF-8 b/.local/share/nautilus/scripts/Plain text/Encode to UTF-8 new file mode 100755 index 0000000..89cd107 --- /dev/null +++ b/.local/share/nautilus/scripts/Plain text/Encode to UTF-8 @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=iconv; package=libc-bin" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime='text/|application/json'") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + local temp_file="" + + # Work on a temporary file. + temp_file=$(_get_temp_file) + + # Run the main process. + std_output=$(iconv -f "$(_get_file_encoding "$input_file")" "$input_file" -t utf-8 -o "$temp_file") + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 + + # Move the temporary file to the output. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + _move_temp_file_to_output "$input_file" "$temp_file" "$output_file" + + # Remove the temporary files on each iteration (if not removed before). + rm -f -- "$temp_file" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Plain text/Line breaks to CRLF (Windows) b/.local/share/nautilus/scripts/Plain text/Line breaks to CRLF (Windows) new file mode 100755 index 0000000..40888d6 --- /dev/null +++ b/.local/share/nautilus/scripts/Plain text/Line breaks to CRLF (Windows) @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=perl; package=perl-base" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime='text/|application/json'") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + local temp_file="" + + # Work on a temporary file. + temp_file=$(_get_temp_file) + + # Run the main process. + std_output=$(perl -pe "s/\r\n|\n|\r/\r\n/g" -- "$input_file" >"$temp_file") + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 + + # Move the temporary file to the output. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + _move_temp_file_to_output "$input_file" "$temp_file" "$output_file" + + # Remove the temporary files on each iteration (if not removed before). + rm -f -- "$temp_file" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Plain text/Line breaks to LF (Unix) b/.local/share/nautilus/scripts/Plain text/Line breaks to LF (Unix) new file mode 100755 index 0000000..9c598bf --- /dev/null +++ b/.local/share/nautilus/scripts/Plain text/Line breaks to LF (Unix) @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=perl; package=perl-base" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime='text/|application/json'") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + local temp_file="" + + # Work on a temporary file. + temp_file=$(_get_temp_file) + + # Run the main process. + std_output=$(perl -pe "s/\r\n|\n|\r/\n/g" -- "$input_file" >"$temp_file") + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 + + # Move the temporary file to the output. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + _move_temp_file_to_output "$input_file" "$temp_file" "$output_file" + + # Remove the temporary files on each iteration (if not removed before). + rm -f -- "$temp_file" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Plain text/List encodings b/.local/share/nautilus/scripts/Plain text/List encodings new file mode 100755 index 0000000..e4e713e --- /dev/null +++ b/.local/share/nautilus/scripts/Plain text/List encodings @@ -0,0 +1,46 @@ +#!/usr/bin/env bash +# install_keyboard_shortcut=4 + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_recursive=true; par_get_pwd=true; par_select_mime='text/|application/json'") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + + local std_output="" + std_output=$(_storage_text_read_all) + std_output=$(_text_sort "$std_output") + + _display_list_box "$std_output" "--column=Encoding;--column=File" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + local file_encoding="" + file_encoding=$(_get_file_encoding "$input_file") + + if [[ -z "$file_encoding" ]]; then + return + fi + + # Run the main process. + std_output="$file_encoding$FIELD_SEPARATOR$input_file" + std_output=$(_text_remove_pwd "$std_output") + + _storage_text_write_ln "$std_output" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Plain text/List files with bad chars b/.local/share/nautilus/scripts/Plain text/List files with bad chars new file mode 100755 index 0000000..928872d --- /dev/null +++ b/.local/share/nautilus/scripts/Plain text/List files with bad chars @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +# install_keyboard_shortcut=3 + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_recursive=true; par_get_pwd=true; par_select_mime='text/|application/json'") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + + local std_output="" + std_output=$(_storage_text_read_all) + + _display_list_box "$std_output" "--column=Char;--column=Line;--column=File" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + + # Run the main process. + std_output=$( + grep --ignore-case --perl-regexp --only-matching --line-number \ + "[^ \w\t\n\r\-\,\;\:\!\?\.\'\"\(\)\[\]\{\}\@\*\/\\\&\#\%\`\^\+\<\=\>\|\~\$áàâãçéêíóôõú\“\”®§©ªº°¹²³«»´¢£µ]" \ + -- "$input_file" /dev/null + ) + std_output=$(_text_remove_pwd "$std_output") + # shellcheck disable=SC2001 + std_output=$(sed "s|^\([^:]*\):\([^:]*\):\([^:]*\)$|\3$FIELD_SEPARATOR\2$FIELD_SEPARATOR\1|g" <<<"$std_output") + + _storage_text_write_ln "$std_output" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Plain text/List line breaks b/.local/share/nautilus/scripts/Plain text/List line breaks new file mode 100755 index 0000000..effbf20 --- /dev/null +++ b/.local/share/nautilus/scripts/Plain text/List line breaks @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +# shellcheck disable=SC2001 +# install_keyboard_shortcut=5 + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_recursive=true; par_get_pwd=true; par_select_mime='text/|application/json'") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + + local std_output="" + std_output=$(_storage_text_read_all) + std_output=$(_text_sort "$std_output") + + _display_list_box "$std_output" "--column=Endings;--column=File" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + + # Run the main process. + std_output=$(file --dereference --separator "$FIELD_SEPARATOR" --no-pad -- "$input_file") + std_output=$(_text_remove_pwd "$std_output") + std_output=$(sed "s|$FIELD_SEPARATOR.*with CRLF, CR, LF line.*|$FIELD_SEPARATOR CRLF+CR+LF (windows)|" <<<"$std_output") + std_output=$(sed "s|$FIELD_SEPARATOR.*with CRLF, LF line.*|$FIELD_SEPARATOR CRLF+LF (windows)|" <<<"$std_output") + std_output=$(sed "s|$FIELD_SEPARATOR.*with CRLF, CR line.*|$FIELD_SEPARATOR CRLF+CR (windows)|" <<<"$std_output") + std_output=$(sed "s|$FIELD_SEPARATOR.*with CRLF line.*|$FIELD_SEPARATOR CRLF (windows)|" <<<"$std_output") + std_output=$(sed "s|$FIELD_SEPARATOR.*with CR line.*|$FIELD_SEPARATOR CR (mac)|" <<<"$std_output") + std_output=$(sed "s|$FIELD_SEPARATOR.*with CR, LF line.*|$FIELD_SEPARATOR CR+LF (mac)|" <<<"$std_output") + std_output=$(sed "s|$FIELD_SEPARATOR.*no line.*|$FIELD_SEPARATOR (no line)|" <<<"$std_output") + std_output=$(sed "s|$FIELD_SEPARATOR.*text.*|$FIELD_SEPARATOR LF (unix)|" <<<"$std_output") + std_output=$(sed "s|\(.*\)$FIELD_SEPARATOR\s*\(.*\)|\2$FIELD_SEPARATOR\1|" <<<"$std_output") + std_output=$(grep "(windows)\|(unix)\|(mac)\|(no line)" <<<"$std_output") + + _storage_text_write_ln "$std_output" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Plain text/List lines count b/.local/share/nautilus/scripts/Plain text/List lines count new file mode 100755 index 0000000..b17115a --- /dev/null +++ b/.local/share/nautilus/scripts/Plain text/List lines count @@ -0,0 +1,43 @@ +#!/usr/bin/env bash +# install_keyboard_shortcut=6 + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_recursive=true; par_get_pwd=true; par_select_mime='text/|application/json'") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + + local std_output="" + std_output=$(_storage_text_read_all) + std_output=$(sort -h -r <<<"$std_output") + + _display_list_box "$std_output" "--column=Count;--column=File" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + + # Run the main process. + std_output=$(wc --lines -- "$input_file" 2>/dev/null) + std_output=$(grep -v ".*[0-9]* total$" <<<"$std_output") + # shellcheck disable=SC2001 + std_output=$(sed "s| *\([0-9]*\) *\(.*\)|\1$FIELD_SEPARATOR\2|" <<<"$std_output") + std_output=$(_text_remove_pwd "$std_output") + + _storage_text_write_ln "$std_output" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Plain text/List max line length b/.local/share/nautilus/scripts/Plain text/List max line length new file mode 100755 index 0000000..b871e16 --- /dev/null +++ b/.local/share/nautilus/scripts/Plain text/List max line length @@ -0,0 +1,43 @@ +#!/usr/bin/env bash +# install_keyboard_shortcut=7 + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_recursive=true; par_get_pwd=true; par_select_mime='text/|application/json'") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + + local std_output="" + std_output=$(_storage_text_read_all) + std_output=$(sort -h -r <<<"$std_output") + + _display_list_box "$std_output" "--column=Count;--column=File" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + + # Run the main process. + std_output=$(wc --max-line-length -- "$input_file" 2>/dev/null) + std_output=$(grep -v ".*[0-9]* total$" <<<"$std_output") + # shellcheck disable=SC2001 + std_output=$(sed "s| *\([0-9]*\) *\(.*\)|\1$FIELD_SEPARATOR\2|" <<<"$std_output") + std_output=$(_text_remove_pwd "$std_output") + + _storage_text_write_ln "$std_output" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Plain text/List text issues b/.local/share/nautilus/scripts/Plain text/List text issues new file mode 100755 index 0000000..c6d2c04 --- /dev/null +++ b/.local/share/nautilus/scripts/Plain text/List text issues @@ -0,0 +1,92 @@ +#!/usr/bin/env bash +# install_keyboard_shortcut=2 + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_recursive=true; par_get_pwd=true; par_select_mime='text/|application/json'") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "" + + local std_output="" + std_output=$(_storage_text_read_all) + std_output=$(_text_sort "$std_output") + + _display_list_box "$std_output" "--column=Issues;--column=File" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local file_encoding="" + local file_information="" + local issues="" + + file_encoding=$(_get_file_encoding "$input_file") + file_information=$(file --dereference --separator "$FIELD_SEPARATOR" --no-pad -- "$input_file" | sed "s|\(.*\)$FIELD_SEPARATOR ||") + + # Run the checker 'non UTF-8 encoding'. + if [[ "${file_encoding,,}" != *"us-ascii"* ]] && [[ "${file_encoding,,}" != *"utf-8"* ]]; then + issues+="[non UTF-8 encoding]" + fi + + # Run the checker 'UTF-8 with BOM'. + if [[ "${file_encoding,,}" == *"utf-8"* ]]; then + if head -c3 "$input_file" | LC_ALL=C grep --quiet --perl-regexp -m1 '\xef\xbb\xbf'; then + issues+="[UTF-8 with BOM]" + fi + fi + + # Run the checker 'non-LF line break'. + if [[ "$file_information" == *"with CR"* ]]; then + issues+="[non-LF line break]" + fi + + # Run the checker 'trailing spaces' (for Unix and Windows files). + if grep --quiet --perl-regexp -m1 "[ \t]\r?$" "$input_file"; then + issues+="[trailing spaces]" + fi + + # Run the checker 'trailing spaces' (for Mac files). + if [[ "$file_information" == *"with CR line"* ]] || [[ "$file_information" == *"with CR, LF line"* ]]; then + if cat -A "$input_file" | grep --quiet -m1 " ^M"; then + [[ "$issues" != *"trailing spaces"* ]] && issues+="[trailing spaces]" + fi + fi + + # Run the checker 'mix tabs and spaces' (different lines). + if grep --quiet --perl-regexp -m1 "^\t" "$input_file" && grep --quiet --perl-regexp -m1 "^ " "$input_file"; then + issues+="[mix tabs and spaces]" + fi + + # Run the checker 'mix tabs and spaces' (same line). + if grep --quiet --perl-regexp -m1 "\t " "$input_file" || grep --quiet --perl-regexp -m1 " \t" "$input_file"; then + [[ "$issues" != *"mix tabs and spaces"* ]] && issues+="[mix tabs and spaces]" + fi + + # Run the checker 'missing line at the end'. + if ! tail -c 1 "$input_file" | hexdump -e '16/1 "%02x" "\n"' | grep --quiet -m1 "0d\|0a"; then + issues+="[missing line at the end]" + else + if tail -c 3 "$input_file" | hexdump -e '16/1 "%02x" "\n"' | grep --quiet -m1 "..0d0d\|..0a0a\|0a0d0a"; then + # Run the checker 'has many line breaks at the end'. + issues+="[extra lines at the end]" + fi + fi + + # Save the result only for files with issues. + if [[ -n "$issues" ]]; then + _storage_text_write_ln "$issues$FIELD_SEPARATOR$(_text_remove_pwd "$input_file")" + fi +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Plain text/List words count b/.local/share/nautilus/scripts/Plain text/List words count new file mode 100755 index 0000000..1c0d511 --- /dev/null +++ b/.local/share/nautilus/scripts/Plain text/List words count @@ -0,0 +1,43 @@ +#!/usr/bin/env bash +# install_keyboard_shortcut=8 + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_recursive=true; par_get_pwd=true; par_select_mime='text/|application/json'") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + + local std_output="" + std_output=$(_storage_text_read_all) + std_output=$(sort -h -r <<<"$std_output") + + _display_list_box "$std_output" "--column=Count;--column=File" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local std_output="" + + # Run the main process. + std_output=$(wc --words -- "$input_file" 2>/dev/null) + std_output=$(grep -v ".*[0-9]* total$" <<<"$std_output") + # shellcheck disable=SC2001 + std_output=$(sed "s| *\([0-9]*\) *\(.*\)|\1$FIELD_SEPARATOR\2|" <<<"$std_output") + std_output=$(_text_remove_pwd "$std_output") + + _storage_text_write_ln "$std_output" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Plain text/Remove trailing spaces b/.local/share/nautilus/scripts/Plain text/Remove trailing spaces new file mode 100755 index 0000000..5fbf7dd --- /dev/null +++ b/.local/share/nautilus/scripts/Plain text/Remove trailing spaces @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime='text/|application/json'") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + local temp_file="" + + # Work on a temporary file. + temp_file=$(_get_temp_file) + + # Run the main process. + std_output=$(sed "s|[ \t]*\(\r*\)$|\1|" -- "$input_file" >"$temp_file") + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 + + # Move the temporary file to the output. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + _move_temp_file_to_output "$input_file" "$temp_file" "$output_file" + + # Remove the temporary files on each iteration (if not removed before). + rm -f -- "$temp_file" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Plain text/Repair to UTF-8, CRLF (recursive) b/.local/share/nautilus/scripts/Plain text/Repair to UTF-8, CRLF (recursive) new file mode 100755 index 0000000..fd5e862 --- /dev/null +++ b/.local/share/nautilus/scripts/Plain text/Repair to UTF-8, CRLF (recursive) @@ -0,0 +1,58 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=iconv; package=libc-bin | command=perl; package=perl-base" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_recursive=true; par_select_mime='text/|application/json'; par_skip_extension=bak") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + local temp_file1="" + local temp_file2="" + + # Work on a temporary file. + temp_file1=$(_get_temp_file) + temp_file2=$(_get_temp_file) + + # Run the process (part 1) 'convert encoding to utf-8'. + std_output=$(iconv -f "$(_get_file_encoding "$input_file")" "$input_file" -t utf-8 -o "$temp_file1") + _check_output "$?" "$std_output" "$input_file" "" || return 1 + + # Run the process (part 2) 'convert line breaks to Windows'. + std_output=$(perl -pe "s/\r\n|\n|\r/\r\n/g" "$temp_file1" >"$temp_file2") + _check_output "$?" "$std_output" "$input_file" "" || return 1 + + # Run the process (part 3) 'remove trailing spaces'. + sed -i "s|[ \t]*\(\r*\)$|\1|" "$temp_file2" + + # Run the process (part 4) 'remove the empty line in EOF'. + printf "\n" >>"$temp_file2" + sed -i ':Loop;N;$!bLoop;s|\n*$||g' "$temp_file2" + + # Move the temporary file to the output. + output_file=$input_file + _move_temp_file_to_output "$input_file" "$temp_file2" "$output_file" + + # Remove the temporary files on each iteration (if not removed before). + rm -f -- "$temp_file1" + rm -f -- "$temp_file2" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Plain text/Repair to UTF-8, LF (recursive) b/.local/share/nautilus/scripts/Plain text/Repair to UTF-8, LF (recursive) new file mode 100755 index 0000000..04e1240 --- /dev/null +++ b/.local/share/nautilus/scripts/Plain text/Repair to UTF-8, LF (recursive) @@ -0,0 +1,58 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=iconv; package=libc-bin | command=perl; package=perl-base" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_recursive=true; par_select_mime='text/|application/json'; par_skip_extension=bak") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + local temp_file1="" + local temp_file2="" + + # Work on a temporary file. + temp_file1=$(_get_temp_file) + temp_file2=$(_get_temp_file) + + # Run the process (part 1) 'convert encoding to utf-8'. + std_output=$(iconv -f "$(_get_file_encoding "$input_file")" "$input_file" -t utf-8 -o "$temp_file1") + _check_output "$?" "$std_output" "$input_file" "" || return 1 + + # Run the process (part 2) 'convert line breaks to Unix'. + std_output=$(perl -pe "s/\r\n|\n|\r/\n/g" "$temp_file1" >"$temp_file2") + _check_output "$?" "$std_output" "$input_file" "" || return 1 + + # Run the process (part 3) 'remove trailing spaces'. + sed -i "s|[ \t]*\(\r*\)$|\1|" "$temp_file2" + + # Run the process (part 4) 'remove the empty line in EOF'. + printf "\n" >>"$temp_file2" + sed -i ':Loop;N;$!bLoop;s|\n*$||g' "$temp_file2" + + # Move the temporary file to the output. + output_file=$input_file + _move_temp_file_to_output "$input_file" "$temp_file2" "$output_file" + + # Remove the temporary files on each iteration (if not removed before). + rm -f -- "$temp_file1" + rm -f -- "$temp_file2" +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Rename files/Remove accents (translit.) b/.local/share/nautilus/scripts/Rename files/Remove accents (translit.) new file mode 100755 index 0000000..a4b8527 --- /dev/null +++ b/.local/share/nautilus/scripts/Rename files/Remove accents (translit.) @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "command=iconv; package=libc-bin" + _display_wait_box "2" + input_files=$(_get_files "par_type=all") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + local dir="" + local filename="" + + dir=$(dirname -- "$input_file") + filename=$(basename -- "$input_file") + + # Remove accents (transliterate). + output_file=$(iconv -f utf8 -t ascii//TRANSLIT <<<"$filename") + + # Run the main process. + std_output=$(_move_file "skip" "$input_file" "$dir/$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Rename files/Rename to lowercase b/.local/share/nautilus/scripts/Rename files/Rename to lowercase new file mode 100755 index 0000000..a3c5f36 --- /dev/null +++ b/.local/share/nautilus/scripts/Rename files/Rename to lowercase @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=all") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + local dir="" + local filename="" + + dir=$(dirname -- "$input_file") + filename=$(basename -- "$input_file") + + # Transform to lowercase. + output_file=${filename,,} + + # Run the main process. + std_output=$(_move_file "skip" "$input_file" "$dir/$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Rename files/Rename to lowercase (recursive) b/.local/share/nautilus/scripts/Rename files/Rename to lowercase (recursive) new file mode 100755 index 0000000..b9edc3e --- /dev/null +++ b/.local/share/nautilus/scripts/Rename files/Rename to lowercase (recursive) @@ -0,0 +1,65 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=all") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Rename files. + local file="" + find "$input_file" -type f ! -path "$IGNORE_FIND_PATH" -print0 2>/dev/null | while read -r -d '' file; do + local dir="" + local filename="" + local new_filename="" + + dir=$(dirname -- "$file") + filename=$(basename -- "$file") + + # Transform to lowercase. + new_filename=${filename,,} + + # Run the main process. + std_output=$(_move_file "skip" "$file" "$dir/$new_filename" 2>&1) + _check_output "$?" "$std_output" "$file" "" + done + + # Rename directories. + local dir="" + find "$input_file" -type d ! -path "$IGNORE_FIND_PATH" -print0 2>/dev/null | sort -r -z | while read -r -d '' dir; do + local parent_dir="" + local dirname="" + local new_dirname="" + + parent_dir=$(dirname -- "$dir") + dirname=$(basename -- "$dir") + + # Transform to lowercase. + new_dirname=${dirname,,} + + # Run the main process. + std_output=$(_move_file "skip" "$dir" "$parent_dir/$new_dirname" 2>&1) + _check_output "$?" "$std_output" "$dir" "" + done +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Rename files/Rename to sentence case b/.local/share/nautilus/scripts/Rename files/Rename to sentence case new file mode 100755 index 0000000..71cac65 --- /dev/null +++ b/.local/share/nautilus/scripts/Rename files/Rename to sentence case @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=all") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + local dir="" + local filename="" + + dir=$(dirname -- "$input_file") + filename=$(basename -- "$input_file") + + # Transform to sentence case. + # shellcheck disable=SC2001 + output_file=$(sed "s|\(\w\)\(.*\)|\U\1\L\2|g; s|\(\.\s\s*\)\(\w\)|\1\U\2|g" <<<"$filename") + + # Run the main process. + std_output=$(_move_file "skip" "$input_file" "$dir/$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Rename files/Rename to title case b/.local/share/nautilus/scripts/Rename files/Rename to title case new file mode 100755 index 0000000..e082679 --- /dev/null +++ b/.local/share/nautilus/scripts/Rename files/Rename to title case @@ -0,0 +1,112 @@ +#!/usr/bin/env bash +# shellcheck disable=SC2001 + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=all") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + local dir="" + local filename="" + local filename_extension="" + dir=$(dirname -- "$input_file") + filename=$(basename -- "$input_file") + filename_extension=$(_get_filename_extension "$input_file") + output_file=$filename + + # Transform similar ' characters. + output_file=$(sed "s|"$'\u0060'"|'|g" <<<"$output_file") # Grave accent. + output_file=$(sed "s|"$'\u00b4'"|'|g" <<<"$output_file") # Acute accent. + output_file=$(sed "s|"$'\u2018'"|'|g" <<<"$output_file") # Left single quotation. + output_file=$(sed "s|"$'\u2019'"|'|g" <<<"$output_file") # Right single quotation. + + # Transform to title case. + output_file=$(sed "s|\(\w\)\(\w*\)|\U\1\L\2|g" <<<"$output_file") + + # Words to lowercase. + local words="" + words="a|an|and|as|at|but|by|for|from|if|in|nor|of|on|or|per|so|the|to|via|with|yet" + words+="|a|as|e|o|os|um|uns|uma|umas|com|da|das|de|desde|do|dos|em|na|nas|no|nos|ou|pra|para|pela|pelas|pelo|pelos|por|se|sob|sobre" + words+="|von" + output_file=$(sed -E "s/ ($words)\b/ \L\1/gI" <<<"$output_file") + + # Uppercase the beginning of sentences. + output_file=$(sed -E "s|([-\.])(\s\w)|\1\U\2|g" <<<"$output_file") + + # Fix words with ' character. + output_file=$(sed "s|\('\w\)|\L\1|gI" <<<"$output_file") + output_file=$(sed "s| \(d'\w\)| \U\1|gI" <<<"$output_file") + output_file=$(sed "s| \(o'\w\)| \U\1|gI" <<<"$output_file") + output_file=$(sed "s| o' | O' |gI" <<<"$output_file") + output_file=$(sed "s|'em |'Em |gI" <<<"$output_file") + output_file=$(sed "s| '\(\w\)| '\U\1|gI" <<<"$output_file") + + # Fix common uppercase word abbreviations. + words="[0-9]\w|ac|api|sql|aka|asap|ceo|cfo|cto|dc|diy|dna|faq|isbn|ko|mtv|rpg|rpm|tv|usa|vip" + words+="|bios|cmos|fifa|gba|nba|nes|nfl|nhl|rom|snes|uml" + output_file=$(sed -E "s/\b($words)\b/\U\1/gI" <<<"$output_file") + + # Fix the some specific cases. + output_file=$(sed "s|-in-|-in-|gI" <<<"$output_file") + output_file=$(sed "s|\bphd\b|PhD|gI" <<<"$output_file") + output_file=$(sed "s|\bno\. |No. |gI" <<<"$output_file") + + # Fix the some specific cases: 'featuring' word. + output_file=$(sed "s|\bfeat\. |feat. |gI" <<<"$output_file") + output_file=$(sed "s|\bfeaturing |featuring |gI" <<<"$output_file") + + # Fix the some specific cases: article 'the'. + output_file=$(sed "s|, a |, A |gI" <<<"$output_file") + output_file=$(sed "s|, an |, An |gI" <<<"$output_file") + output_file=$(sed "s|, the |, The |gI" <<<"$output_file") + output_file=$(sed "s|\& the |\& The |gI" <<<"$output_file") + output_file=$(sed "s|\band the |and The |gI" <<<"$output_file") + + # Fix the some specific cases: some roman numbers. + output_file=$(sed -E "s/ (IX|IV|V?I{0,3})\b/ \U\1/gI" <<<"$output_file") + + # Fix the some specific cases: classical songs. + output_file=$(sed "s| in a minor| in A Minor|gI" <<<"$output_file") + output_file=$(sed "s| in e minor| in E Minor|gI" <<<"$output_file") + output_file=$(sed "s| in a major| in A Major|gI" <<<"$output_file") + output_file=$(sed "s| in e major| in E Major|gI" <<<"$output_file") + output_file=$(sed "s| in a flat| in A Flat|gI" <<<"$output_file") + output_file=$(sed "s| in e flat| in E Flat|gI" <<<"$output_file") + output_file=$(sed "s| in a sharp| in A Sharp|gI" <<<"$output_file") + output_file=$(sed "s| in e sharp| in E Sharp|gI" <<<"$output_file") + words="bwv|hwv|rv|wwv" + output_file=$(sed -E "s/\b($words)\b/\U\1/gI" <<<"$output_file") + output_file=$(sed "s|\bwoo\b|WoO|gI" <<<"$output_file") + + # Fix abbreviations with one letter character. + output_file=$(sed "s| \(\w\.\)| \U\1|gI" <<<"$output_file") + + # Strip the extension. + output_file=$(_strip_filename_extension "$output_file") + + # Run the main process. + std_output=$(_move_file "skip" "$input_file" "$dir/$output_file${filename_extension,,}" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Rename files/Rename to uppercase b/.local/share/nautilus/scripts/Rename files/Rename to uppercase new file mode 100755 index 0000000..f06fdfd --- /dev/null +++ b/.local/share/nautilus/scripts/Rename files/Rename to uppercase @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=all") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + local dir="" + local filename="" + + dir=$(dirname -- "$input_file") + filename=$(basename -- "$input_file") + + # Transform to uppercase. + output_file=${filename^^} + + # Run the main process. + std_output=$(_move_file "skip" "$input_file" "$dir/$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Rename files/Rename to uppercase (recursive) b/.local/share/nautilus/scripts/Rename files/Rename to uppercase (recursive) new file mode 100755 index 0000000..5ba9f92 --- /dev/null +++ b/.local/share/nautilus/scripts/Rename files/Rename to uppercase (recursive) @@ -0,0 +1,65 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=all") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Rename files. + local file="" + find "$input_file" -type f ! -path "$IGNORE_FIND_PATH" -print0 2>/dev/null | while read -r -d '' file; do + local dir="" + local filename="" + local new_filename="" + + dir=$(dirname -- "$file") + filename=$(basename -- "$file") + + # Transform to uppercase. + new_filename=${filename^^} + + # Run the main process. + std_output=$(_move_file "skip" "$file" "$dir/$new_filename" 2>&1) + _check_output "$?" "$std_output" "$file" "" + done + + # Rename directories. + local dir="" + find "$input_file" -type d ! -path "$IGNORE_FIND_PATH" -print0 2>/dev/null | sort -r -z | while read -r -d '' dir; do + local parent_dir="" + local dirname="" + local new_dirname="" + + parent_dir=$(dirname -- "$dir") + dirname=$(basename -- "$dir") + + # Transform to uppercase. + new_dirname=${dirname^^} + + # Run the main process. + std_output=$(_move_file "skip" "$dir" "$parent_dir/$new_dirname" 2>&1) + _check_output "$?" "$std_output" "$dir" "" + done +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Rename files/Replace gaps with dashes b/.local/share/nautilus/scripts/Rename files/Replace gaps with dashes new file mode 100755 index 0000000..57e4ee0 --- /dev/null +++ b/.local/share/nautilus/scripts/Rename files/Replace gaps with dashes @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=all") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + local dir="" + local filename="" + + dir=$(dirname -- "$input_file") + filename=$(basename -- "$input_file") + + # Replace gaps with dashes. + output_file=$(tr -s -- "_ \t" "-" <<<"$filename") + + # Run the main process. + std_output=$(_move_file "skip" "$input_file" "$dir/$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Rename files/Replace gaps with spaces b/.local/share/nautilus/scripts/Rename files/Replace gaps with spaces new file mode 100755 index 0000000..476534f --- /dev/null +++ b/.local/share/nautilus/scripts/Rename files/Replace gaps with spaces @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=all") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + local dir="" + local filename="" + + dir=$(dirname -- "$input_file") + filename=$(basename -- "$input_file") + + # Replace gaps with spaces. + output_file=$(tr -s -- "-_\t" " " <<<"$filename") + + # Run the main process. + std_output=$(_move_file "skip" "$input_file" "$dir/$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Rename files/Replace gaps with underscores b/.local/share/nautilus/scripts/Rename files/Replace gaps with underscores new file mode 100755 index 0000000..e9ea833 --- /dev/null +++ b/.local/share/nautilus/scripts/Rename files/Replace gaps with underscores @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies "" + _display_wait_box "2" + input_files=$(_get_files "par_type=all") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + local dir="" + local filename="" + + dir=$(dirname -- "$input_file") + filename=$(basename -- "$input_file") + + # Replace gaps with underscores. + output_file=$(tr -s -- "- \t" "_" <<<"$filename") + + # Run the main process. + std_output=$(_move_file "skip" "$input_file" "$dir/$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Video/Convert to 'mkv' b/.local/share/nautilus/scripts/Video/Convert to 'mkv' new file mode 100755 index 0000000..f1d5a78 --- /dev/null +++ b/.local/share/nautilus/scripts/Video/Convert to 'mkv' @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=ffmpeg; pkg_manager=apt; package=ffmpeg | + command=ffmpeg; pkg_manager=dnf; package=ffmpeg-free | + command=ffmpeg; pkg_manager=pacman; package=ffmpeg | + command=ffmpeg; pkg_manager=zypper; package=ffmpeg" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=video/; par_validate_conflict=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=mkv") + std_output=$(ffmpeg -hide_banner -y -i "$input_file" -- "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Video/Convert to 'mkv' (copy video) b/.local/share/nautilus/scripts/Video/Convert to 'mkv' (copy video) new file mode 100755 index 0000000..21bc66c --- /dev/null +++ b/.local/share/nautilus/scripts/Video/Convert to 'mkv' (copy video) @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=ffmpeg; pkg_manager=apt; package=ffmpeg | + command=ffmpeg; pkg_manager=dnf; package=ffmpeg-free | + command=ffmpeg; pkg_manager=pacman; package=ffmpeg | + command=ffmpeg; pkg_manager=zypper; package=ffmpeg" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=video/; par_validate_conflict=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=mkv") + std_output=$(ffmpeg -hide_banner -y -i "$input_file" -vcodec copy -- "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Video/Convert to 'mp4' b/.local/share/nautilus/scripts/Video/Convert to 'mp4' new file mode 100755 index 0000000..cf45f22 --- /dev/null +++ b/.local/share/nautilus/scripts/Video/Convert to 'mp4' @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=ffmpeg; pkg_manager=apt; package=ffmpeg | + command=ffmpeg; pkg_manager=dnf; package=ffmpeg-free | + command=ffmpeg; pkg_manager=pacman; package=ffmpeg | + command=ffmpeg; pkg_manager=zypper; package=ffmpeg" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=video/; par_validate_conflict=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=mp4") + std_output=$(ffmpeg -hide_banner -y -i "$input_file" -- "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Video/Convert to 'mp4' (copy video) b/.local/share/nautilus/scripts/Video/Convert to 'mp4' (copy video) new file mode 100755 index 0000000..90b8b27 --- /dev/null +++ b/.local/share/nautilus/scripts/Video/Convert to 'mp4' (copy video) @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=ffmpeg; pkg_manager=apt; package=ffmpeg | + command=ffmpeg; pkg_manager=dnf; package=ffmpeg-free | + command=ffmpeg; pkg_manager=pacman; package=ffmpeg | + command=ffmpeg; pkg_manager=zypper; package=ffmpeg" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=video/; par_validate_conflict=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=mp4") + std_output=$(ffmpeg -hide_banner -y -i "$input_file" -vcodec copy -- "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Video/Export to 'gif' b/.local/share/nautilus/scripts/Video/Export to 'gif' new file mode 100755 index 0000000..a4700c8 --- /dev/null +++ b/.local/share/nautilus/scripts/Video/Export to 'gif' @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=ffmpeg; pkg_manager=apt; package=ffmpeg | + command=ffmpeg; pkg_manager=dnf; package=ffmpeg-free | + command=ffmpeg; pkg_manager=pacman; package=ffmpeg | + command=ffmpeg; pkg_manager=zypper; package=ffmpeg" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=video/; par_validate_conflict=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=gif") + std_output=$(ffmpeg -hide_banner -y -i "$input_file" -filter:v "fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 -- "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Video/Extract audio b/.local/share/nautilus/scripts/Video/Extract audio new file mode 100755 index 0000000..a31a216 --- /dev/null +++ b/.local/share/nautilus/scripts/Video/Extract audio @@ -0,0 +1,57 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=ffmpeg; pkg_manager=apt; package=ffmpeg | + command=ffmpeg; pkg_manager=dnf; package=ffmpeg-free | + command=ffmpeg; pkg_manager=pacman; package=ffmpeg | + command=ffmpeg; pkg_manager=zypper; package=ffmpeg" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=video/; par_validate_conflict=true") + output_dir=$(_get_output_dir "par_use_same_dir=true") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Get the audio format from the video. + local audio_format="" + audio_format=$(ffprobe -hide_banner -v error -select_streams a:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 "$input_file") + _check_output "$?" "Could not find the audio format from the video." "$input_file" "$output_file" || return 1 + + # Define the filename extension according to the audio format. + local extension="" + case $audio_format in + "aac") extension="m4a" ;; + "aiff") extension="aiff" ;; + "alac") extension="m4a" ;; + "eac3") extension="ac3" ;; + "pcm") extension="wav" ;; + "vorbis") extension="ogg" ;; + "wmav2") extension="wma" ;; + *) extension=$audio_format ;; + esac + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=replace; par_extension=$extension") + std_output=$(ffmpeg -hide_banner -y -i "$input_file" -vn -acodec copy -- "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/Video/Strip metadata b/.local/share/nautilus/scripts/Video/Strip metadata new file mode 100755 index 0000000..e11ca47 --- /dev/null +++ b/.local/share/nautilus/scripts/Video/Strip metadata @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Source the script 'common-functions.sh'. +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR") +source "$ROOT_DIR/common-functions.sh" + +_main() { + local input_files="" + local output_dir="" + + # Execute initial checks. + _check_dependencies " + command=ffmpeg; pkg_manager=apt; package=ffmpeg | + command=ffmpeg; pkg_manager=dnf; package=ffmpeg-free | + command=ffmpeg; pkg_manager=pacman; package=ffmpeg | + command=ffmpeg; pkg_manager=zypper; package=ffmpeg" + _display_wait_box "2" + input_files=$(_get_files "par_type=file; par_select_mime=video/") + output_dir=$(_get_output_dir "par_use_same_dir=false") + + # Execute the function '_main_task' for each file in parallel. + _run_task_parallel "$input_files" "$output_dir" + _display_result_box "$output_dir" +} + +_main_task() { + local input_file=$1 + local output_dir=$2 + local output_file="" + local std_output="" + + # Run the main process. + output_file=$(_get_output_filename "$input_file" "$output_dir" "par_extension_opt=preserve") + std_output=$(ffmpeg -hide_banner -y -i "$input_file" -map_metadata -1 -c:v copy -c:a copy -- "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 +} + +_main "$@" diff --git a/.local/share/nautilus/scripts/common-functions.sh b/.local/share/nautilus/scripts/common-functions.sh new file mode 100755 index 0000000..670cdd0 --- /dev/null +++ b/.local/share/nautilus/scripts/common-functions.sh @@ -0,0 +1,2596 @@ +#!/usr/bin/env bash +# shellcheck disable=SC2001 + +# This file contains common functions that the scripts will source. + +set -u + +# ----------------------------------------------------------------------------- +# CONSTANTS +# ----------------------------------------------------------------------------- + +ACCESSED_RECENTLY_DIR="$ROOT_DIR/Accessed recently" +ACCESSED_RECENTLY_LINKS_TO_KEEP=10 +FIELD_SEPARATOR=$'\r' # The main field separator. +GUI_BOX_HEIGHT=550 # Height of the GUI dialog boxes. +GUI_BOX_WIDTH=900 # Width of the GUI dialog boxes. +GUI_INFO_WIDTH=400 # Width of the GUI small dialog boxes. +IGNORE_FIND_PATH="*.git/*" # Path to ignore in the 'find' command. +PREFIX_ERROR_LOG_FILE="Errors" # Name of 'error' directory. +PREFIX_OUTPUT_DIR="Output" # Name of 'output' directory. +TEMP_DIR=$(mktemp --directory) # Temp directories for use in scripts. +TEMP_DIR_ITEMS_TO_REMOVE="$TEMP_DIR/items_to_remove" +TEMP_DIR_LOGS="$TEMP_DIR/logs" +TEMP_DIR_STORAGE_TEXT="$TEMP_DIR/storage_text" +TEMP_DIR_TASK="$TEMP_DIR/task" +WAIT_BOX_CONTROL_KDE="$TEMP_DIR/wait_box_control_kde" +WAIT_BOX_CONTROL="$TEMP_DIR/wait_box_control" +WAIT_BOX_FIFO="$TEMP_DIR/wait_box_fifo" + +readonly \ + ACCESSED_RECENTLY_DIR \ + ACCESSED_RECENTLY_LINKS_TO_KEEP \ + FIELD_SEPARATOR \ + GUI_BOX_HEIGHT \ + GUI_BOX_WIDTH \ + GUI_INFO_WIDTH \ + IGNORE_FIND_PATH \ + PREFIX_ERROR_LOG_FILE \ + PREFIX_OUTPUT_DIR \ + TEMP_DIR \ + TEMP_DIR_LOGS \ + TEMP_DIR_STORAGE_TEXT \ + TEMP_DIR_TASK \ + WAIT_BOX_CONTROL \ + WAIT_BOX_CONTROL_KDE \ + WAIT_BOX_FIFO + +# ----------------------------------------------------------------------------- +# GLOBAL VARIABLES +# ----------------------------------------------------------------------------- + +IFS=$FIELD_SEPARATOR +INPUT_FILES=$* +TEMP_DATA_TASK="" + +# ----------------------------------------------------------------------------- +# BUILD THE STRUCTURE OF THE 'TEMP_DIR' +# ----------------------------------------------------------------------------- + +# Store the path of temporary items to be removed after exit. +mkdir -p "$TEMP_DIR_ITEMS_TO_REMOVE" +mkdir -p "$TEMP_DIR_LOGS" # Store 'error logs'. +mkdir -p "$TEMP_DIR_STORAGE_TEXT" # Store the output from parallel processes. +mkdir -p "$TEMP_DIR_TASK" # Store temporary files of scripts. + +# ----------------------------------------------------------------------------- +# FUNCTIONS +# ----------------------------------------------------------------------------- + +_cleanup_on_exit() { + # This function performs cleanup tasks when the script exits. It is + # designed to safely and efficiently remove temporary directories or files + # that were created during the script's execution. + + # Remove local temporary dirs or files. + local items_to_remove="" + items_to_remove=$(cat -- "$TEMP_DIR_ITEMS_TO_REMOVE/"* 2>/dev/null) + + # Escape single quotes in filenames to handle them correctly in 'xargs' + # with 'bash -c'. + items_to_remove=$(sed -z "s|'|'\\\''|g" <<<"$items_to_remove") + + printf "%s" "$items_to_remove" | xargs \ + --no-run-if-empty \ + --delimiter="$FIELD_SEPARATOR" \ + --max-procs="$(_get_max_procs)" \ + --replace="{}" \ + bash -c "{ chmod -R u+rw -- '{}' && rm -rf -- '{}'; } &>/dev/null" + + # Remove the main temporary dir. + rm -rf -- "$TEMP_DIR" &>/dev/null + + if ! _is_gui_session; then + printf "End of the script.\n" >&2 + fi +} +trap _cleanup_on_exit EXIT + +_check_dependencies() { + # This function ensures that all required dependencies are available for + # the scripts to run. It verifies the presence of specified commands or + # packages and prompts the user to install missing ones. + # + # Parameters: + # - $1 (dependencies): A list of dependencies to check, formatted as a + # "|" delimited string. Each dependency can specify: + # - "command": The name of a command to check for in the shell. + # - "package": The package associated with the command (if different). + # - "pkg_manager": Optional. The specific package manager. + # + # Example: + # - _check_dependencies " + # command=ffmpeg; pkg_manager=apt; package=ffmpeg | + # command=ffmpeg; pkg_manager=dnf; package=ffmpeg-free | + # command=ffmpeg; pkg_manager=pacman; package=ffmpeg | + # command=ffmpeg; pkg_manager=zypper; package=ffmpeg" + + local dependencies=$1 + local packages_to_install="" + local pkg_manager_installed="" + + [[ -z "$dependencies" ]] && return + + # Skip duplicated dependencies in the input list. + dependencies=$(tr "|" "\n" <<<"$dependencies") + dependencies=$(tr -d " " <<<"$dependencies") + dependencies=$(sort --unique <<<"$dependencies") + dependencies=$(_text_remove_empty_lines "$dependencies") + + [[ -z "$dependencies" ]] && return + + # Get the name of the installed package manager. + pkg_manager_installed=$(_pkg_get_package_manager) + if [[ -z "$pkg_manager_installed" ]]; then + _display_error_box "Could not find a package manager!" + _exit_script + fi + + # Check all dependencies. + dependencies=$(tr "\n" "$FIELD_SEPARATOR" <<<"$dependencies") + local dependency="" + for dependency in $dependencies; do + local command="" + local package="" + local pkg_manager="" + + # Evaluate the values parameters from the 'dependency' variable. + eval "$dependency" + + # Ignore installing the dependency if there is a command in the shell. + if [[ -n "$command" ]] && _command_exists "$command"; then + continue + fi + + # Ignore installing the dependency if the installed + # package managers differ. + if [[ -n "$pkg_manager" ]] && + [[ "$pkg_manager_installed" != "$pkg_manager" ]]; then + continue + fi + + # Ignore installing the dependency if the package is already installed + # (packages that do not have a command). + if [[ -n "$package" ]] && [[ -z "$command" ]] && + _pkg_is_package_installed "$pkg_manager_installed" "$package"; then + continue + fi + + # If the package is not specified, use the command name as + # the package name. + if [[ -z "$package" ]] && [[ -n "$command" ]]; then + package=$command + fi + + # Add the package to the list to install. + if [[ -n "$package" ]]; then + packages_to_install+=" $package" + fi + done + + # Ask the user to install the packages. + if [[ -n "$packages_to_install" ]]; then + local message="These packages were not found:" + message+=$(sed "s| |\n- |g" <<<"$packages_to_install") + message+=$'\n'$'\n' + message+="Would you like to install them?" + if _display_question_box "$message"; then + _pkg_install_packages \ + "$pkg_manager_installed" "${packages_to_install/ /}" + else + _exit_script + fi + fi +} + +_check_output() { + # This function validates the success of a command or process based on its + # exit code and output. It logs errors if the command fails or if an + # expected output file is missing. + # + # Parameters: + # - $1 (exit_code): The exit code returned by the command or process. + # - $2 (std_output): The standard output or error from the command. + # - $3 (input_file): The input file associated (if applicable). + # - $4 (output_file): The expected output file to verify its existence. + # + # Returns: + # - "0" (true): If the command was successful and the output file exists. + # - "1" (false): If the command failed or the output file does not exist. + + local exit_code=$1 + local std_output=$2 + local input_file=$3 + local output_file=$4 + + # Check the 'exit_code' and log the error. + if ((exit_code != 0)); then + _log_error "Command failed with a non-zero exit code." \ + "$input_file" "$std_output" "$output_file" + return 1 + fi + + # Check if the output file exists. + if [[ -n "$output_file" ]] && [[ ! -e "$output_file" ]]; then + _log_error "The output file does not exist." \ + "$input_file" "$std_output" "$output_file" + return 1 + fi + + return 0 +} + +_command_exists() { + # This function checks whether a given command is available on the system. + # + # Parameters: + # - $1 (command_check): The name of the command to verify. + # + # Returns: + # - "0" (true): If the command is available. + # - "1" (false): If the command is not available. + + local command_check=$1 + + if command -v "$command_check" &>/dev/null; then + return 0 + fi + return 1 +} + +_convert_delimited_string_to_text() { + # This function converts a delimited string of items into + # newline-separated text. + # + # Parameters: + # - $1 (input_items): A string containing items separated by the + # 'FIELD_SEPARATOR' variable. + # + # Returns: + # - A string containing the items separated by newlines. + + local input_items=$1 + local new_line="'\$'\\\n''" + + input_items=$(sed -z "s|\n|$new_line|g; s|$new_line$||g" <<<"$input_items") + input_items=$(tr "$FIELD_SEPARATOR" "\n" <<<"$input_items") + + printf "%s" "$input_items" +} + +_directory_pop() { + # This function pops the top directory off the directory stack and changes + # to the previous directory. + # + # Returns: + # - "0" (true): If the directory was successfully popped and changed. + # - "1" (false): If there was an error popping the directory. + + popd &>/dev/null || { + _log_error "Could not pop a directory." "" "" "" + return 1 + } + return 0 +} + +_directory_push() { + # This function pushes the specified directory onto the directory stack and + # changes to it. + # + # Parameters: + # - $1 (directory): The target directory to push onto the directory stack + # and navigate to. + # + # Returns: + # - "0" (true): If the directory was successfully pushed and changed. + # - "1" (false): If there was an error pushing the directory. + + local directory=$1 + + pushd "$directory" &>/dev/null || { + _log_error "Could not push the directory '$directory'." "" "" "" + return 1 + } + return 0 +} + +_convert_text_to_delimited_string() { + # This function converts newline-separated text into a delimited string of + # items. + # + # Parameters: + # - $1 (input_items): A string containing items separated by newlines. + # + # Returns: + # - A string containing the items separated by the 'FIELD_SEPARATOR' + # variable. + + local input_items=$1 + local new_line="'\$'\\\n''" + + input_items=$(tr "\n" "$FIELD_SEPARATOR" <<<"$input_items") + input_items=$(sed -z "s|$new_line|\n|g" <<<"$input_items") + + input_items=$(_str_remove_empty_tokens "$input_items") + printf "%s" "$input_items" +} + +_display_dir_selection_box() { + # This function presents a graphical interface to allow the user to select + # one or more directories. + + local input_files="" + + if _command_exists "zenity"; then + input_files=$(zenity --title "$(_get_script_name)" \ + --file-selection --multiple --directory \ + --separator="$FIELD_SEPARATOR" 2>/dev/null) || _exit_script + elif _command_exists "kdialog"; then + input_files=$(kdialog --title "$(_get_script_name)" \ + --getexistingdirectory 2>/dev/null) || _exit_script + # Use parameter expansion to remove the last space. + input_files=${input_files% } + input_files=${input_files// \//$FIELD_SEPARATOR/} + fi + + input_files=$(_str_remove_empty_tokens "$input_files") + printf "%s" "$input_files" +} + +# shellcheck disable=SC2120 +_display_file_selection_box() { + # This function presents a graphical interface to allow the user to select + # a file. + # + # Parameters: + # - $1 (file_filter): Optional. File filter pattern to restrict the types + # of files shown. + # - $2 (title): Optional. Title of the window. + + local file_filter=${1:-""} + local title=${2:-"$(_get_script_name)"} + local input_files="" + + if _command_exists "zenity"; then + input_files=$(zenity --title "$title" \ + --file-selection \ + ${file_filter:+--file-filter="$file_filter"} \ + --separator="$FIELD_SEPARATOR" 2>/dev/null) || _exit_script + elif _command_exists "kdialog"; then + input_files=$(kdialog --title "$title" \ + --getopenfilename 2>/dev/null) || _exit_script + # Use parameter expansion to remove the last space. + input_files=${input_files% } + input_files=${input_files// \//$FIELD_SEPARATOR/} + fi + + input_files=$(_str_remove_empty_tokens "$input_files") + printf "%s" "$input_files" +} + +_display_error_box() { + # This function displays an error message to the user, adapting to the + # available environment. + # + # Parameters: + # - $1 (message): The error message to display. + + local message=$1 + + if ! _is_gui_session; then + printf "Error: %s\n" "$message" >&2 + elif [[ -n "$DBUS_SESSION_BUS_ADDRESS" ]]; then + _gdbus_notify "dialog-error" "$(_get_script_name)" "$message" + elif _command_exists "zenity"; then + zenity --title "$(_get_script_name)" --error \ + --width="$GUI_INFO_WIDTH" --text "$message" &>/dev/null + elif _command_exists "kdialog"; then + kdialog --title "$(_get_script_name)" --error "$message" &>/dev/null + elif _command_exists "xmessage"; then + xmessage -title "$(_get_script_name)" "Error: $message" &>/dev/null + fi +} + +_display_info_box() { + # This function displays an information message to the user, adapting to + # the available environment. + # + # Parameters: + # - $1 (message): The information message to display. + + local message=$1 + + if ! _is_gui_session; then + printf "Info: %s\n" "$message" >&2 + elif [[ -n "$DBUS_SESSION_BUS_ADDRESS" ]]; then + _gdbus_notify "dialog-information" "$(_get_script_name)" "$message" + elif _command_exists "zenity"; then + zenity --title "$(_get_script_name)" --info \ + --width="$GUI_INFO_WIDTH" --text "$message" &>/dev/null + elif _command_exists "kdialog"; then + kdialog --title "$(_get_script_name)" --msgbox "$message" &>/dev/null + elif _command_exists "xmessage"; then + xmessage -title "$(_get_script_name)" "Info: $message" &>/dev/null + fi +} + +_display_list_box() { + # This function displays a list box with selectable items, adapting to the + # available environment. + # + # Parameters: + # - $1 (message): A string containing the items to display in the list. + # - $2 (columns): Column definitions for the list, typically in the + # format "--column=;--column=". + # - $3 (item_name): A string representing the name of the items in the + # list. If not provided, the default value is "items". + # - $4 (resolve_links): A boolean-like string ("true" or "false") + # indicating whether symbolic links in item paths should be resolved to + # their target locations when opening the item's location. Defaults to + # "true". + + local message=$1 + local columns=$2 + local item_name=${3:-"items"} + local resolve_links=${4:-"true"} + local columns_count=0 + local items_count=0 + local selected_item="" + local message_select="" + _close_wait_box + _logs_consolidate "" + + if [[ -n "$message" ]]; then + items_count=$(tr -cd "\n" <<<"$message" | wc -c) + message_select=" Select an item to open its location:" + fi + + # Count the number of columns. + columns_count=$(grep --only-matching "column=" <<<"$columns" | wc -l) + + if ! _is_gui_session; then + if [[ -z "$message" ]]; then + message="(Empty result)" + printf "%s\n" "$message" >&2 + else + message=$(tr "$FIELD_SEPARATOR" " " <<<"$message") + printf "%s\n" "$message" + fi + elif _command_exists "zenity"; then + if [[ -z "$message" ]]; then + # NOTE: Some versions of Zenity crash if the + # message is empty (Segmentation fault). + message=" " + fi + columns=$(tr ";" "$FIELD_SEPARATOR" <<<"$columns") + message=$(tr "\n" "$FIELD_SEPARATOR" <<<"$message") + # shellcheck disable=SC2086 + selected_item=$(zenity --title "$(_get_script_name)" --list \ + --editable --multiple --separator="$FIELD_SEPARATOR" \ + --width="$GUI_BOX_WIDTH" --height="$GUI_BOX_HEIGHT" \ + --print-column "$columns_count" \ + --text "Total of $items_count $item_name.$message_select" \ + $columns $message 2>/dev/null) || _exit_script + + if ((items_count != 0)) && [[ -n "$selected_item" ]]; then + # Open the directory of the clicked item in the list. + _open_items_locations "$selected_item" "$resolve_links" + fi + elif _command_exists "kdialog"; then + columns=$(sed "s|--column=||g" <<<"$columns") + columns=$(tr ";" "\t" <<<"$columns") + message=$(tr "$FIELD_SEPARATOR" "\t" <<<"$message") + message="$columns"$'\n'$'\n'"$message" + kdialog --title "$(_get_script_name)" \ + --geometry "${GUI_BOX_WIDTH}x${GUI_BOX_HEIGHT}" \ + --textinputbox "" "$message" &>/dev/null || _exit_script + elif _command_exists "xmessage"; then + columns=$(sed "s|--column=||g" <<<"$columns") + columns=$(tr ";" "\t" <<<"$columns") + message=$(tr "$FIELD_SEPARATOR" "\t" <<<"$message") + message="$columns"$'\n'$'\n'"$message" + xmessage -title "$(_get_script_name)" \ + "$message" &>/dev/null || _exit_script + fi +} + +_display_password_box() { + # This function prompts the user to enter a password, either via the + # terminal or a graphical dialog box. + # + # Parameters: + # - $1 (message): A message to display as a prompt for the password. + + local message=$1 + local password="" + + # Ask the user for the 'password'. + if ! _is_gui_session; then + read -r -p "$message " password >&2 + elif _command_exists "zenity"; then + sleep 0.2 # Avoid 'wait_box' open before. + password=$(zenity \ + --title="Password" --entry --hide-text --width="$GUI_INFO_WIDTH" \ + --text "$message" 2>/dev/null) || return 1 + elif _command_exists "kdialog"; then + sleep 0.2 # Avoid 'wait_box' open before. + password=$(kdialog --title "Password" \ + --password "$message" 2>/dev/null) || return 1 + fi + + printf "%s" "$password" +} + +_display_password_box_define() { + # This function prompts the user to enter a password and ensures the + # password is not empty. + + local message="Type your password:" + local password="" + + password=$(_display_password_box "$message") || return 1 + + # Check if the 'password' is not empty. + if [[ -z "$password" ]]; then + _display_error_box "The password can not be empty!" + return 1 + fi + + printf "%s" "$password" +} + +_display_question_box() { + # This function prompts the user with a yes/no question and returns the + # user's response. + # + # Parameters: + # - $1 (message): The question message to display to the user. + + local message=$1 + local response="" + + if ! _is_gui_session; then + read -r -p "$message [Y/n] " response + [[ ${response,,} == *"n"* ]] && return 1 + elif _command_exists "zenity"; then + zenity --title "$(_get_script_name)" --question \ + --width="$GUI_INFO_WIDTH" --text="$message" &>/dev/null || return 1 + elif _command_exists "kdialog"; then + kdialog --title "$(_get_script_name)" \ + --yesno "$message" &>/dev/null || return 1 + elif _command_exists "xmessage"; then + xmessage -title "$(_get_script_name)" \ + -buttons "Yes:0,No:1" "$message" &>/dev/null || return 1 + fi + return 0 +} + +_display_text_box() { + # This function displays a message to the user in a text box, either in the + # terminal or using a GUI dialog. + # + # Parameters: + # - $1 (message): The message to display. If empty, a default message + # "(Empty result)" is shown. + + local message=$1 + _close_wait_box + _logs_consolidate "" + + if [[ -z "$message" ]]; then + message="(Empty result)" + fi + + if ! _is_gui_session; then + printf "%s\n" "$message" + elif _command_exists "zenity"; then + zenity --title "$(_get_script_name)" --text-info --no-wrap \ + --width="$GUI_BOX_WIDTH" --height="$GUI_BOX_HEIGHT" \ + <<<"$message" &>/dev/null || _exit_script + elif _command_exists "kdialog"; then + kdialog --title "$(_get_script_name)" \ + --geometry "${GUI_BOX_WIDTH}x${GUI_BOX_HEIGHT}" \ + --textinputbox "" \ + "$message" &>/dev/null || _exit_script + elif _command_exists "xmessage"; then + xmessage -title "$(_get_script_name)" \ + "$message" &>/dev/null || _exit_script + fi +} + +_display_result_box() { + # This function displays a result summary at the end of a process, + # including error checking and output directory information. + # + # Parameters: + # - $1 (output_dir): The directory where output files are stored or + # expected to be. + + local output_dir=$1 + _close_wait_box + _logs_consolidate "$output_dir" + + # If 'output_dir' parameter is defined. + if [[ -n "$output_dir" ]]; then + # Try to remove the output directory (if it is empty). + if [[ "$output_dir" == *"/$PREFIX_OUTPUT_DIR"* ]]; then + rmdir "$output_dir" &>/dev/null + fi + + # Check if the output directory still exists. + if [[ -d "$output_dir" ]]; then + local dir_label="" + dir_label=$(_str_human_readable_path "$output_dir") + _display_info_box \ + "Finished! The output files are in the $dir_label directory." + else + _display_info_box "Finished, but there is nothing to do." + fi + else + _display_info_box "Finished!" + fi +} + +_display_wait_box() { + # This function displays a wait box to inform the user that a task is + # running and they need to wait. + # + # Parameters: + # - $1 (open_delay): Optional. The delay (in seconds) before the wait box + # is shown. Defaults to 2 seconds if not provided. + + local open_delay=${1:-"2"} + local message="Running the task. Please, wait..." + + _display_wait_box_message "$message" "$open_delay" +} + +_display_wait_box_message() { + # This function displays a wait box (progress indicator) to inform the user + # that a task is in progress. + # + # Parameters: + # - $1 (message): The message to display inside the wait box (e.g., + # "Running the task. Please, wait..."). + # - $2 (open_delay): Optional. The delay (in seconds) before the wait box + # is shown. Defaults to 2 seconds if not provided. + + local message=$1 + local open_delay=${2:-"2"} + + if ! _is_gui_session; then + # For non-GUI sessions, simply print the message to the console. + printf "%s\n" "$message" >&2 + + # Check if the Zenity is available. + elif _command_exists "zenity"; then + # Control flag to inform that a 'wait_box' will open + # (if the task takes over 2 seconds). + touch "$WAIT_BOX_CONTROL" + + # Create the FIFO for communication with Zenity 'wait_box'. + if [[ ! -p "$WAIT_BOX_FIFO" ]]; then + mkfifo "$WAIT_BOX_FIFO" + fi + + # Launch a background thread for Zenity 'wait_box': + # - Waits for the specified delay. + # - Opens the Zenity 'wait_box' if the control flag still exists. + # - If Zenity 'wait_box' fails or is cancelled, exit the script. + # shellcheck disable=SC2002 + sleep "$open_delay" && [[ -f "$WAIT_BOX_CONTROL" ]] && + tail -f -- "$WAIT_BOX_FIFO" | (zenity \ + --title="$(_get_script_name)" --progress \ + --width="$GUI_INFO_WIDTH" \ + --pulsate --auto-close --text="$message" || _exit_script) & + + # Check if the KDialog is available. + elif _command_exists "kdialog"; then + _get_qdbus_command || return 0 + # Control flag to inform that a 'wait_box' will open + # (if the task takes over 2 seconds). + touch "$WAIT_BOX_CONTROL" + + # Launch a background thread for KDialog 'wait_box': + # - Waits for the specified delay. + # - Opens the KDialog 'wait_box' if the control flag still exists. + sleep "$open_delay" && [[ -f "$WAIT_BOX_CONTROL" ]] && + kdialog --title="$(_get_script_name)" \ + --progressbar "$message" 0 >"$WAIT_BOX_CONTROL_KDE" & + + # Launch another background thread to monitor the KDialog 'wait_box': + # - Periodically checks if the dialog has been closed or cancelled. + # - If KDialog 'wait_box' is cancelled, exit the script. + ( + while [[ -f "$WAIT_BOX_CONTROL" ]] || + [[ -f "$WAIT_BOX_CONTROL_KDE" ]]; do + if [[ -f "$WAIT_BOX_CONTROL_KDE" ]]; then + # Extract the D-Bus reference for the KDialog instance. + local dbus_ref="" + dbus_ref=$(cut -d " " -f 1 <"$WAIT_BOX_CONTROL_KDE") + if [[ -n "$dbus_ref" ]]; then + # Check if the user has cancelled the wait box. + $(_get_qdbus_command) "$dbus_ref" "/ProgressDialog" \ + "wasCancelled" 2>/dev/null || _exit_script + fi + fi + sleep 0.2 + done + ) & + fi +} + +_close_wait_box() { + # This function is responsible for closing any open "wait boxes" (progress + # indicators) that were displayed during the execution of a task. It checks + # for both Zenity and KDialog wait boxes and handles their closure. + + # Check if 'wait_box' will open. + if [[ -f "$WAIT_BOX_CONTROL" ]]; then + rm -f -- "$WAIT_BOX_CONTROL" # Cancel the future open. + fi + + # Check if Zenity 'wait_box' is open (waiting for an input in the FIFO). + if pgrep -fl "$WAIT_BOX_FIFO" &>/dev/null; then + # Close the Zenity using the FIFO. + printf "100\n" >"$WAIT_BOX_FIFO" + fi + + # Check if KDialog 'wait_box' is open. + while [[ -f "$WAIT_BOX_CONTROL_KDE" ]]; do + # Extract the D-Bus reference for the KDialog instance. + local dbus_ref="" + dbus_ref=$(cut -d " " -f 1 <"$WAIT_BOX_CONTROL_KDE") + if [[ -n "$dbus_ref" ]]; then + # Close the KDialog 'wait_box'. + $(_get_qdbus_command) "$dbus_ref" "/ProgressDialog" \ + "close" 2>/dev/null + rm -f -- "$WAIT_BOX_CONTROL_KDE" + fi + sleep 0.2 + done +} + +_exit_script() { + # This function is responsible for safely exiting the script by terminating + # all child processes associated with the current script and printing an + # exit message to the terminal. + + _close_wait_box + + local child_pids="" + local script_pid=$$ + + if ! _is_gui_session; then + printf "Exiting the script...\n" >&2 + fi + + # Get the process ID (PID) of all child processes. + child_pids=$(pstree -p "$script_pid" | + grep --only-matching --perl-regexp "\(+\K[^)]+") + + # NOTE: Use 'xargs' and kill to send the SIGTERM signal to all child + # processes, including the current script. + # See the: https://www.baeldung.com/linux/safely-exit-scripts + xargs kill <<<"$child_pids" &>/dev/null +} + +_find_filtered_files() { + # This function filters a list of files or directories based on various + # user-specified criteria, such as file type, extensions, and recursion. + # + # Parameters: + # - $1 (input_files): A space-separated string containing file or + # directory paths to filter. These paths are passed to the "find" + # command. + # - $2 (par_type): A string specifying the type of file to search for. It + # can be: + # - "file": To search for files and symbolic links. + # - "directory": To search for directories and symbolic links. + # - $3 (par_skip_extension): A string of file extensions to exclude from + # the search. Only files with extensions not matching this list will be + # included. + # - $4 (par_select_extension): A string of file extensions to include in + # the search. Only files with matching extensions will be included. + # - $5 (par_find_parameters): Optional. Additional parameters to be + # passed directly to the "find" command. + # + # Example: + # - Input: "dir1 dir2", "file", "", "txt|pdf", "true" + # - Output: A list of files with extensions ".txt" or ".pdf" from the + # directories "dir1" and "dir2", searched recursively. + + local input_files=$1 + local par_type=$2 + local par_skip_extension=$3 + local par_select_extension=$4 + local par_find_parameters=$5 + local filtered_files="" + local find_command="" + + input_files=$(sed "s|'|'\"'\"'|g" <<<"$input_files") + input_files=$(sed "s|$FIELD_SEPARATOR|' '|g" <<<"$input_files") + + # Build a 'find' command. + find_command="find '$input_files'" + + if [[ -n "$par_find_parameters" ]]; then + find_command+=" $par_find_parameters" + fi + + # Expand the directories with the 'find' command. + case "$par_type" in + "file") find_command+=" \( -type l -o -type f \)" ;; + "directory") find_command+=" \( -type l -o -type d \)" ;; + esac + + if [[ -n "$par_select_extension" ]]; then + find_command+=" -regextype posix-extended " + find_command+=" -regex \".*\.($par_select_extension)$\"" + fi + + if [[ -n "$par_skip_extension" ]]; then + find_command+=" -regextype posix-extended " + find_command+=" ! -regex \".*\.($par_skip_extension)$\"" + fi + + find_command+=" ! -path \"$IGNORE_FIND_PATH\"" + # shellcheck disable=SC2089 + find_command+=" -print0" + + # shellcheck disable=SC2086 + filtered_files=$(eval $find_command 2>/dev/null | + tr "\0" "$FIELD_SEPARATOR") + filtered_files=$(_str_remove_empty_tokens "$filtered_files") + + # Return the filtered files. + printf "%s" "$filtered_files" +} + +_gdbus_notify() { + # This function sends a desktop notification using the "gdbus" tool, which + # interfaces with the D-Bus notification system (specifically the + # "org.freedesktop.Notifications" service). + # + # Parameters: + # - $1 (icon): The icon to display with the notification. + # - $2 (title): The title of the notification. + # - $3 (body): The main message to be displayed in the notification. + + local icon=$1 + local title=$2 + local body=$3 + local app_name=$title + local method="Notify" + local interface="org.freedesktop.Notifications" + local object_path="/org/freedesktop/Notifications" + + # Use 'gdbus' to send the notification. + gdbus call --session --dest "$interface" --object-path "$object_path" \ + --method "$interface.$method" "$app_name" 0 "$icon" "$title" "$body" \ + "[]" '{"urgency": <1>}' 5000 &>/dev/null +} + +_get_filename_dir() { + # This function extracts the directory path from a given file path. + # + # Parameters: + # - $1 (input_filename): The full path or relative path to the file. + + local input_filename=$1 + local dir="" + + dir=$(cd -- "$(dirname -- "$input_filename")" &>/dev/null && pwd) + + printf "%s" "$dir" +} + +_get_filename_extension() { + # This function extracts the file extension from a given filename. + # + # Parameters: + # - $1 (filename): The input filename (can be absolute or relative). + + local filename=$1 + filename=$(sed -E "s|.*/(\.)*||g" <<<"$filename") + filename=$(sed -E "s|^(\.)*||g" <<<"$filename") + + printf "%s" "$filename" | + grep --ignore-case --only-matching --perl-regexp \ + "(\.tar)?\.[a-z0-9_~-]{0,15}$" || true +} + +_get_filename_full_path() { + # This function returns the full absolute path of a given filename. + # + # Parameters: + # - $1 (input_filename): The input filename or relative path. + + local input_filename=$1 + local full_path=$input_filename + local dir="" + + if [[ $input_filename != "/"* ]]; then + dir=$(_get_filename_dir "$input_filename") + full_path=$dir/$(basename -- "$input_filename") + fi + + printf "%s" "$full_path" +} + +_get_filename_next_suffix() { + # This function generates a unique filename by adding a numeric suffix to + # the base filename if a file with the same name already exists. It ensures + # that the new filename does not overwrite an existing file. + # + # Parameters: + # - $1 (filename): The input filename or path. This can be an absolute or + # relative filename. If the input file has an extension, it will be + # stripped for the purpose of generating the new filename. + + local filename=$1 + local filename_result=$filename + local filename_base="" + local filename_extension="" + + # Directories do not have an extension. + if [[ -d "$filename" ]]; then + filename_base=$filename + else + filename_base=$(_strip_filename_extension "$filename") + filename_extension=$(_get_filename_extension "$filename") + fi + + # Avoid overwriting a file. If there is a file with the same name, + # try to add a suffix, as 'file (1)', 'file (2)', ... + local count=1 + while [[ -e "$filename_result" ]]; do + filename_result="$filename_base ($count)$filename_extension" + ((count++)) + done + + printf "%s" "$filename_result" +} + +_get_filenames_filemanager() { + # This function retrieves a list of selected filenames or URIs from a file + # manager (such as Caja, Nemo, or Nautilus) and processes the input + # accordingly. If no selection is detected, it falls back to using a + # standard input file list. + + local input_files="" + + # Try to use the information provided by the file manager. + if [[ -v "CAJA_SCRIPT_SELECTED_URIS" ]]; then + input_files=$CAJA_SCRIPT_SELECTED_URIS + elif [[ -v "NEMO_SCRIPT_SELECTED_URIS" ]]; then + input_files=$NEMO_SCRIPT_SELECTED_URIS + elif [[ -v "NAUTILUS_SCRIPT_SELECTED_URIS" ]]; then + input_files=$NAUTILUS_SCRIPT_SELECTED_URIS + fi + + if [[ -n "$input_files" ]]; then + # Replace '\n' with 'FIELD_SEPARATOR'. + input_files=$(_convert_text_to_delimited_string "$input_files") + + # Decode the URI list. + input_files=$(_text_uri_decode "$input_files") + else + input_files=$INPUT_FILES # Standard input. + input_files=$(_str_remove_empty_tokens "$input_files") + fi + + printf "%s" "$input_files" +} + +_get_files() { + # This function retrieves a list of files or directories based on the + # provided parameters and performs various filtering, validation, and + # sorting operations. The input files can be filtered by type, extension, + # mime type, etc. It also supports recursive directory expansion and + # validation of file conflicts. + # + # Parameters: + # - $1 (parameters): A string containing key-value pairs that configure + # the function's behavior. Example: 'par_type=file; par_min_items=2'. + # + # Parameters options: + # - "par_type": Specifies the type of items to filter: + # - "file" (default): Filters files. + # - "directory": Filters directories. + # - "all": Includes both files and directories. + # - "par_recursive": Specifies whether to expand directories recursively: + # - "false" (default): Does not expand directories. + # - "true": Expands directories recursively. + # - "par_get_pwd": If "true", returns the current working directory if no + # files are selected. + # - "par_max_items", "par_min_items": Limits the number of files. + # - "par_select_extension": Filters by file extension. + # - "par_select_mime": Filters by MIME type. + # - "par_skip_extension": Skips files with specific extensions. + # - "par_skip_encoding": Skips files with specific encodings. + # - "par_sort_list": If "true", sorts the list of files. + # - "par_validate_conflict": If "true", validates for filenames with the + # same base name. + + local parameters=$1 + local input_files="" + input_files=$(_get_filenames_filemanager) + + # Default values for input parameters. + local par_get_pwd="false" + local par_max_items="" + local par_min_items="" + local par_recursive="false" + local par_select_extension="" + local par_select_mime="" + local par_skip_encoding="" + local par_skip_extension="" + local par_sort_list="false" + local par_type="file" + local par_validate_conflict="" + + # Evaluate the values from the 'parameters' variable. + eval "$parameters" + + # Check if there are input files. + if (($(_get_items_count "$input_files") == 0)); then + if [[ "$par_get_pwd" == "true" ]]; then + # Return the current working directory if no files have been + # selected. + input_files=$(_get_working_directory) + else + # Try selecting the files by opening a file selection box. + if [[ "$par_type" == "directory" ]]; then + input_files=$(_display_dir_selection_box) + else + input_files=$(_display_file_selection_box) + fi + fi + fi + + # If the items are in a remote server, translate the addresses to 'gvfs'. + if [[ "$input_files" == *"://"* ]]; then + local working_directory="" + working_directory=$(_get_working_directory) + input_files=$(sed \ + "s|[a-z0-9\+_-]*://[^$FIELD_SEPARATOR]*/|$working_directory/|g" \ + <<<"$input_files") + fi + + local initial_items_count=0 + initial_items_count=$(_get_items_count "$input_files") + + local find_parameters="" + if ((initial_items_count == 1)) && [[ -d "$input_files" ]] && + [[ "$par_recursive" == "false" ]] && + printf "%s" "$(basename -- "$input_files")" | + grep --quiet --ignore-case --word-regexp "batch"; then + # This workaround allows the scripts to handle cases with a large input + # list of files. In this case, just select a single directory with a + # name that includes the word 'batch'. Then, the scripts operate on the + # files within the selected directory. This addresses the GNOME error: + # "Could not start application: Failed to execute child process + # "/bin/sh" (Argument list too long)". + find_parameters="-mindepth 1 -maxdepth 1" + elif [[ "$par_recursive" == "false" ]]; then + find_parameters="-maxdepth 0" + fi + + # Pre-select the input files. + input_files=$(_find_filtered_files \ + "$input_files" \ + "$par_type" \ + "$par_skip_extension" \ + "$par_select_extension" \ + "$find_parameters") + + # Return the current working directory if no directories have been + # selected. + if (($(_get_items_count "$input_files") == 0)); then + if [[ "$par_get_pwd" == "true" ]] && + [[ "$par_type" == "directory" ]]; then + input_files=$(_get_working_directory) + fi + fi + + # Validates the mime or encoding of the file. + if [[ -n "$par_select_mime" ]] || [[ -n "$par_skip_encoding" ]]; then + input_files=$(_validate_file_mime_parallel \ + "$input_files" \ + "$par_select_mime" \ + "$par_skip_encoding") + fi + + # Validates the number of valid files. + _validate_files_count \ + "$input_files" \ + "$par_type" \ + "$par_select_extension" \ + "$par_select_mime" \ + "$par_min_items" \ + "$par_max_items" \ + "$par_recursive" + + # Sort the list by filename. + if [[ "$par_sort_list" == "true" ]]; then + input_files=$(printf "%s" "$input_files" | tr "$FIELD_SEPARATOR" "\0" | + sort --zero-terminated --version-sort | tr "\0" "$FIELD_SEPARATOR") + input_files=$(_str_remove_empty_tokens "$input_files") + fi + + # Validates filenames with the same base name. + if [[ "$par_validate_conflict" == "true" ]]; then + _validate_conflict_filenames "$input_files" + fi + + printf "%s" "$input_files" +} + +_get_file_encoding() { + # This function retrieves the MIME encoding of a specified file. + # + # Parameters: + # - $1 (filename): The path to the file whose encoding is to be + # determined. + + local filename=$1 + local std_output="" + + std_output=$(file --dereference --brief --mime-encoding \ + -- "$filename" 2>/dev/null) + + if [[ "$std_output" == "cannot"* ]]; then + return + fi + + printf "%s" "$std_output" +} + +_get_file_mime() { + # This function retrieves the MIME type of a specified file. + # + # Parameters: + # - $1 (filename): The path to the file whose MIME is to be determined. + + local filename=$1 + local std_output="" + + std_output=$(file --dereference --brief --mime-type \ + -- "$filename" 2>/dev/null) + + if [[ "$std_output" == "cannot"* ]]; then + return + fi + + printf "%s" "$std_output" +} + +_get_items_count() { + # This function counts the number of items in a string, where items are + # separated by a specific field separator. It assumes that the input string + # contains a list of items separated by the value of the variable + # $FIELD_SEPARATOR. + # + # Parameters: + # - $1 (input_files): A string containing a list of items separated by + # the defined $FIELD_SEPARATOR. + + local input_files=$1 + local files_count=0 + + if [[ -n "$input_files" ]]; then + files_count=$(tr -cd "$FIELD_SEPARATOR" <<<"$input_files" | wc -c) + ((files_count++)) + fi + + printf "%s" "$files_count" +} + +_get_max_procs() { + # This function returns the maximum number of processing units (CPU cores) + # available on the system. + + nproc --all 2>/dev/null +} + +_get_output_dir() { + # This function determines and returns the appropriate output directory + # path based on the provided parameters and the system's available + # directories. + # + # Parameters: + # - $1 (parameters): A string containing key-value pairs that configure + # the function's behavior. Example: 'par_use_same_dir=true'. + # + # Parameters options: + # - "par_use_same_dir": If set to "true", the function uses the base + # directory (e.g., current working directory or an alternative with write + # permissions) as the output directory. If "false" or not set, a new + # subdirectory is created for the output. + + local parameters=$1 + local base_dir="" + local output_dir="" + + # Default values for input parameters. + local par_use_same_dir="" + + # Evaluate the values from the 'parameters' variable. + eval "$parameters" + + # Check directories available to put the 'output' dir. + base_dir=$(_get_working_directory) + [[ ! -w "$base_dir" ]] && base_dir=$HOME + [[ ! -w "$base_dir" ]] && base_dir="/tmp" + if [[ ! -w "$base_dir" ]]; then + _display_error_box "Could not find a directory with write permissions!" + _exit_script + fi + + if [[ "$par_use_same_dir" == "true" ]]; then + printf "%s" "$base_dir" + return + fi + + output_dir="$base_dir/$PREFIX_OUTPUT_DIR" + + # If the file already exists, add a suffix. + output_dir=$(_get_filename_next_suffix "$output_dir") + + mkdir --parents "$output_dir" + printf "%s" "$output_dir" +} + +_get_output_filename() { + # This function generates the output filename based on the given input + # file, output directory, and a set of optional parameters. It allows for + # customization of the output filename by adding prefixes, suffixes, and + # selecting how the file extension should be handled. + # + # Parameters: + # - $1 (input_file): The input file for which the output filename will be + # generated. + # - $2 (output_dir): The directory where the output file will be placed. + # - $3 (parameters): A string containing optional parameters that define + # how the output filename should be constructed. It supports the + # following options: + # - par_extension_opt: Specifies how to handle the file extension. + # Options are: + # - "append": Append a new extension "par_extension" to the existing + # file extension. + # - "preserve": Keep the original file extension. + # - "replace": Replace the current extension with a new one + # "par_extension". + # - "strip": Remove the file extension entirely. + # - par_extension: The extension to use when "par_extension_opt" is set + # to "append" or "replace". This value is ignored for the "preserve" + # and "strip" options. + # - par_prefix: A string to be added as prefix to the output filename. + # - par_suffix: A string to be added as suffix to the output + # filename, placed before the extension. + + local input_file=$1 + local output_dir=$2 + local parameters=$3 + local output_file="" + local filename="" + + # Default values for input parameters. + local par_extension_opt="preserve" + local par_extension="" + local par_prefix="" + local par_suffix="" + + # Evaluate the values from the 'parameters' variable. + eval "$parameters" + + filename=$(basename -- "$input_file") + + # Start constructing the output file path with the output directory. + output_file="$output_dir/" + [[ -n "$par_prefix" ]] && output_file+="$par_prefix " + + if [[ -d "$input_file" ]]; then + # Handle case where input_file is a directory. + case "$par_extension_opt" in + "append" | "replace") + output_file+=$filename + output_file+=".$par_extension" + ;; + "preserve" | "strip") + output_file+=$filename + ;; + esac + else + # Handle case where input_file is a regular file. + case "$par_extension_opt" in + "append") + # Append the new extension to the existing one. + output_file+=$(_strip_filename_extension "$filename") + [[ -n "$par_suffix" ]] && output_file+=" $par_suffix" + output_file+=$(_get_filename_extension "$filename") + output_file+=".$par_extension" + ;; + "preserve") + # Preserve the original extension. + output_file+=$(_strip_filename_extension "$filename") + [[ -n "$par_suffix" ]] && output_file+=" $par_suffix" + output_file+=$(_get_filename_extension "$filename") + ;; + "replace") + # Replace the existing extension with the new one. + output_file+=$(_strip_filename_extension "$filename") + [[ -n "$par_suffix" ]] && output_file+=" $par_suffix" + output_file+=".$par_extension" + ;; + "strip") + # Remove the extension. + output_file+=$(_strip_filename_extension "$filename") + [[ -n "$par_suffix" ]] && output_file+=" $par_suffix" + ;; + esac + fi + + # If the file already exists, add a suffix. + output_file=$(_get_filename_next_suffix "$output_file") + + printf "%s" "$output_file" +} + +_get_qdbus_command() { + # This function retrieves the first command matching the pattern "qdbus". + # The command may vary depending on the Linux distribution and could be + # "qdbus", "qdbus-qt6", "qdbus6", or similar variations. + # + # Returns: + # - "0" (true): If a command matching the pattern "qdbus" is found. + # - "1" (false): If no command matching the pattern "qdbus" is found. + + compgen -c | grep --perl-regexp -m1 "^qdbus" || return 1 + return 0 +} + +_get_script_name() { + # This function returns the name of the currently executing script. It uses + # the "basename" command to extract the script's filename from the full + # path provided by "$0". + + basename -- "$0" +} + +_get_temp_dir_local() { + # This function creates a temporary directory in a specified location and + # returns its path. The directory is created using "mktemp", with a custom + # prefix ("basename"). It also generates a temporary file to track the + # directory to be removed later. + # + # Parameters: + # - $1 (output_dir): The directory where the temporary directory will be + # created. + # - $2 (basename): The prefix for the temporary directory name. + # + # Output: + # - The full path to the newly created temporary directory. + + local output_dir=$1 + local basename=$2 + local temp_dir="" + temp_dir=$(mktemp --directory \ + --tmpdir="$output_dir" "$basename.XXXXXXXX.tmp") + + # Remember to remove this directory after exit. + item_to_remove=$(mktemp --tmpdir="$TEMP_DIR_ITEMS_TO_REMOVE") + printf "%s$FIELD_SEPARATOR" "$temp_dir" >"$item_to_remove" + + printf "%s" "$temp_dir" +} + +_get_temp_file() { + # This function creates a temporary file in a specified temporary directory + # and returns its path. The file is created using "mktemp", and the + # directory for the temporary file is specified by the $TEMP_DIR_TASK + # variable. + # + # Output: + # - The full path to the newly created temporary file. + + local temp_file="" + temp_file=$(mktemp --tmpdir="$TEMP_DIR_TASK") + + printf "%s" "$temp_file" +} + +_get_temp_file_dry() { + # This function simulates the creation of a temporary file in a specified + # directory without actually creating the file. It uses the "--dry-run" + # option with "mktemp", which allows checking what the file path would be + # if it were to be created. + # + # Output: + # - The path of the temporary file, without actually creating the file. + + local temp_file="" + temp_file=$(mktemp --dry-run --tmpdir="$TEMP_DIR_TASK") + + printf "%s" "$temp_file" +} + +_get_working_directory() { + # This function attempts to determine the current working directory in a + # variety of ways, based on the available environment variables or input + # files. It first checks if the file manager (e.g., Caja, Nemo, or + # Nautilus) provides the current URI (directory) of the script. If not, it + # falls back to other methods. If the working directory cannot be obtained + # from the file manager or input files, it defaults to the current + # directory. + # + # Output: + # - The determined working directory. + + local working_directory="" + + # Try to use the information provided by the file manager. + if [[ -v "CAJA_SCRIPT_CURRENT_URI" ]]; then + working_directory=$CAJA_SCRIPT_CURRENT_URI + elif [[ -v "NEMO_SCRIPT_CURRENT_URI" ]]; then + working_directory=$NEMO_SCRIPT_CURRENT_URI + elif [[ -v "NAUTILUS_SCRIPT_CURRENT_URI" ]]; then + working_directory=$NAUTILUS_SCRIPT_CURRENT_URI + fi + + if [[ -n "$working_directory" ]] && + [[ "$working_directory" == "file://"* ]]; then + working_directory=$(_text_uri_decode "$working_directory") + else + # Files selected in the search screen (or other possible cases). + working_directory="" + fi + + if [[ -z "$working_directory" ]]; then + # NOTE: The working directory can be detected by using the directory + # name of the first input file. Some file managers do not send the + # working directory for the scripts, so it is not precise to use the + # 'pwd' command. + local item_1="" + item_1=$(cut -d "$FIELD_SEPARATOR" -f 1 <<<"$INPUT_FILES") + + if [[ -n "$item_1" ]]; then + working_directory=$(_get_filename_dir "$item_1") + else + working_directory=$(pwd) + fi + fi + + printf "%s" "$working_directory" +} + +_is_directory_empty() { + # This function checks if a given directory is empty. + # + # Parameters: + # - $1 (directory): The path of the directory to check. + # + # Returns: + # - "0" (true): If the directory is empty. + # - "1" (false): If the directory contains any files or subdirectories. + + local directory=$1 + + if ! find "$directory" -mindepth 1 -maxdepth 1 -print -quit | + grep --quiet .; then + return 0 + fi + return 1 +} + +_is_gui_session() { + # This function checks whether the script is running in a graphical user + # interface (GUI) session. It does so by checking if the DISPLAY + # environment variable is set, which is typically present in GUI sessions + # (e.g., X11 or Wayland). + # + # Returns: + # - "0" (true): If is a GUI session. + # - "1" (false): If is not a GUI session. + + if env | grep --quiet "^DISPLAY"; then + return 0 + fi + return 1 +} + +_log_error() { + # This function writes an error log entry with a specified message, + # including details such as the input file, output file, and terminal + # output. The entry is saved to a temporary log file. + # + # Parameters: + # - $1 (message): The error message to be logged. + # - $2 (input_file): The path of the input file associated with the + # operation. + # - $3 (std_output): The standard output or result from the operation + # that will be logged. + # - $4 (output_file): The path of the output file associated with the + # operation. + + local message=$1 + local input_file=$2 + local std_output=$3 + local output_file=$4 + + local log_temp_file="" + log_temp_file=$(mktemp --tmpdir="$TEMP_DIR_LOGS") + + { + printf "[%s]\n" "$(date "+%Y-%m-%d %H:%M:%S")" + if [[ -n "$input_file" ]]; then + printf " > Input file: %s\n" "$input_file" + fi + if [[ -n "$output_file" ]]; then + printf " > Output file: %s\n" "$output_file" + fi + printf " > %s\n" "Error: $message" + if [[ -n "$std_output" ]]; then + printf " > Standard output:\n" + printf "%s\n" "$std_output" + fi + printf "\n" + } >"$log_temp_file" +} + +_logs_consolidate() { + # This function gathers all error logs from a temporary directory and + # compiles them into a single consolidated log file. If any error logs are + # found, it displays an error message indicating the location of the + # consolidated log file and terminates the script. + # + # Parameters: + # $1 (output_dir): Optional. The directory where the consolidated log + # file will be saved. If not specified, a default directory is used. + + local output_dir=$1 + local log_file_output="$output_dir/$PREFIX_ERROR_LOG_FILE.log" + local log_files_count="" + + # Do nothing if there are no error log files. + log_files_count="$(find "$TEMP_DIR_LOGS" -type f 2>/dev/null | wc -l)" + if ((log_files_count == 0)); then + return 0 + fi + + if [[ -z "$output_dir" ]]; then + output_dir=$(_get_output_dir "par_use_same_dir=true") + fi + log_file_output="$output_dir/$PREFIX_ERROR_LOG_FILE.log" + + # If the file already exists, add a suffix. + log_file_output=$(_get_filename_next_suffix "$log_file_output") + + # Compile log errors in a single file. + { + printf "Script: '%s'.\n" "$(_get_script_name)" + printf "Total errors: %s.\n\n" "$log_files_count" + cat -- "$TEMP_DIR_LOGS/"* 2>/dev/null + } >"$log_file_output" + + local log_file="" + log_file=$(_str_human_readable_path "$log_file_output") + _display_error_box "Finished with errors! See the $log_file for details." + + _exit_script +} + +_move_file() { + # This function moves a file from the source location to the destination, + # with options to handle conflicts when the destination file already + # exists. + # + # Parameters: + # - $1 (par_when_conflict): Optional, default: "skip". Defines the + # behavior when the destination file already exists. + # - "overwrite": Overwrite the destination file. + # - "rename": Rename the source file to avoid conflicts by adding a + # suffix to the destination filename. + # - "skip": Skip moving the file if the destination file exists (logs a + # error). + # - $2 (file_src): The path to the source file to be moved. + # - $3 (file_dst): The destination path where the file should be moved. + # + # Returns: + # - "0" (true): If the operation is successful or if the source and + # destination are the same file. + # - "1" (false): If any required parameters are missing, if the move + # fails, or if an invalid conflict parameter is provided. + + local par_when_conflict=${1:-"skip"} + local file_src=$2 + local file_dst=$3 + + # Check for empty parameters. + if [[ -z "$file_src" ]] || [[ -z "$file_dst" ]]; then + return 1 + fi + + # Add the './' prefix in the path. + if [[ ! "$file_src" == "/"* ]] && + [[ ! "$file_src" == "./"* ]] && [[ ! "$file_src" == "." ]]; then + file_src="./$file_src" + fi + if [[ ! "$file_dst" == "/"* ]] && + [[ ! "$file_dst" == "./"* ]] && [[ ! "$file_dst" == "." ]]; then + file_dst="./$file_dst" + fi + + # Ignore moving to the same file. + if [[ "$file_src" == "$file_dst" ]]; then + return 0 + fi + + # Process the parameter "when_conflict": what to do when the 'file_dst' + # already exists. + case "$par_when_conflict" in + "overwrite") + mv -f -- "$file_src" "$file_dst" 2>/dev/null + ;; + "rename") + # Rename the file (add a suffix). + file_dst=$(_get_filename_next_suffix "$file_dst") + mv -n -- "$file_src" "$file_dst" 2>/dev/null + ;; + "skip") + # Do not move the file if the destination file already exists. + mv -n -- "$file_src" "$file_dst" 2>/dev/null + ;; + esac + + if [[ -e "$file_src" ]]; then + if [[ -e "$file_dst" ]]; then + _log_error "The destination file already exists." \ + "$file_src" "" "$file_dst" + else + _log_error "Unable to move." \ + "$file_src" "" "$file_dst" + fi + return 1 + fi + + return 0 +} + +_move_temp_file_to_output() { + # This function moves a temporary file to a specified output location, + # handling various conditions to ensure the move is safe and proper. + # + # Parameters: + # - $1 (input_file): The path to the original input file, which may be + # backed up during the process. + # - $2 (temp_file): The temporary file to be moved to the output + # location. + # - $3 (output_file): The target path where the temp file should be + # moved. + + local input_file=$1 + local temp_file=$2 + local output_file=$3 + local std_output="" + + # Skip empty files. + if [[ ! -s "$temp_file" ]]; then + return 1 + fi + + # Skip files if the content of 'temp_file' is equal to the 'input_file'. + if cmp --silent -- "$temp_file" "$input_file"; then + return 1 + fi + + # If 'input_file' equals 'output_file', create a backup of 'input_file'. + if [[ "$input_file" == "$output_file" ]]; then + _move_file "rename" "$input_file" "$input_file.bak" || return 1 + fi + + # Move the 'temp_file' to 'output_file'. + _move_file "rename" "$temp_file" "$output_file" || return 1 + + # Preserve the same permissions of 'input_file'. + std_output=$(chmod --reference="$input_file" -- "$output_file" 2>&1) + _check_output "$?" "$std_output" "$input_file" "$output_file" || return 1 + + return 0 +} + +_open_items_locations() { + # This function opens the locations of selected items in the appropriate + # file manager. + # + # Parameters: + # - $1 (items): A space-separated list of file or directory paths whose + # locations will be opened. Paths can be relative or absolute. + # - $2 (resolve_links): A boolean-like string ("true" or "false") + # indicating whether symbolic links in the provided paths should be + # resolved to their target locations before opening. + + local items=$1 + local resolve_links=$2 + + # Exit if no items are provided. + if [[ -z "$items" ]]; then + return + fi + + # Detect the currently running file manager. + local file_manager="" + if [[ -v "CAJA_SCRIPT_SELECTED_URIS" ]]; then + file_manager="caja" + elif [[ -v "NEMO_SCRIPT_SELECTED_URIS" ]]; then + file_manager="nemo" + elif [[ -v "NAUTILUS_SCRIPT_SELECTED_URIS" ]]; then + file_manager="nautilus" + else + file_manager=$(pgrep -o -l \ + "caja|dolphin|nautilus|nemo|pcmanfm|pcmanfm-qt|thunar" | + cut -f 2 -d " ") + + # If no file manager is detected, fall back to the system default. + if [[ -z "$file_manager" ]]; then + file_manager=$(_xdg_get_default_app "inode/directory") + fi + fi + + # Restore absolute paths for items if relative paths are used. + local working_directory="" + working_directory=$(_get_working_directory) + items=$(sed "s|\./|$working_directory/|g" <<<"$items") + + # Prepare items to be opened by the file manager. + local items_open="" + local item="" + for item in $items; do + # Skip the root directory ("/") since opening it is redundant. + if [[ "$item" == "/" ]]; then + continue + fi + + # Resolve symbolic links to their target locations if requested. + if [[ "$resolve_links" == "true" ]] && [[ -L "$item" ]]; then + item=$(readlink -f "$item") + fi + items_open+="$item$FIELD_SEPARATOR" + done + + # Remove the trailing field separator. + items_open=$(_str_remove_empty_tokens "$items_open") + + # Open the items using the detected file manager. + case "$file_manager" in + "nautilus" | "caja" | "dolphin") + # Open the directory of each item and select it. + # shellcheck disable=SC2086 + $file_manager --select $items_open & + ;; + "nemo" | "thunar") + # Open the directory of each item (selection not supported). + # shellcheck disable=SC2086 + $file_manager $items_open & + ;; + *) + # For other file managers (e.g., "pcmanfm-qt"), open the directory of + # each item. + local dir="" + for item in $items_open; do + # Open the directory of the item. + dir=$(_get_filename_dir "$item") + if [[ -z "$dir" ]]; then + continue + fi + $file_manager "$dir" & + done + ;; + esac +} + +_pkg_get_package_manager() { + # This function detects and returns the name of the package manager + # available on the system. + # + # Output: + # - Prints the name of the detected package manager. Possible values are: + # - "apt": Indicates that "apt-get" (Debian/Ubuntu) is available. + # - "dnf": Indicates that "dnf" (Fedora/RHEL) is available. + # - "pacman": Indicates that "pacman" (Arch Linux) is available. + # - "zypper": Indicates that "zypper" (openSUSE) is available. + # - If no supported package manager is found, the output is an empty + # string. + + local pkg_manager="" + + # Check for an installed package manager. + if _command_exists "apt-get"; then + pkg_manager="apt" + elif _command_exists "dnf"; then + pkg_manager="dnf" + elif _command_exists "pacman"; then + pkg_manager="pacman" + elif _command_exists "zypper"; then + pkg_manager="zypper" + fi + + printf "%s" "$pkg_manager" +} + +_pkg_install_packages() { + # This function installs specified packages using the given package + # manager. + # + # Parameters: + # - $1 (pkg_manager): The package manager to use for installation. + # Supported values are: + # - "apt": For Debian/Ubuntu systems. + # - "dnf": For Fedora/RHEL systems. + # - "pacman": For Arch Linux systems. + # - "zypper": For openSUSE systems. + # - $2 (packages): A space-separated list of package names to install. + + local pkg_manager=$1 + local packages=$2 + + _display_wait_box_message "Installing the packages. Please, wait..." + + # Install the packages. + if ! _command_exists "pkexec"; then + _display_error_box \ + "Could not run the installer with administrator permission!" + _exit_script + fi + + case "$pkg_manager" in + "apt") + pkexec bash -c \ + "apt-get update; apt-get -y install $packages &>/dev/null" + ;; + "dnf") + pkexec bash -c \ + "dnf check-update; dnf -y install $packages &>/dev/null" + ;; + "pacman") + pkexec bash -c \ + "pacman -Syy; pacman --noconfirm -S $packages &>/dev/null" + ;; + "zypper") + pkexec bash -c \ + "zypper refresh; zypper --non-interactive install $packages &>/dev/null" + ;; + esac + + _close_wait_box + + # Check if all packages were installed. + packages=$(tr " " "$FIELD_SEPARATOR" <<<"$packages") + local package="" + for package in $packages; do + if ! _pkg_is_package_installed "$pkg_manager" "$package"; then + _display_error_box "Could not install the package '$package'!" + _exit_script + fi + done + + _display_info_box "The packages have been successfully installed!" +} + +_pkg_is_package_installed() { + # This function checks if a specific package is installed using the given + # package manager. + # + # Parameters: + # - $1 (pkg_manager): The package manager to use for the check. + # Supported values are: + # - "apt": For Debian/Ubuntu systems. + # - "dnf": For Fedora/RHEL systems. + # - "pacman": For Arch Linux systems. + # - "zypper": For openSUSE systems. + # - $2 (package): The name of the package to check. + # + # Returns: + # - "0" (true): If the package is installed. + # - "1" (false): If the package is not installed or an error occurs. + + local pkg_manager=$1 + local package=$2 + + case "$pkg_manager" in + "apt") + if dpkg -s "$package" &>/dev/null; then + return 0 + fi + ;; + "dnf") + if dnf repoquery --installed | grep --quiet "$package"; then + return 0 + fi + ;; + "pacman") + if pacman -Q "$package" &>/dev/null; then + return 0 + fi + ;; + "zypper") + if zypper search --installed-only "$package" | grep --quiet "^i"; then + return 0 + fi + ;; + esac + return 1 +} + +_recent_scripts_organize() { + # This function organizes the directory containing recently accessed + # scripts ('ACCESSED_RECENTLY_DIR'). This function manages symbolic links + # in the directory by: + # 1. Keeping only the 'ACCESSED_RECENTLY_LINKS_TO_KEEP' most recently + # accessed scripts. + # 2. Renaming retained links with numeric prefixes (e.g., "01", "02") to + # maintain chronological order. + + local links=() + local link="" + while IFS= read -r -d $'\0' link; do + # Check if the link is broken. + if [[ ! -e "$link" ]]; then + # Remove broken links. + rm -f -- "$link" + else + links+=("$link") + fi + done < <( + find "$ACCESSED_RECENTLY_DIR" -maxdepth 1 -type l -print0 2>/dev/null | + sort --zero-terminated --numeric-sort + ) + + # Process the links, keeping only the 'ACCESSED_RECENTLY_LINKS_TO_KEEP' + # most recent. + local count=1 + local link_name="" + for link in "${links[@]}"; do + if ((count <= ACCESSED_RECENTLY_LINKS_TO_KEEP)); then + # Rename the link with a numeric prefix for ordering. + link_name=$(basename "$link" | + sed --regexp-extended 's|^.?[0-9]{2} ||') + mv -f -- "$link" \ + "$ACCESSED_RECENTLY_DIR/$(printf '%02d' "$count") $link_name" \ + 2>/dev/null + ((count++)) + else + # Remove excess links. + rm -f -- "$link" + fi + done +} + +_recent_scripts_add() { + # This function adds the running script to the history of recently accessed + # scripts ('ACCESSED_RECENTLY_DIR'). + + local running_script=$0 + if [[ "$0" != "/"* ]]; then + # If $0 is a relative path, resolve it relative to the current working + # directory. + running_script="$SCRIPT_DIR/"$(basename -- "$0") + fi + + # Resolve symbolic links to their target locations. + if [[ -L "$running_script" ]]; then + running_script=$(readlink -f "$running_script") + fi + + # Create 'ACCESSED_RECENTLY_DIR' if it does not exist. + if [[ ! -d $ACCESSED_RECENTLY_DIR ]]; then + mkdir -p "$ACCESSED_RECENTLY_DIR" + fi + + _directory_push "$ACCESSED_RECENTLY_DIR" || return 1 + + # Remove any existing links pointing to the same script. + find "$ACCESSED_RECENTLY_DIR" -lname "$running_script" \ + -exec rm -f -- "{}" + + + # Create a new symbolic link with a ".00" prefix. + ln -s -- "$running_script" ".00 $(basename -- "$running_script")" + + _directory_pop || return 1 +} + +_run_task_parallel() { + # This function runs a task in parallel for a set of input files, using a + # specified output directory for results. + # + # Parameters: + # - $1 (input_files): A field-separated list of file paths to process. + # - $2 (output_dir): The directory where the output files will be stored. + + local input_files=$1 + local output_dir=$2 + + # Export variables to be used inside new shells (when using 'xargs'). + export \ + FIELD_SEPARATOR \ + GUI_BOX_HEIGHT \ + GUI_BOX_WIDTH \ + GUI_INFO_WIDTH \ + IGNORE_FIND_PATH \ + INPUT_FILES \ + TEMP_DATA_TASK \ + TEMP_DIR_ITEMS_TO_REMOVE \ + TEMP_DIR_LOGS \ + TEMP_DIR_STORAGE_TEXT \ + TEMP_DIR_TASK + + # Export functions to be used inside new shells (when using 'xargs'). + export -f \ + _check_output \ + _command_exists \ + _convert_delimited_string_to_text \ + _convert_text_to_delimited_string \ + _directory_pop \ + _directory_push \ + _display_password_box \ + _exit_script \ + _get_file_encoding \ + _get_file_mime \ + _get_filename_dir \ + _get_filename_extension \ + _get_filename_full_path \ + _get_filename_next_suffix \ + _get_max_procs \ + _get_output_filename \ + _get_temp_dir_local \ + _get_temp_file \ + _get_temp_file_dry \ + _get_working_directory \ + _is_directory_empty \ + _is_gui_session \ + _log_error \ + _main_task \ + _move_file \ + _move_temp_file_to_output \ + _storage_text_write \ + _storage_text_write_ln \ + _str_remove_empty_tokens \ + _strip_filename_extension \ + _text_remove_pwd \ + _text_uri_decode + + # Escape single quotes in filenames to handle them correctly in 'xargs' + # with 'bash -c'. + input_files=$(sed -z "s|'|'\\\''|g" <<<"$input_files") + + printf "%s" "$input_files" | xargs \ + --no-run-if-empty \ + --delimiter="$FIELD_SEPARATOR" \ + --max-procs="$(_get_max_procs)" \ + --replace="{}" \ + bash -c "_main_task '{}' '$output_dir'" +} + +_storage_text_clean() { + # This function clears all temporary text storage files. + + rm -f -- "$TEMP_DIR_STORAGE_TEXT/"* &>/dev/null +} + +_storage_text_read_all() { + # This function concatenates and outputs the content of all temporary text + # storage files. + + cat -- "$TEMP_DIR_STORAGE_TEXT/"* 2>/dev/null +} + +_storage_text_write() { + # This function writes a given input text to temporary text storage files. + # + # Parameters: + # - $1 (input_text): The text to be stored in a temporary file. + + local input_text=$1 + local temp_file="" + + if [[ -z "$input_text" ]] || [[ "$input_text" == $'\n' ]]; then + return + fi + + # Save the text to be compiled into a single file. + temp_file=$(mktemp --tmpdir="$TEMP_DIR_STORAGE_TEXT") + printf "%s" "$input_text" >"$temp_file" +} + +_storage_text_write_ln() { + # This function writes a given input text, followed by a newline character, + # to a temporary text storage file. + + local input_text=$1 + + if [[ -z "$input_text" ]]; then + return + fi + + _storage_text_write "$input_text"$'\n' +} + +_str_human_readable_path() { + # This function transforms a given file path into a more human-readable + # format. + # + # Parameters: + # - $1 (input_path): The input file path to process. + + local input_path=$1 + local output_path="" + + output_path=$(_text_remove_pwd "$input_path") + output_path=$(_text_remove_home "$output_path") + output_path=$(sed "s|^\./||g" <<<"$output_path") + + if [[ "$output_path" == "." ]]; then + output_path="same" + elif [[ "$output_path" == "~" ]]; then + output_path="home" + elif [[ "$output_path" == "" ]]; then + output_path="(none)" + else + output_path="'$output_path'" + fi + + printf "%s" "$output_path" +} + +_str_remove_empty_tokens() { + # This function removes empty tokens from a string, ensuring it is compact + # and well-formed. + # + # Parameters: + # - $1 (input_str): The input string containing tokens separated by + # $FIELD_SEPARATOR. + + local input_str=$1 + input_str=$(tr -s "$FIELD_SEPARATOR" <<<"$input_str") + input_str=$(sed "s|$FIELD_SEPARATOR$||" <<<"$input_str") + + printf "%s" "$input_str" +} + +_strip_filename_extension() { + # This function removes the file extension from a given filename, if one + # exists. + # + # Parameters: + # - $1 (filename): The filename from which to strip the extension. + # + # Returns: + # - The filename without its extension. + + local filename=$1 + local extension="" + extension=$(_get_filename_extension "$filename") + + if [[ -z "$extension" ]]; then + printf "%s" "$filename" + return 0 + fi + + local len_extension=${#extension} + printf "%s" "${filename::-len_extension}" +} + +_text_remove_empty_lines() { + local input_text=$1 + + grep -v "^\s*$" <<<"$input_text" || true +} + +_text_remove_home() { + # This function replaces the user's home directory path in a given string + # with the tilde ("~") symbol for brevity. + # + # Parameters: + # - $1 (input_text): The input string that may contain the user's home + # directory path. + # + # Returns: + # - The modified string with the home directory replaced by "~", or the + # original string if "$HOME" is not defined. + # + # Examples: + # - Input: "/home/user/documents/file.txt" (assuming $HOME is + # "/home/user") + # - Output: "~/documents/file.txt" + # + # - Input: "/etc/config" (assuming $HOME is "/home/user") + # - Output: "/etc/config" + + local input_text=$1 + + if [[ -n "$HOME" ]]; then + sed "s|$HOME|~|g" <<<"$input_text" + else + printf "%s" "$input_text" + fi +} + +_text_remove_pwd() { + # This function replaces the current working directory path in a given + # string with a dot (".") for brevity. + # + # Parameters: + # - $1 (input_text): The input string that may contain the current + # working directory path. + # + # Returns: + # - The modified string with the working directory replaced by ".", or + # the original string if the working directory is not found. + # + # Examples: + # - Input: "/home/user/project/file.txt" (assuming current directory is + # "/home/user/project") + # - Output: "./file.txt" + # + # - Input: "/etc/config" (assuming current directory is + # "/home/user/project") + # - Output: "/etc/config" + + local input_text=$1 + local working_directory="" + working_directory=$(_get_working_directory) + + if [[ "$working_directory" != "/" ]]; then + sed "s|$working_directory|.|" <<<"$input_text" + else + printf "%s" "$input_text" + fi +} + +_text_sort() { + # This function sorts the lines of a given text input in a version-aware + # manner. + # + # Parameters: + # - $1 (input_text): The input text to be sorted, where each line is + # treated as a separate string. + # + # Returns: + # - The sorted text with each line in the correct order. + + local input_text=$1 + + sort --version-sort <<<"$input_text" +} + +_text_uri_decode() { + # This function decodes a URI-encoded string by converting percent-encoded + # characters back to their original form. + # + # Parameters: + # - $1 (uri_encoded): The URI-encoded string that needs to be decoded. + # + # Returns: + # - The decoded URI string, with percent-encoded characters replaced and + # the "file://" prefix removed. + # + # Example: + # - Input: "file:///home/user%20name/file%20name.txt" + # - Output: "/home/user name/file name.txt" + + local uri_encoded=$1 + + uri_encoded=${uri_encoded//%/\\x} + uri_encoded=${uri_encoded//file:\/\//} + + # shellcheck disable=SC2059 + printf "$uri_encoded" +} + +_unset_global_variables_file_manager() { + # This function unset global variables that may have been set by different + # file managers (Caja, Nautilus, Nemo) during script execution. + + unset \ + CAJA_SCRIPT_CURRENT_URI \ + CAJA_SCRIPT_NEXT_PANE_CURRENT_URI \ + CAJA_SCRIPT_NEXT_PANE_SELECTED_FILE_PATHS \ + CAJA_SCRIPT_NEXT_PANE_SELECTED_URIS \ + CAJA_SCRIPT_SELECTED_FILE_PATHS \ + CAJA_SCRIPT_SELECTED_URIS \ + CAJA_SCRIPT_WINDOW_GEOMETRY \ + NAUTILUS_SCRIPT_CURRENT_URI \ + NAUTILUS_SCRIPT_NEXT_PANE_CURRENT_URI \ + NAUTILUS_SCRIPT_NEXT_PANE_SELECTED_FILE_PATHS \ + NAUTILUS_SCRIPT_NEXT_PANE_SELECTED_URIS \ + NAUTILUS_SCRIPT_SELECTED_FILE_PATHS \ + NAUTILUS_SCRIPT_SELECTED_URIS \ + NAUTILUS_SCRIPT_WINDOW_GEOMETRY \ + NEMO_SCRIPT_CURRENT_URI \ + NEMO_SCRIPT_NEXT_PANE_CURRENT_URI \ + NEMO_SCRIPT_NEXT_PANE_SELECTED_FILE_PATHS \ + NEMO_SCRIPT_NEXT_PANE_SELECTED_URIS \ + NEMO_SCRIPT_SELECTED_FILE_PATHS \ + NEMO_SCRIPT_SELECTED_URIS \ + NEMO_SCRIPT_WINDOW_GEOMETRY +} + +_validate_conflict_filenames() { + # This function checks if there are any files with the same base name in + # the provided list of input files. + # + # Parameters: + # - $1 (input_files): A string containing a list of file paths, where + # each file path can include extensions. This list is checked for + # duplicates based on the base file name (excluding extensions). + # + # Example: + # - Input: "file1.txt file2.txt file1.jpg" + # - Output: An error box will be displayed indicating that "file1" is + # duplicated. + + local input_files=$1 + local filenames="" + + filenames=$(printf "%s" "$input_files" | tr "$FIELD_SEPARATOR" "\0" | + sed -z "s|/\.|//|" | # Ignore hidden files without extension. + sed -z --regexp-extended \ + "s|(\.tar)?\.[a-z0-9_~-]{0,15}$||I" | # Remove file extensions. + sort --zero-terminated --version-sort | # Sort files. + uniq --zero-terminated --repeated | # Find duplicate base names. + tr "\0" "$FIELD_SEPARATOR") + + # If duplicates are found, display an error and exit the script. + if [[ -n "$filenames" ]]; then + local basenames="" + # shellcheck disable=SC2086 + basenames=$(basename --multiple -- $filenames) + _display_error_box \ + "There are selected files with the same base name:\n$basenames" + _exit_script + fi +} + +_validate_file_mime() { + # This function validates the MIME type and optionally the encoding of a + # given file. It checks whether the file's MIME type matches a specified + # pattern (regex) and, if provided, whether the file's encoding matches + # another specified pattern. + # + # Parameters: + # - $1 (input_file): The path to the file that is being validated. This + # is the file whose MIME type will be checked. + # - $2 (par_select_mime): A MIME type pattern (or regular expression) + # used to validate the file's MIME type. If this parameter is empty, + # MIME type validation is skipped. + # - $3 (par_skip_encoding): An optional encoding pattern (or regular + # expression) used to validate the file's encoding. If this parameter + # is empty, encoding validation is skipped. + + local input_file=$1 + local par_select_mime=$2 + local par_skip_encoding=$3 + + # Validate MIME type if a pattern is provided. + if [[ -n "$par_select_mime" ]]; then + local file_mime="" + file_mime=$(_get_file_mime "$input_file") + par_select_mime=${par_select_mime//+/\\+} + grep --quiet --ignore-case --perl-regexp \ + "($par_select_mime)" <<<"$file_mime" || return + fi + + # Validate encoding if a pattern is provided. + if [[ -n "$par_skip_encoding" ]]; then + local file_encoding="" + file_encoding=$(_get_file_encoding "$input_file") + par_skip_encoding=${par_skip_encoding//+/\\+} + grep --quiet --ignore-case --perl-regexp \ + "($par_skip_encoding)" <<<"$file_encoding" && return + fi + + # Create a temp file containing the name of the valid file. + _storage_text_write "$input_file$FIELD_SEPARATOR" +} + +_validate_file_mime_parallel() { + # This function validates the MIME types of multiple files in parallel, + # based on a specified MIME type pattern. It processes a list of file paths + # concurrently using `xargs` and calls the `_validate_file_mime` function + # for each file. + # + # Parameters: + # - $1 (input_files): A space-separated string containing the paths of + # the files to validate. These files will be checked for the MIME type + # pattern. + # - $2 (par_select_mime): The MIME type pattern (or regular expression) + # used to validate the files' MIME types. If this parameter is empty, + # no MIME type validation is performed, and all input files are + # returned as valid. + # - $3 (par_skip_encoding): An optional encoding pattern (or regular + # expression) used to validate the files' encodings. If this + # parameter is empty, no encoding validation is performed. + # + # Example: + # - Input: File paths "file1.txt file2.png", MIME pattern "text/plain". + # - Output: If "file1.txt" has a MIME type of "text/plain", it will be + # included in the output, but "file2.png" will be excluded if its MIME + # type doesn't match. + + local input_files=$1 + local par_select_mime=$2 + local par_skip_encoding=$3 + + # Export variables to be used inside new shells (when using 'xargs'). + export FIELD_SEPARATOR TEMP_DIR_STORAGE_TEXT + + # Export functions to be used inside new shells (when using 'xargs'). + export -f \ + _get_file_encoding \ + _get_file_mime \ + _storage_text_write \ + _validate_file_mime + + # Escape single quotes in filenames to handle them correctly in 'xargs' + # with 'bash -c'. + input_files=$(sed -z "s|'|'\\\''|g" <<<"$input_files") + + # Execute the function '_validate_file_mime' for each file in parallel + # (using 'xargs'). + printf "%s" "$input_files" | xargs \ + --no-run-if-empty \ + --delimiter="$FIELD_SEPARATOR" \ + --max-procs="$(_get_max_procs)" \ + --replace="{}" \ + bash -c \ + "_validate_file_mime '{}' '$par_select_mime' '$par_skip_encoding'" + + # Compile valid files in a single list. + input_files=$(_storage_text_read_all) + _storage_text_clean + + input_files=$(_str_remove_empty_tokens "$input_files") + printf "%s" "$input_files" +} + +_validate_files_count() { + # This function validates the number of selected files or directories based + # on several criteria, such as type, extension, MIME type, and minimum or + # maximum item count. + # + # Parameters: + # - $1 (input_files): A space-separated string containing the paths of + # files or directories to be validated. + # - $2 (par_type): A string indicating the type of items to validate. + # Possible values: + # - "file": Validate files only. + # - "directory": Validate directories only. + # - "all": Validate both files and directories. + # - $3 (par_select_extension): A pipe-separated list of file extensions + # to filter the files. Files must have one of these extensions. + # - $4 (par_select_mime): A string representing MIME types to filter the + # files by. Only files with matching MIME types are selected. + # - $5 (par_min_items): The minimum number of valid items required. If + # fewer valid items are selected, an error is displayed. + # - $6 (par_max_items): The maximum number of valid items allowed. If + # more valid items are selected, an error is displayed. + # - $7 (par_recursive): A string indicating whether the validation should + # be recursive. If "true", directories will be searched recursively. + # + # Example: + # - Input: "dir1 dir2", "file", "txt|pdf", "", 1, 5, "true" + # - Output: The function checks if the directories "dir1" and "dir2" + # contain at least 1 and no more than 5 ".txt" or ".pdf" files, + # recursively. + + local input_files=$1 + local par_type=$2 + local par_select_extension=$3 + local par_select_mime=$4 + local par_min_items=$5 + local par_max_items=$6 + local par_recursive=$7 + + # Define a label for a valid file. + local valid_file_label="valid files" + if [[ "$par_type" == "directory" ]]; then + valid_file_label="directories" + elif [[ -n "$par_select_mime" ]]; then + valid_file_label="$par_select_mime" + valid_file_label=$(sed "s|\|| or |g" <<<"$par_select_mime") + valid_file_label=$(sed "s|/$||g; s|/ | |g" <<<"$valid_file_label") + valid_file_label+=" files" + elif [[ "$par_type" == "file" ]]; then + valid_file_label="files" + elif [[ "$par_type" == "all" ]]; then + valid_file_label="files or directories" + fi + + # Count the number of valid files. + local valid_items_count=0 + valid_items_count=$(_get_items_count "$input_files") + + # Define a label for the extension. + local extension_label="" + if [[ -n "$par_select_extension" ]]; then + extension_label="'.${par_select_extension//|/\' or \'.}'" + fi + + # Check if there is at least one valid file. + if ((valid_items_count == 0)); then + if [[ "$par_recursive" == "true" ]]; then + if [[ -n "$par_select_extension" ]]; then + _display_error_box \ + "No files with extension: $extension_label were selected!" + else + _display_error_box "No $valid_file_label were selected!" + fi + else + if [[ -n "$par_select_extension" ]]; then + _display_error_box \ + "You must select files with extension: $extension_label!" + else + _display_error_box "You must select $valid_file_label!" + fi + fi + _exit_script + fi + + if [[ -n "$par_min_items" ]] && ((valid_items_count < par_min_items)); then + _display_error_box \ + "You must select at least $par_min_items $valid_file_label!" + _exit_script + fi + + if [[ -n "$par_max_items" ]] && ((valid_items_count > par_max_items)); then + _display_error_box \ + "You must select up to $par_max_items $valid_file_label!" + _exit_script + fi +} + +_xdg_get_default_app() { + # This function retrieves the default application associated with a + # specific MIME type on a Linux system using the "xdg-mime" command. + # + # Parameters: + # - $1 (mime): The MIME type (e.g., "application/pdf", "image/png") for + # which to find the default application. + # + # Example: + # - Input: "application/pdf" + # - Output: The function prints the default application's executable for + # opening PDF files (e.g., "evince" or "okular"). + + local mime=$1 + local desktop_file="" + local default_app="" + + desktop_file=$(xdg-mime query default "$mime" 2>/dev/null) + + default_app=$(grep -m1 "^Exec" "/usr/share/applications/$desktop_file" | + sed "s|Exec=||g" | cut -d " " -f 1) + + if [[ -z "$default_app" ]]; then + _display_error_box \ + "Could not find the default application to open '$mime' files!" + _exit_script + fi + + printf "%s" "$default_app" +} + +# Execute functions to organize the recently accessed scripts. +_recent_scripts_add +_recent_scripts_organize diff --git a/.local/share/nautilus/scripts/invert picture vertically b/.local/share/nautilus/scripts/invert picture vertically new file mode 100755 index 0000000..1caacab --- /dev/null +++ b/.local/share/nautilus/scripts/invert picture vertically @@ -0,0 +1,3 @@ +#!/bin/bash + +mogrify -flip "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" diff --git a/.local/share/nautilus/scripts/ncdu_open b/.local/share/nautilus/scripts/ncdu_open new file mode 100755 index 0000000..7bcd2d0 --- /dev/null +++ b/.local/share/nautilus/scripts/ncdu_open @@ -0,0 +1,4 @@ +#!/bin/bash + +# alacritty -e ncdu_open "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" +alacritty -e ncdu_open "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS"