function alias_if --description "Alias if a program exists" if test (count $argv) -lt 2 return end if command -sq $argv[1] if test (count $argv) -gt 2 alias $argv[2] "$argv[1] $argv[3..-1]" else alias $argv[2] "$argv[1]" end end end function alias_if_not --description "Alias if a program doesn't exist" if test (count $argv) -lt 2 return end if not command -sq $argv[1] if test (count $argv) -gt 2 alias $argv[1] "$argv[2] $argv[3..-1]" else alias $argv[1] "$argv[2]" end end end function find_prog --description "Find one or more programs in \$PATH" for prog in $argv for search_path in $PATH if test -x "$search_path/$prog" echo -n "$prog" return end end end end function pp --description "Pretty print a message from a script" -a type -a msg if test -z "$msg" return end if test -z "$type" set type info end switch $type case error set -f mcolor red set -f pcolor red set -f prefix '!! ' case warn set -f mcolor yellow set -f pcolor yellow set -f prefix '?? ' case info set -f mcolor normal set -f pcolor green set -f prefix '==> ' case info2 set -f mcolor normal set -f pcolor blue set -f prefix ' -> ' case ask set -f mcolor normal set -f pcolor blue set -f prefix ':: ' case debug set -f mcolor cyan set -f pcolor cyan set -f prefix '** ' end echo -n (set_color -o $pcolor)"$prefix"(set_color normal) echo $(set_color $mcolor)"$msg"(set_color normal) end function ask --description "Ask a question answered by yes or no" read -n 1 -f -P (pp ask "$argv[1] [y/N] ") answer switch $answer case y Y return 0 # yes case '*' return 1 # no end end