#!/usr/bin/env bash

# @see https://github.com/mchav/with

# check if user is root
# and re-exec the script with sudo if not
#
# equivalent to: [ "$(whoami)" != "root" ] && exec sudo -- "$0" "$@"
# bash only, but without external call to whoami

(( EUID != 0 )) && exec sudo -- "$0" "$@"

echo "Installing with"
sudo curl -s https://raw.githubusercontent.com/mchav/with/master/with -o /usr/bin/with && sudo chmod +x /usr/bin/with
sudo curl -s https://raw.githubusercontent.com/mchav/with/master/with.bash-completion -o /etc/bash_completion.d/with.bash-completion
echo "with successfully installed!"
