Wrote a #shell function without using ls inside of $( ), so my inner @mirabilos won't harass me. XD
#slightly easier wireguard command
function wg {
local dir file profile profiledir= parm=${1:-} statustext
#Find profile dir
for dir in {,/usr/local}/etc/wireguard; do
if [[ -d $dir ]]; then
profiledir=$dir
break
fi
done
#Find config file
if [[ -n $profiledir ]]; then
for file in $profiledir/*.conf; do
if [[ -e $file ]]; then
profile=${file//*\/}
profile=${profile/.conf}
break
fi
done
fi
[[ -n $profile ]] || profile=proton
statustext="wireguard profile $profile"
case ${parm,,} in
up|on) doas wg-quick up $profile;;
down|off) doas wg-quick down $profile;;
status) echo -en "$statustext _______\r"
echo -en "$statustext "
ifconfig |grep -q "^$profile:" && echo enabled || echo disabled;;
*) warn "wg usage: wg up|down|status";;
esac
}
Hmm, seems ${foo,,} for lower case conversion is #bash-only. I wonder if I should use tr instead.
🍵 
Qiita - 人気の記事







