mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-11 00:10:08 +00:00
refactor(lib): refactor take functions
This commit is contained in:
parent
c249288151
commit
7eeb1e193d
1 changed files with 12 additions and 11 deletions
|
@ -41,26 +41,27 @@ function mkcd takedir() {
|
|||
}
|
||||
|
||||
function takeurl() {
|
||||
data=$(mktemp)
|
||||
curl -L $1 > $data
|
||||
tar xf $data
|
||||
thedir=$(tar tf $data | head -1)
|
||||
rm $data
|
||||
cd $thedir
|
||||
local data thedir
|
||||
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})
|
||||
git clone "$1"
|
||||
cd "$(basename ${1%%.git})"
|
||||
}
|
||||
|
||||
function take() {
|
||||
if [[ $1 =~ ^(https?|ftp).*\.tar\.(gz|bz2|xz)$ ]]; then
|
||||
takeurl $1
|
||||
takeurl "$1"
|
||||
elif [[ $1 =~ ^([A-Za-z0-9]\+@|https?|git|ssh|ftps?|rsync).*\.git/?$ ]]; then
|
||||
takegit $1
|
||||
takegit "$1"
|
||||
else
|
||||
takedir $1
|
||||
takedir "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue