2024-01-09 15:48:11 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
pipe=${args[--pipe]:?}
|
2024-01-12 01:40:58 +00:00
|
|
|
completions=${args[--completions]:-}
|
2024-01-09 15:48:11 +00:00
|
|
|
target=${args[target]:?}
|
|
|
|
url=${args[url]:?}
|
|
|
|
|
|
|
|
if [ "${action:-file}" = "exe" ]
|
|
|
|
then
|
|
|
|
if [ -x "$(command -v "$target")" ]
|
|
|
|
then
|
|
|
|
return
|
|
|
|
fi
|
2024-01-12 01:28:44 +00:00
|
|
|
exe=$target
|
2024-01-09 15:48:11 +00:00
|
|
|
target="$HOME/.local/bin/$target"
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
if [ ! -f "$target" ]
|
|
|
|
then
|
|
|
|
echo "Installing file $url to $target"
|
|
|
|
|
|
|
|
target_dir=$(dirname "$target")
|
|
|
|
mkdir -p "$target_dir"
|
|
|
|
cd "$target_dir" || exit 1
|
|
|
|
|
|
|
|
_http_client "$url" | eval "$pipe" > "$target"
|
|
|
|
|
|
|
|
if [ "${action:-file}" = "exe" ]
|
|
|
|
then
|
|
|
|
chmod +x "$target"
|
2024-01-12 01:28:44 +00:00
|
|
|
|
2024-01-12 01:40:58 +00:00
|
|
|
if [ -n "$completions" ]
|
2024-01-12 01:28:44 +00:00
|
|
|
then
|
|
|
|
echo "Installing completions for $exe"
|
2024-02-01 14:28:03 +00:00
|
|
|
|
|
|
|
# path taken from "__load_completion" function
|
|
|
|
bash_completions_dir=${BASH_COMPLETION_USER_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/bash-completion}/completions
|
|
|
|
mkdir -p "$bash_completions_dir"
|
|
|
|
eval "$target $completions" > "$bash_completions_dir/_$(basename "$exe")"
|
2024-01-12 01:28:44 +00:00
|
|
|
fi
|
2024-01-09 15:48:11 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
_run_hook
|
|
|
|
fi
|