Let's start with the bash function I had handy for my own personal use:
wget_github_zip() {
if [[ $1 =~ ^-+h(elp)?$ ]] ; then
printf "%s\n" "Downloads a github snapshot of a master branch.\nSupports input URLs of the forms */repo_name, *.git, and */master.zip"
return
fi
if [[ ${1} =~ /archive/master.zip$ ]] ; then
download=${1}
out_file=${1/\/archive\/master.zip}
out_file=${out_file##*/}.zip
elif [[ ${1} =~ .git$ ]] ; then
out_file=${1/%.git}
download=${out_file}/archive/master.zip
out_file=${out_file##*/}.zip
else
out_file=${1/%\/} # remove trailing '/'
download=${out_file}/archive/master.zip
out_file=${out_file##*/}.zip
fi
wget -c ${download} -O ${out_file}
}
You want the file to always be called master.zip and always be downloaded into your home directory, so:
wget_github_zip() {
if [[ $1 =~ ^-+h(elp)?$ ]] ; then
printf "%s\n" "Downloads a github snapshot of a master branch.\nSupports input URLs of the forms */repo_name, *.git, and */master.zip"
return
fi
if [[ ${1} =~ /archive/master.zip$ ]] ; then
download=${1}
elif [[ ${1} =~ .git$ ]] ; then
out_file=${1/%.git}
download=${out_file}/archive/master.zip
else
out_file=${1/%\/} # remove trailing '/'
download=${out_file}/archive/master.zip
fi
wget -c ${download} -O ~/master.zip && unzip ~/master.zip && mv ~/master.zip ~/myAddons
}
However, there are a few things for you to consider:
1) My original script will give you a unique download zip file name for each download, based upon the name of the github repository, which is generally what most people really want instead of everything being called master
and having to manually rename them afterwards for uniqueness. In that version of the script, you can use the value of $out_file to uniquely name the root directory unzipped tree.
2) If you really do want all downloaded zip
files to be named ~/master.zip
, do you want to delete each after they have been unzipped?
3) Since you seem to always want everything put in directory ~/myAddons
, why not perform all the operations there, and save yourself the need to move the unzipped directory?
wget -c https://github.com/user/repository/archive/master.zip -O ~/master.zip && unzip "$_" && mv ~/*-master ~/dir-name
– jesse_b Feb 04 '18 at 13:24depth=1
option. Without thedepth=
option, the user could end up with a needlessly huge download. – user1404316 Feb 04 '18 at 13:28git show
orgit log
to see what's changed between versions. – cas Feb 04 '18 at 14:11zip
file is not an unreasonable request. – chepner Feb 04 '18 at 14:32unzip
should take an argument for a directory to extract into, so you could create the parent dir first – Will Crawford Feb 04 '18 at 15:04git
? – user1404316 Feb 04 '18 at 16:09