-
Notifications
You must be signed in to change notification settings - Fork 0
/
global.zsh
60 lines (47 loc) · 1.55 KB
/
global.zsh
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
#####################################################################
### Artifacts and Operations ########################################
#####################################################################
_CA__LOCAL_CONFIG="$HOME/.config/code-activator-zsh/settings.zsh"
_CA_ERROR() { [ $_CA__SUPPRESS_ERROR ] || echo "CA::ERROR : $@" >&2; }
_CA_FZF() {
local MSG="$@"
[ ! $_NOSEP ] && MSG="$@ : "
fzf -i --height=50% --layout=reverse $FLAGS --prompt $MSG
}
_CA_FZF_PRINT() { _NOSEP=$_NOSEP FLAGS=(--print-query) _CA_FZF $@ | tail -1; }
_CA_LOAD() { source $_CA/zsh/$1.zsh; }
_CA_READ() { read -k $1; echo; }
_CA_MULTILINE() { sed 's/\s\+/\n/g'; }
_CA_LIST() {
local base_dir PROJECTS=()
for base_dir in $CA__DIRS
do
[ ! -d $base_dir ] && continue
for project_dir in $(find "$base_dir" -mindepth 1 -maxdepth 1 \( -type d -o -type l \) )
do
echo $(basename $base_dir)/$(basename $project_dir)
done
done
}
#####################################################################
### Dependency Checking #############################################
#####################################################################
_CA__CHECK_DEPENDENCIES() {
local D DEPENDENCIES=($@)
for D in $DEPENDENCIES
do
command -v $D >/dev/null 2>&1 || {
local LINK=$(_CA__GET_DEPENDENCY_LINK $D)
echo "I require '$D', but it's not installed. $LINK" >&2
}
done
}
_CA__GET_DEPENDENCY_LINK() {
local LINK
case $1 in
fzf ) LINK='https://github.com/junegunn/fzf' ;;
jq ) LINK='https://github.com/stedolan/jq' ;;
esac
[ $LINK ] && LINK='('$LINK')'
echo $LINK
}