♻️ Use argument names

This commit is contained in:
Marley Rae 2024-01-28 20:33:46 -08:00
parent 3a892978bf
commit c189a85f52
4 changed files with 38 additions and 51 deletions

View file

@ -16,8 +16,8 @@ function brew_prefix
end end
end end
function brew_tap function brew_tap -a $tap
brew tap "$argv[1]" &>/dev/null brew tap "$tap" &>/dev/null
end end
function brew_update function brew_update
@ -30,12 +30,7 @@ end
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function brew_install function brew_install -a $formula_readable_name $formula $arguments $tap_value
set -f formula_readable_name $argv[1]
set -f formula $argv[2]
set -f arguments $argv[3]
set -f tap_value $argv[4]
# Check that Homebrew is installed # Check that Homebrew is installed
if ! cmd_exists "brew" if ! cmd_exists "brew"
print_error "$formula_readable_name ('Homebrew' is not installed)" print_error "$formula_readable_name ('Homebrew' is not installed)"

View file

View file

@ -21,10 +21,7 @@ end
# Symlink Dotfiles # # Symlink Dotfiles #
################################################################################ ################################################################################
function link_file function link_file -a $src $dst
set -f src $argv[1]
set -f dst $argv[2]
set -f action set -f action
if [ -f "$dst" ] || [ -d "$dst" ] || [ -L "$dst" ] if [ -f "$dst" ] || [ -d "$dst" ] || [ -L "$dst" ]
@ -91,10 +88,10 @@ function link_file
end end
end end
function make_dst function make_dst -a $src
set -l path (string replace -a '/' '\/' "$DOT") set -l path (string replace -a '/' '\/' "$DOT")
set -l regex (string join '' '^' "$path" '\/[a-zA-Z]+\/(.+)\.symlink$') set -l regex (string join '' '^' "$path" '\/[a-zA-Z]+\/(.+)\.symlink$')
set -l dst (string replace -r $regex '$1' "$argv[1]") set -l dst (string replace -r $regex '$1' "$src")
printf '%s' "$HOME/$dst" printf '%s' "$HOME/$dst"
end end

View file

@ -2,57 +2,57 @@
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function print_in_color function print_in_color -a $color $text
printf '%b' \ printf '%b' \
"$(tput setaf $argv[2] 2> /dev/null)" \ "$(tput setaf $color 2> /dev/null)" \
$argv[1] \ $text \
"$(tput sgr0 2> /dev/null)" "$(tput sgr0 2> /dev/null)"
end end
function print_in_red function print_in_red -a $text
print_in_color $argv[1] 1 print_in_color $text 1
end end
function print_in_yellow function print_in_yellow -a $text
print_in_color $argv[1] 3 print_in_color $text 3
end end
function print_in_green function print_in_green -a $text
print_in_color $argv[1] 2 print_in_color $text 2
end end
function print_in_purple function print_in_purple -a $text
print_in_color $argv[1] 5 print_in_color $text 5
end end
function print_title function print_title -a $text
print_in_purple "\n • $argv[1]\n\n" print_in_purple "\n • $text\n\n"
end end
function print_success function print_success -a $text
print_in_green " [✔] $argv[1]\n" print_in_green " [✔] $text\n"
end end
function print_warning function print_warning -a $text
print_in_yellow " [!] $argv[1]\n" print_in_yellow " [!] $text\n"
end end
function print_error function print_error -a $text $text2
print_in_red " [✖] $argv[1] $argv[2]\n" print_in_red " [✖] $text $text2\n"
end end
function print_question function print_question -a $text
print_in_yellow " [?] $argv[1]\n" print_in_yellow " [?] $text\n"
end end
function print_result function print_result -a $exit_code $text
if [ "$argv[1]" -eq 0 ] if [ "$exit_code" -eq 0 ]
print_success $argv[2] print_success $text
else else
print_error $argv[2] print_error $text
end end
return $argv[1] return $exit_code
end end
function print_error_stream function print_error_stream
@ -63,15 +63,11 @@ end
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function show_spinner function show_spinner -a $pid $cmds $msg
set -l frames '/-\|' set -l frames '/-\|'
set -l number_of_frames (string length $FRAMES) set -l number_of_frames (string length $FRAMES)
set -l pid $argv[1]
set -l cmds $argv[2]
set -l msg $argv[3]
set -l i 0 set -l i 0
set -l frame_text "" set -l frame_text ""
@ -95,9 +91,9 @@ end
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function set_trap function set_trap -a $sig $func
trap -p "$argv[1]" | grep "$argv[2]" &> /dev/null \ trap -p "$sig" | grep "$func" &> /dev/null \
|| trap "$argv[2]" "$argv[1]" || trap "$func" "$sig"
end end
function kill_all_subproccesses function kill_all_subproccesses
@ -111,9 +107,8 @@ end
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function execute function execute -a $cmds
set -l cmds $argv[1] set -q $argv[2] and set -l msg $argv[2] or set -l msg "$cmds"
set -q $argv[2] and set -l msg $argv[2] or set -l msg $argv[1]
set -l tmp_file "$(mktmp /tmp/XXXXX)" set -l tmp_file "$(mktmp /tmp/XXXXX)"