-
Notifications
You must be signed in to change notification settings - Fork 0
/
dump_extensions
executable file
·42 lines (31 loc) · 1.33 KB
/
dump_extensions
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
#!/bin/bash
cd "$(dirname "$0")" || return
declare installed_extensions
declare added_extensions
declare added_extensions_count
declare removed_extensions
declare removed_extensions_count
installed_extensions="$(code --list-extensions)"
readonly installed_extensions
if echo "$installed_extensions" | cmp -s extensions -; then
echo 'Already up to date'
else
added_extensions="$(echo "$installed_extensions" | diff -u extensions - | tail -n +4 | grep '^\+' | sed 's/\+//')"
readonly added_extensions
removed_extensions="$(echo "$installed_extensions" | diff -u - extensions | tail -n +4 | grep '^\+' | sed 's/\+//')"
readonly removed_extensions
if [[ -n $added_extensions ]]; then
added_extensions_count="$(echo "$added_extensions" | wc -l | tr -d '[:space:]')"
readonly added_extensions_count
echo "Added $added_extensions_count extension$([[ added_extensions_count -gt 1 ]] && printf 's'):"
echo "$added_extensions"
fi
[[ -n $added_extensions && -n $removed_extensions ]] && printf '\n'
if [[ -n $removed_extensions ]]; then
removed_extensions_count="$(echo "$removed_extensions" | wc -l | tr -d '[:space:]')"
readonly removed_extensions_count
echo "Removed $removed_extensions_count extension$([[ removed_extensions_count -gt 1 ]] && printf 's'):"
echo "$removed_extensions"
fi
echo "$installed_extensions" >extensions
fi