add truncate_description
This commit is contained in:
parent
f7bf18e85c
commit
5011637263
1 changed files with 12 additions and 5 deletions
|
|
@ -35,6 +35,15 @@ die() {
|
||||||
error_exit() { die "Encountered unknown error."; }
|
error_exit() { die "Encountered unknown error."; }
|
||||||
kill_exit() { die "\nExited due to user intervention."; }
|
kill_exit() { die "\nExited due to user intervention."; }
|
||||||
|
|
||||||
|
truncate_description() {
|
||||||
|
desc="$@"
|
||||||
|
if [[ "${#desc}" -gt $DESC_LIMIT ]]; then
|
||||||
|
echo "$(echo $desc | cut -c 1-$DESC_LIMIT)..."
|
||||||
|
else
|
||||||
|
echo $desc
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
trap error_exit ERR
|
trap error_exit ERR
|
||||||
trap kill_exit SIGTERM SIGINT
|
trap kill_exit SIGTERM SIGINT
|
||||||
|
|
||||||
|
|
@ -75,22 +84,20 @@ for CONFIG in $SNAPPER_CONFIGS; do
|
||||||
[[ $PACMAN_PRE_POST == "no" ]] && continue
|
[[ $PACMAN_PRE_POST == "no" ]] && continue
|
||||||
|
|
||||||
prefile="/tmp/snap-pac-pre_$CONFIG"
|
prefile="/tmp/snap-pac-pre_$CONFIG"
|
||||||
snapper_cmd="snapper --config $CONFIG create --type $pre_or_post --cleanup-algorithm $PACMAN_CLEANUP_ALGORITHM"
|
snapper_cmd="snapper --config $CONFIG create --type $pre_or_post --cleanup-algorithm $PACMAN_CLEANUP_ALGORITHM --print-number"
|
||||||
|
|
||||||
x=$((x+1))
|
x=$((x+1))
|
||||||
|
|
||||||
case "$pre_or_post" in
|
case "$pre_or_post" in
|
||||||
pre)
|
pre)
|
||||||
printf " %s " "$CONFIG"
|
printf " %s " "$CONFIG"
|
||||||
[[ "${#PACMAN_PRE_DESCRIPTION}" -gt $DESC_LIMIT ]] && PACMAN_PRE_DESCRIPTION="$(echo $PACMAN_PRE_DESCRIPTION | cut -c 1-$DESC_LIMIT)..."
|
$snapper_cmd --description "$(truncate_description $PACMAN_PRE_DESCRIPTION)" > "$prefile"
|
||||||
$snapper_cmd --description "$PACMAN_PRE_DESCRIPTION" --print-number > "$prefile"
|
|
||||||
printf "%s %s\n" "$(< "$prefile")" "$checkmark"
|
printf "%s %s\n" "$(< "$prefile")" "$checkmark"
|
||||||
;;
|
;;
|
||||||
post)
|
post)
|
||||||
if [[ -f $prefile ]]; then
|
if [[ -f $prefile ]]; then
|
||||||
printf " %s " "$CONFIG"
|
printf " %s " "$CONFIG"
|
||||||
[[ "${#PACMAN_POST_DESCRIPTION}" -gt $DESC_LIMIT ]] && PACMAN_POST_DESCRIPTION="$(echo $PACMAN_POST_DESCRIPTION | cut -c 1-$DESC_LIMIT)..."
|
postnum=$($snapper_cmd --description "$(truncate_description $PACMAN_POST_DESCRIPTION)" --pre-number "$(< "$prefile")")
|
||||||
postnum=$($snapper_cmd --description "$PACMAN_POST_DESCRIPTION" --print-number --pre-number "$(< "$prefile")")
|
|
||||||
printf "%s %s\n" "$postnum" "$checkmark"
|
printf "%s %s\n" "$postnum" "$checkmark"
|
||||||
rm "$prefile"
|
rm "$prefile"
|
||||||
else
|
else
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue