-
Notifications
You must be signed in to change notification settings - Fork 3
/
menu-update
executable file
·30 lines (28 loc) · 776 Bytes
/
menu-update
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
#!/bin/bash
# Fills the specified menu database with any missing entries
# from any PATH directory
menu="main"
if [[ -n $1 ]]; then
menu=$1
fi
if [[ ! -e ~/.menu/${menu}.sqlite ]]; then
echo "menu file not found"
exit 1
fi
commands_to_be_added() {
existing=$(sqlite3 -line ~/.menu/${menu}.sqlite "SELECT name FROM commands ORDER BY weight DESC" | grep -v "^$" | cut -b 9- | sort)
IFS=':'
(for dir in $PATH; do
ls -1 "$dir"
done) | sort -u | comm -13 <(echo "$existing") -
}
IFS=$'\n'
ctba=$(commands_to_be_added)
for c in $(echo "$ctba"); do
echo "$c|$c|0"
done | sqlite3 -separator "|" ~/.menu/${menu}.sqlite ".import /dev/stdin commands"
if [[ -z $ctba ]]; then
echo "dynmenu: no commands added"
else
echo "dynmenu: $(echo "$ctba" | wc -l) commands added"
fi