7eeb1e193d4a55ab706931fb80ef556a939be8fd
- Author
- Marc Cornellà <hello@mcornella.com>
- Committer
- Marc Cornellà <hello@mcornella.com>
- Date
Message
refactor(lib): refactor take functions
Diff
1diff --git a/lib/functions.zsh b/lib/functions.zsh
2index 24b7254fbea6311dbbc62c14921d2d37f2e9d529..73b491a5951da152fffd5b5fe5088fc16e3d2ea5 100644
3--- a/lib/functions.zsh
4+++ b/lib/functions.zsh
5@@ -41,26 +41,27 @@ function mkcd takedir() {
6 }
7
8 function takeurl() {
9- data=$(mktemp)
10- curl -L $1 > $data
11- tar xf $data
12- thedir=$(tar tf $data | head -1)
13- rm $data
14- cd $thedir
15+ local data thedir
16+ data="$(mktemp)"
17+ curl -L "$1" > "$data"
18+ tar xf "$data"
19+ thedir="$(tar tf "$data" | head -1)"
20+ rm "$data"
21+ cd "$thedir"
22 }
23
24 function takegit() {
25- git clone $1
26- cd $(basename ${1%%.git})
27+ git clone "$1"
28+ cd "$(basename ${1%%.git})"
29 }
30
31 function take() {
32 if [[ $1 =~ ^(https?|ftp).*\.tar\.(gz|bz2|xz)$ ]]; then
33- takeurl $1
34+ takeurl "$1"
35 elif [[ $1 =~ ^([A-Za-z0-9]\+@|https?|git|ssh|ftps?|rsync).*\.git/?$ ]]; then
36- takegit $1
37+ takegit "$1"
38 else
39- takedir $1
40+ takedir "$@"
41 fi
42 }
43