From b8385c110e7801d3ead71a475e3b5a4afd08a021 Mon Sep 17 00:00:00 2001 From: JMARyA Date: Sat, 24 May 2025 03:00:36 +0200 Subject: [PATCH] add std --- conf.d/std.fish | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 conf.d/std.fish diff --git a/conf.d/std.fish b/conf.d/std.fish new file mode 100644 index 0000000..5ed6c85 --- /dev/null +++ b/conf.d/std.fish @@ -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