Files
sxmo-utils/scripts/core/sxmo_contactmenu.sh
ArenM 7ea019e402 Manual fixups for nerd fonts 3.0
* Make icon_prn a nerd-font icons. It was using a font awesome code
  point, which we don't install with sxmo.
* Fix phone locked and laptop icons that weren't automatically updated
* Fix brightness icon in legacy nerd-fonts range and move it to
  sxmo_hook_icons from sxmo_brightness
* Use standard Unicode arrows instead of nerd-fonts ones
* Use icon variables for arrows in sxmo_wmmenu.sh
* Add variable for audio icon & use in sxmo_audio.sh
* Remove no stray break space from sxmo_contactmenu
* Remove up arrow character from reddit script
* use only icon variables in modemtext
* Update icons breakpoints

Signed-off-by: Willow Barraco <contact@willowbarraco.fr>
2023-05-29 19:58:29 +02:00

194 lines
4.1 KiB
Bash
Executable File

#!/bin/sh
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2022 Sxmo Contributors
# shellcheck source=configs/default_hooks/sxmo_hook_icons.sh
. sxmo_hook_icons.sh
# shellcheck source=scripts/core/sxmo_common.sh
. sxmo_common.sh
set -e
# shellcheck disable=SC2120
newcontact() {
name="$(printf "" | sxmo_dmenu_with_kb.sh -p "$icon_usr Name")"
number="$1"
if [ -n "$number" ]; then
number="$(sxmo_validnumber.sh "$number")" || return
fi
while [ -z "$number" ]; do
number="$(sxmo_contacts.sh --unknown | sxmo_dmenu_with_kb.sh -p "$icon_phl Number")"
number="$(sxmo_validnumber.sh "$number")" || continue
done
# we store as NUMBER\tNAME but display as NAME\tNUMBER
printf "%s\n" "$number $name" >> "$SXMO_CONTACTFILE"
PICKED="$name $number"
}
editcontactname() {
oldnumber="$(printf %s "$1" | cut -d" " -f2)"
oldname="$(printf %s "$1" | cut -d" " -f1)"
ENTRIES="$(printf %b "Old name: $oldname")"
PICKED="$(
printf %b "$ENTRIES" |
sxmo_dmenu_with_kb.sh -p "$icon_edt Edit Contact"
)"
if ! printf %s "$PICKED" | grep -q "^Old name: "; then
newcontact="$oldnumber $PICKED"
sed -i "s/^$oldnumber $oldname$/$newcontact/" "$SXMO_CONTACTFILE"
set -- "$newcontact"
fi
editcontact "$PICKED $oldnumber"
}
editcontactnumber() {
oldnumber="$(printf %s "$1" | cut -d" " -f2)"
oldname="$(printf %s "$1" | cut -d" " -f1)"
ENTRIES="$(sxmo_contacts.sh --unknown | xargs -0 printf "%b (Old number)\n%b" "$oldnumber")"
PICKED= # already used var name
while [ -z "$PICKED" ]; do
PICKED="$(
printf %b "$ENTRIES" |
sxmo_dmenu_with_kb.sh -p "$icon_edt Edit Contact"
)"
if printf %s "$PICKED" | grep -q "(Old number)$"; then
editcontact "$1"
return
fi
PICKED="$(sxmo_validnumber.sh "$PICKED")" || continue
done
newcontact="$PICKED $oldname"
# reverse them
sed -i "s/^$number $name$/$newcontact/" "$SXMO_CONTACTFILE"
editcontact "$oldname $PICKED"
}
deletecontact() {
number="$(printf %s "$1" | cut -d" " -f2)"
name="$(printf %s "$1" | cut -d" " -f1)"
# shellcheck disable=SC2059
ENTRIES="$(printf "$icon_cls No\n$icon_chk Yes")"
PICKED="$(
printf %b "$ENTRIES" |
dmenu -p "$icon_del Delete $name?"
)"
# reverse them
printf %s "$PICKED" | grep -q "Yes" && sed -i "/^$number $name$/d" "$SXMO_CONTACTFILE"
}
editcontact() {
number="$(printf %s "$1" | cut -d" " -f2)"
name="$(printf %s "$1" | cut -d" " -f1)"
ENTRIES="$(printf %b "$icon_ret Cancel\n$icon_usr Name: $name\n$icon_phl Number: $number")"
PICKED="$(
printf %b "$ENTRIES" |
dmenu -p "$icon_edt Edit Contact"
)"
case "$PICKED" in
*"Name: "*)
editcontactname "$1"
;;
*"Number: "*)
editcontactnumber "$1"
;;
*)
showcontact "$1"
;;
esac
}
showcontact() {
number="$(printf %s "$1" | cut -d" " -f2)"
name="$(printf %s "$1" | cut -d" " -f1)"
PICKED="$(dmenu -p "$icon_usr $name" <<EOF
$icon_ret Cancel
$icon_lst List Messages
$icon_msg Send a Message
$icon_phn Call
$icon_itm View
$icon_edt Edit
$icon_del Delete
EOF
)"
case "$PICKED" in
*"List Messages")
sxmo_hook_tailtextlog.sh "$number"
exit
;;
*"Send a Message")
sxmo_modemtext.sh sendtextmenu "$number"
exit
;;
*"Call")
sxmo_modemdial.sh "$number"
exit
;;
*"Edit")
editcontact "$1"
;;
*"View")
if formatted="$(pnc format -f nat "$number" 2>/dev/null)"; then
text="$formatted"
else
text="$number"
fi
# shellcheck disable=SC2016
sxmo_terminal.sh sh -c 'printf "%s\n%s\n" "$1" "$2"; read -r _line' \
"show_number" "$name" "$text" || true
;;
*"Delete")
deletecontact "$1" || showcontact "$1"
;;
esac
}
main() {
while true; do
CONTACTS="$(sxmo_contacts.sh --all)"
ENTRIES="$(printf %b "$CONTACTS" | xargs -0 printf "$icon_ret Close Menu\n$icon_pls New Contact\n%s")"
PICKED="$(
printf %b "$ENTRIES" |
sxmo_dmenu_with_kb.sh -i -p "$icon_lst Contacts"
)"
case "$PICKED" in
"$icon_ret Close Menu")
exit
;;
"$icon_pls New Contact")
newcontact || continue
;;
*)
esac
showcontact "$(printf %s "$PICKED" | sed 's/: /\t/g')"
done
}
if [ -n "$1" ]; then
cmd="$1"
shift
else
cmd=main
fi
"$cmd" "$@"