26 lines
No EOL
632 B
Bash
26 lines
No EOL
632 B
Bash
# usage: skip N
|
|
# skip n elements from input
|
|
function skip() {
|
|
local n=$1
|
|
shift
|
|
tail -n +"$((n+1))" "$@"
|
|
}
|
|
|
|
# usage: data_url <file>
|
|
# turn file into a data url
|
|
data_url() {
|
|
if [ $# -eq 1 ]; then
|
|
file_path=$1
|
|
if [ -f "$file_path" ]; then
|
|
base64_data=$(base64 < "$file_path")
|
|
mime_type=$(file --mime-type -b "$file_path")
|
|
data_url="data:$mime_type;base64,$base64_data"
|
|
echo "$data_url"
|
|
else
|
|
echo "File not found: $file_path"
|
|
fi
|
|
else
|
|
echo "\$ data_url [FILE_PATH]"
|
|
echo "Turn data into a data URL"
|
|
fi
|
|
} |