45 lines
954 B
Bash
45 lines
954 B
Bash
#!/usr/bin/env bash
|
|
|
|
pipe=${args[--pipe]:?}
|
|
completions=${args[--completions]:-}
|
|
target=${args[target]:?}
|
|
url=${args[url]:?}
|
|
|
|
if [ "${action:-file}" = "exe" ] && ! echo "$target" | grep -q "/"
|
|
then
|
|
if [ -x "$(command -v "$target")" ]
|
|
then
|
|
return
|
|
fi
|
|
exe=$target
|
|
target="$HOME/.local/bin/$target"
|
|
fi
|
|
|
|
|
|
if [ ! -e "$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"
|
|
|
|
# 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")"
|
|
fi
|
|
fi
|
|
|
|
_run_hook
|
|
fi
|