26 lines
749 B
Fish
26 lines
749 B
Fish
function latexcolor --description "Get the LaTeX color from HEX code"
|
|
# Declare our arguments
|
|
argparse h/help -- $argv
|
|
|
|
# Get function name
|
|
set current_name $(status current-function)
|
|
|
|
# Check if not enough arguments provided, or help menu
|
|
if set -ql _flag_help || test -z $argv[2]
|
|
echo -e "Usage: $current_name hex"
|
|
echo -e " $current_name [-h|--help] \t\t - Show this help message"
|
|
return 0
|
|
end
|
|
|
|
set hex $argv[1]
|
|
if string match -r '^#' -- $hex
|
|
set hex (string sub -s 2 $hex)
|
|
end
|
|
|
|
# Convert hex to RGB
|
|
set r (math "0x${hex[1..2]} / 255")
|
|
set g (math "0x${hex[3..4]} / 255")
|
|
set b (math "0x${hex[5..6]} / 255")
|
|
|
|
printf "{%.2f, %.2f, %.2f}\n" $r $g $b
|
|
end
|