Skip to content

Instantly share code, notes, and snippets.

@oskopek
Last active May 10, 2017 10:43
Show Gist options
  • Save oskopek/cca1a553c612e24f8326e6bc0b5d84f7 to your computer and use it in GitHub Desktop.
Save oskopek/cca1a553c612e24f8326e6bc0b5d84f7 to your computer and use it in GitHub Desktop.
SIS txt file conversion script
#!/bin/bash
# Author: Ondrej Skopek <oskopek@oskopek.com>
# License: MIT <https://opensource.org/licenses/MIT>
#
# Run this script using no parameters, or a single parameter (the root directory you wish to convert)
# NOTE: This script might irreversibly damage your files. Please, back up your files.
# NOTE 2: If you find any bugs, please report/fix them at:
# https://gist.github.com/oskopek/cca1a553c612e24f8326e6bc0b5d84f7
set -e
root_dir="$1"
if [ -z "$root_dir" ]; then
root_dir="." # root directory to recursively convert
fi
whitelist="pdf jpg wav wave mp3 vob mp4 csv xml txt" # whitelist of all file endings
uninstall_file="sis-unconvert.sh.txt"
uninstall_file_win="sis-unconvert.bat.txt"
orig_dir="`pwd`"
cd "$root_dir"
files="`find . -not \( -name '\.git' -type d -prune \) -type f`"
for ending in $whitelist; do
files="`echo "$files" | grep -v "\.$ending\$"`"
done
echo '#!/bin/bash' > "$uninstall_file"
chmod +x "$uninstall_file"
echo '@echo off' > "$uninstall_file_win"
chmod +x "$uninstall_file_win"
for file in $files; do
mv -v "$file" "$file".txt
echo mv -v "$file".txt "$file" >> "$uninstall_file"
file="`echo $file | sed -E 's@/@\\\\@g'`"
echo 'move /y' "$file".txt "$file" >> "$uninstall_file_win"
done
cd "$orig_dir"
IMPORTANT
=========
In case a "sis-unconvert.sh.txt" or "sis-unconvert.bat.txt" is present in this
directory, you have obtained a SIS-compatible version of this work.
To convert it back into a regular version, run either "sis-unconvert.sh.txt"
or "sis-unconvert.bat.txt", depending on your platform.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment