zshconfig/zsh/std.zsh
2024-03-02 22:33:55 +01:00

32 lines
No EOL
704 B
Bash

# usage: skip N
# skip n elements from input
function skip() {
local n=$1
shift
tail -n +"$((n+1))" "$@"
}
# get <i>
# get specified line number
function get() {
sed -n "$1p"
}
# 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
}