Fixed, now works pretty well

This commit is contained in:
inigoortega 2019-09-02 00:36:15 +02:00
parent 4183d3ff4d
commit c4800c44a3

25
scripts/lol-summoners.sh Normal file → Executable file
View file

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
usage() { usage() {
echo "Usage: $0 [-y] [-b <browser>]" 1>&2 echo "Usage: $0 [-m] [-b <browser>] [-r <region>]" 1>&2
exit 1 exit 1
} }
@ -25,13 +25,16 @@ get_browser() {
echo "$browser" echo "$browser"
} }
while getopts ":m:b:" option; do while getopts ":mb:r:" option; do
case "${option}" in case "${option}" in
y) m)
no_ignore_me="1" no_ignore_me="1"
;; ;;
r)
region="${OPTARG}"
;;
b) b)
browser=${OPTARG} browser="${OPTARG}"
if [ ! command -v "$browser" ]; then if [ ! command -v "$browser" ]; then
echo "Can't run \'$browser\' browser'" 1>&2 echo "Can't run \'$browser\' browser'" 1>&2
exit 3 exit 3
@ -53,8 +56,14 @@ temp="/tmp/lol-summmoners.$(date +%s)"
# Get the text copied from champion select, get summoner names # Get the text copied from champion select, get summoner names
# and save them into the temporary file # and save them into the temporary file
xclip -o -selection clipboard \ xclip -o -selection clipboard \
| grep "$pattern" | sed -E "s/(.*)$pattern/\1/" > $temp | grep "$pattern" | sed -E "s/(.*)$pattern/\1/" > "$temp"
# Region
if [ -z "$region" ]; then
region="$LOL_REGION"
fi
# Browser
if [ -z "$browser" ]; then if [ -z "$browser" ]; then
browser="$(get_browser)" browser="$(get_browser)"
fi fi
@ -63,12 +72,14 @@ fi
while read -r summoner while read -r summoner
do do
# Ignore if it is you # Ignore if it is you
if [ "$summoner" -eq "$yourself" -a "$no_ignore_me" -ne "1" ]; then if [ "$summoner" = "$yourself" -a "$no_ignore_me" -ne "1" ]; then
continue continue
fi fi
# Make spaces + # Make spaces +
summoner="$(echo "$summoner" | sed "s/ /+/g")" summoner="$(echo "$summoner" | sed "s/ /+/g")"
# Open # Open
$browser "https://euw.op.gg/summoner/userName=$summoner" $browser "https://$region.op.gg/summoner/userName=$summoner"
done < "$temp" done < "$temp"
rm "$temp"