#!/bin/bash

VERSION=$1

rm -rf fzf-*.tar.?z go-modules-fzf*

echo "Downloading fzf-$VERSION..."

wget "https://github.com/junegunn/fzf/archive/$VERSION/fzf-$VERSION.tar.gz"

tar xf fzf-$VERSION.tar.gz
mkdir -p go-modules-fzf-$VERSION

cd fzf-$VERSION
  export GOPATH=$(realpath ../go-modules-fzf-$VERSION)
  go mod download
cd ..

cd go-modules-fzf-$VERSION/pkg/mod/cache/
  mv download go-modules-fzf-$VERSION
  tar cf ../../../../go-modules-fzf-$VERSION.tar go-modules-fzf-$VERSION
cd ../../../../

plzip -9 go-modules-fzf-$VERSION.tar

gunzip fzf-$VERSION.tar.gz
plzip -9 fzf-$VERSION.tar

rm -rf fzf-$VERSION
rm -rf go-modules-fzf-$VERSION
