-
Notifications
You must be signed in to change notification settings - Fork 29
/
c_extras.sh
145 lines (126 loc) · 3.3 KB
/
c_extras.sh
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
_basename_no_extension () {
sed -e 's/^.*\/\(.*\)\.inc$/\1/'
}
_composure_functions () {
_list_composure_files | _basename_no_extension
}
_load_tab_completions () {
# support tab completion for 'revise' command
# you may disable this by adding the following line to your shell startup:
# export COMPOSURE_TAB_COMPLETION=0
if [ "$COMPOSURE_TAB_COMPLETION" = "0" ]; then
return # if you say so...
fi
case "$(_shell)" in
zsh)
read -r -d '' SCRIPT <<ZSHDATA
_zsh_revise_complete () {
typeset word completions
word="\$1"
completions="\$(_composure_functions)"
reply=( "\${(ps:\n:)completions}" )
}
compctl -K _zsh_revise_complete revise
ZSHDATA
eval "$SCRIPT"
unset SCRIPT
;;
bash)
read -r -d '' SCRIPT <<BASHDATA
_bash_revise_complete () {
typeset cur
cur=\${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( \$(compgen -W "\$(_composure_functions)" -- \$cur) )
return 0
}
complete -F _bash_revise_complete revise
BASHDATA
eval "$SCRIPT"
unset SCRIPT
;;
*)
echo "composure tab completions unavailable"
;;
esac
}
# Second-order functions for composure
findgroup ()
{
about 'finds all functions belonging to group'
param '1: name of group'
example '$ findgroup tools'
group 'composure'
typeset func
for func in $(_typeset_functions)
do
typeset group="$(typeset -f $func | metafor group)"
if [ "$group" = "$1" ]; then
echo "$func"
fi
done
}
overview ()
{
about 'gives overview of available shell functions, by group'
group 'composure'
# display a brief progress message...
printf '%s' 'building documentation...'
typeset grouplist=$(mktemp /tmp/grouplist.XXXX);
typeset func;
for func in $(_typeset_functions);
do
typeset group="$(typeset -f $func | metafor group)";
if [ -z "$group" ]; then
group='misc';
fi;
typeset about="$(typeset -f $func | metafor about)";
_letterpress "$about" $func >> $grouplist.$group;
echo $grouplist.$group >> $grouplist;
done;
# clear progress message
printf '\r%s\n' ' '
typeset group;
typeset gfile;
for gfile in $(cat $grouplist | sort | uniq);
do
printf '%s\n' "${gfile##*.}:";
cat $gfile;
printf '\n';
command rm $gfile 2> /dev/null;
done | less
command rm $grouplist 2> /dev/null
}
recompose ()
{
about 'loads a stored function from ~/.composure repo'
param '1: name of function'
example '$ load myfunc'
group 'composure'
. $(_get_composure_dir)/$1.inc
}
unique_metafor ()
{
about 'displays all unique metadata for a given keyword'
param '1: keyword'
example '$ unique_metafor group'
group 'composure'
typeset keyword=$1
typeset file=$(mktemp /tmp/composure.XXXX)
typeset -f | metafor $keyword >> $file
cat $file | sort | uniq
command rm $file 2>/dev/null
}
compost () {
about 'delete function stored in composure repo'
param '1: name of function'
example '$ compost myfunc'
group 'composure'
typeset func=$1
[ -z "$func" ] && echo "you must specify a function name!" && return 1
(
cd $(_get_composure_dir)
git rm "$func.inc" && git commit -m "Delete function $func"
)
}
_load_tab_completions