42 lines
752 B
Bash
42 lines
752 B
Bash
#!/usr/bin/env bash
|
|
|
|
pipe=${args[--pipe]:?}
|
|
completions=${args[--completions]:-}
|
|
target=${args[target]:?}
|
|
url=${args[url]:?}
|
|
|
|
if [ "${action:-file}" = "exe" ]
|
|
then
|
|
if [ -x "$(command -v "$target")" ]
|
|
then
|
|
return
|
|
fi
|
|
exe=$target
|
|
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"
|
|
|
|
if [ -n "$completions" ]
|
|
then
|
|
echo "Installing completions for $exe"
|
|
# shellcheck disable=SC2086
|
|
"$target" $completions > "$XDG_CONFIG_HOME/completionsrc.d/_$(basename "$exe")"
|
|
fi
|
|
fi
|
|
|
|
_run_hook
|
|
fi
|