feat(take): add support to `take' for taking remote urls (#2029)
Download, extract, and cd into the resulting directory.
Co-authored-by: Mitchel Humpherys <mitchelh@codeaurora.org>
Diff
1diff --git a/lib/functions.zsh b/lib/functions.zsh
2index c4340f16ce35d66dc3aa41bba1311b3deb6a9509..9cc735196c6d8e2ce40f29bd7194ff65449d827e 100644
3--- a/lib/functions.zsh
4+++ b/lib/functions.zsh
5@@ -13,7 +13,7 @@ function upgrade_oh_my_zsh() {
6 omz update
7 }
8 9-function take() {
10+function takedir() {
11 mkdir -p $@ && cd ${@:$#}
12 }
1314@@ -37,6 +37,30 @@ function open_command() {
15 ${=open_cmd} "$@" &>/dev/null
16 }
1718+function takeurl() {
19+ data=$(mktemp)
20+ curl -L $1 > $data
21+ tar xf $data
22+ thedir=$(tar tf $data | head -1)
23+ rm $data
24+ cd $thedir
25+}
26+
27+function takegit() {
28+ git clone $1
29+ cd $(basename ${1%%.git})
30+}
31+
32+function take() {
33+ if [[ $1 =~ ^(https?|ftp).*\.tar\.(gz|bz2|xz)$ ]]; then
34+ takeurl $1
35+ elif [[ $1 =~ ^([A-Za-z0-9]\+@|https?|git|ssh|ftps?|rsync).*\.git/?$ ]]; then
36+ takegit $1
37+ else
38+ takedir $1
39+ fi
40+}
41+
42 #
43 # Get the value of an alias.
44 #