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

View file

View file

@ -21,10 +21,7 @@ end
# Symlink Dotfiles #
################################################################################
function link_file
set -f src $argv[1]
set -f dst $argv[2]
function link_file -a $src $dst
set -f action
if [ -f "$dst" ] || [ -d "$dst" ] || [ -L "$dst" ]
@ -91,10 +88,10 @@ function link_file
end
end
function make_dst
function make_dst -a $src
set -l path (string replace -a '/' '\/' "$DOT")
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"
end

View file

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