add std
This commit is contained in:
parent
70b72ee3e3
commit
b8385c110e
1 changed files with 33 additions and 0 deletions
33
conf.d/std.fish
Normal file
33
conf.d/std.fish
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue