Unverified Commit f68d65d3 authored by Mitchel Humpherys's avatar Mitchel Humpherys Committed by GitHub
Browse files

feat(take): add support to `take' for taking remote urls (#2029)



Download, extract, and cd into the resulting directory.
Co-authored-by: default avatarMitchel Humpherys <mitchelh@codeaurora.org>
parent a3d90624
...@@ -13,7 +13,7 @@ function upgrade_oh_my_zsh() { ...@@ -13,7 +13,7 @@ function upgrade_oh_my_zsh() {
omz update omz update
} }
function take() { function takedir() {
mkdir -p $@ && cd ${@:$#} mkdir -p $@ && cd ${@:$#}
} }
...@@ -37,6 +37,30 @@ function open_command() { ...@@ -37,6 +37,30 @@ function open_command() {
${=open_cmd} "$@" &>/dev/null ${=open_cmd} "$@" &>/dev/null
} }
function takeurl() {
data=$(mktemp)
curl -L $1 > $data
tar xf $data
thedir=$(tar tf $data | head -1)
rm $data
cd $thedir
}
function takegit() {
git clone $1
cd $(basename ${1%%.git})
}
function take() {
if [[ $1 =~ ^(https?|ftp).*\.tar\.(gz|bz2|xz)$ ]]; then
takeurl $1
elif [[ $1 =~ ^([A-Za-z0-9]\+@|https?|git|ssh|ftps?|rsync).*\.git/?$ ]]; then
takegit $1
else
takedir $1
fi
}
# #
# Get the value of an alias. # Get the value of an alias.
# #
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment