This commit is contained in:
JMARyA 2025-05-24 03:00:36 +02:00
parent 70b72ee3e3
commit b8385c110e
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263

33
conf.d/std.fish Normal file
View file

@ -0,0 +1,33 @@
# usage: skip N [files...]
# skip n elements from input
function skip
set -l n $argv[1]
set argv $argv[2..-1]
# tail -n +N+1 means start printing from line n+1
tail -n + (math $n + 1) $argv
end
# usage: get N
# get specified line number from stdin
function get
sed -n "$argv[1]p"
end
# usage: data_url FILE
# turn file into a data url
function data_url
if test (count $argv) -eq 1
set file_path $argv[1]
if test -f $file_path
# base64 output (base64 reads from stdin in fish with <)
set base64_data (base64 < $file_path)
set mime_type (file --mime-type -b $file_path)
echo "data:$mime_type;base64,$base64_data"
else
echo "File not found: $file_path"
end
else
echo "\$ data_url [FILE_PATH]"
echo "Turn data into a data URL"
end
end