/
zfetch
85 lines (75 loc) · 2.05 KB
/
zfetch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env zsh
# This code was originally from
# https://github.com/jason0x43/dotfiles/blob/eff04270c4d8074db36d3e3bf85f64d3ccbeafe9/zsh/functions/zfetch
# Terminal colors
TC='\e['
Rst="${TC}0m"
Blk="${TC}30m";
Red="${TC}31m";
Grn="${TC}32m";
Yel="${TC}33m";
Blu="${TC}34m";
Prp="${TC}35m";
Cyn="${TC}36m";
Wht="${TC}37m";
git_clone_error_msg() {
echo -e " ${Red}[ERROR]${Rst} git clone errored: ${Red}${1}${Rst}. ${Yel}aborting...${Rst}"
}
# Simplest dependency fetcher known to mankind
if [[ $1 == "update" ]]; then
for name in ${(@k)plugins}; do
local cwd=$(pwd)
local dest=$plugins[$name]
cd $dest
echo -e "Updating ${Yel}${name}${Rst}..."
git pull --quiet --recurse-submodules
cd $cwd
done
elif [[ $1 == "ls" ]]; then
for name in ${(@k)plugins}; do
echo -e "${name}: ${Yel}$plugins[$name]${Rst}"
done
else
# the short name of the repo (org/repo)
local name="$1"
local plugin_name="${2:-"${name##*/}.plugin.zsh"}"
# where the repo is going
local dest="${3:-"$ZPLUGDIR"}"
# if the dest dir ends with /, append the name to it to get the real dest dir
if [[ $dest == */ ]]; then
dest=$dest$name
else
dest=$dest/$name
fi
local cwd=$(pwd)
plugins[$name]=$dest
if [[ ! -d $dest ]]; then
local url=git@github.com:$name
local ref=$3
echo -e "Missing plugin ${Yel}${name}${Rst}"
echo -e " Cloning from ${Blu}${url}${Rst}..."
if [[ -n $ref ]]; then
git clone --quiet $url $dest
if [[ $? != 0 ]]; then
git_clone_error_msg $?
cd $cwd
return $?
fi
git checkout --quiet $ref
echo -e " Checked out branch ${ref}"
else
git clone --quiet --depth 1 $url $dest
if [[ $? != 0 ]]; then
git_clone_error_msg $?
cd $cwd
return $?
fi
echo -e " Checked out default branch"
fi
fi
plugin="$dest/$plugin_name"
if [ -f "$plugin" ]; then
source "$plugin"
fi
cd $cwd
fi