summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitchel Humpherys <mitch.special@gmail.com>2021-06-11 21:09:08 -0700
committerGitHub <noreply@github.com>2021-06-11 21:09:08 -0700
commitf68d65d32a4fce41f08ac229614b7e46baf5e916 (patch)
tree395b8d548ea0de66e05740fa510ed2574f2e2bae
parenta3d90624df4ca9c4f438e8905f5c56399747db73 (diff)
downloadzsh-f68d65d32a4fce41f08ac229614b7e46baf5e916.tar.gz
zsh-f68d65d32a4fce41f08ac229614b7e46baf5e916.tar.bz2
zsh-f68d65d32a4fce41f08ac229614b7e46baf5e916.zip
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>
-rw-r--r--lib/functions.zsh26
1 files changed, 25 insertions, 1 deletions
diff --git a/lib/functions.zsh b/lib/functions.zsh
index c4340f16c..9cc735196 100644
--- a/lib/functions.zsh
+++ b/lib/functions.zsh
@@ -13,7 +13,7 @@ function upgrade_oh_my_zsh() {
omz update
}
-function take() {
+function takedir() {
mkdir -p $@ && cd ${@:$#}
}
@@ -37,6 +37,30 @@ function open_command() {
${=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.
#