53
loading...
This website collects cookies to deliver better user experience
.helpers
inside home directory.take
command on zsh automatically creates folders and change the directories.take .helpers/b64
file_to_b64
inside the b64
folder and put this code.#!/bin/bash
while getopts ":e:p:" opt; do
case $opt in
e) ext="${OPTARG}"
;;
p) path="${OPTARG}"
;;
\?) echo "Invalid option -${OPTARG}" >&2
exit 1
;;
esac
done
if [ -z ${ext} ]; then
echo "ERROR: Extension is missing"
exit 1
fi
if [ ! -z ${path} ]; then
path="${path}/"
fi
for file in ${path}*.${ext}; do
[ -e "${file}" ] || continue
filename=${file%%.*}
if [ -f "${filename}.b64" ]; then
rm -r "${filename}.b64"
fi
base64 ${file}|tr -d '\n' > "${filename}.b64"
echo "SUCCESS: '${filename}.b64' file was created"
done
b64_to_file
inside the b64
folder and put this code.#!/bin/bash
while getopts ":p:" opt; do
case $opt in
p) path="${OPTARG}"
;;
\?) echo "Invalid option -${OPTARG}" >&2
exit 1
;;
esac
done
if [ ! -z ${path} ]; then
path="${path}/"
fi
for file in ${path}*.b64; do
[ -e "$file" ] || continue
filename=${file%%.*}
base64 --decode --ignore-garbage ${file} > "${filename}.tmp"
ext=$(file -b --mime-type ${filename}.tmp | cut -d'/' -f2)
if [ ! -z ${ext} ]; then
if [ -f "${filename}.${ext}" ]; then
rm -r "${filename}.${ext}"
fi
mv "${filename}.tmp" "${filename}.${ext}"
echo "SUCCESS: '${filename}.${ext}' file was created"
else
rm -r "${filename}.tmp"
echo "ERROR: '${filename}.b64' has no mime-type"
fi
done
chmod +x ~/.helpers/**/*
.helpers/b64
folder each time we want to use those commands. PATH
and alises to .zshrc
.export PATH="$HOME/.helpers/b64/:$PATH"
alias b2f="b64_to_file"
alias f2b="file_to_b64"
-e
extension file name parameter.file_to_b64 -e jpg #current path
file_to_b64 -e jpg -p foldername
# with alias
f2b -e jpg -p ~/dev/files
*.b64
files and decode to files. No need to define the extension, it will search inside the mime file type.b64_to_file #current path
b64_to_file -p foldername
# with alias
b2f -p ~/dev/files