Skip to content

Commit ed8d24f

Browse files
committed
feat: command to edit chat-list with default editor
1 parent f7afe13 commit ed8d24f

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tg-notify

+27
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ usage() {
4949
echo "$bin_name add|add-chat add chat to chat-list" >&2
5050
echo "$bin_name ls|list-chats print chat-list" >&2
5151
echo "$bin_name rm|remove-chat [chat id] remove chat from chat-list" >&2
52+
echo "$bin_name e|edit|edit-chat-list open chat-list with default editor" >&2
5253
echo "$bin_name [-f|--format <format>] send [msg] [*chat ids] send message" >&2
5354
echo "$bin_name -v|--version|version print version information" >&2
5455
echo "$bin_name -h|--help|usage|help display this help message" >&2
@@ -243,6 +244,29 @@ remove-chat() {
243244
sed -i "/^${chat_id/#@/-}/d" "$chat_list_file"
244245
}
245246

247+
## edit chat list with default editor
248+
edit-chat-list() {
249+
local editor="${VISUAL:-"${EDITOR:-}"}"
250+
if command -v sensible-editor >/dev/null; then
251+
editor=sensible-editor
252+
fi
253+
if [[ -z "$editor" ]]; then
254+
for e in nvim vim vi nano; do
255+
if command -v "$e" >/dev/null; then
256+
editor="$e"
257+
break
258+
fi
259+
done
260+
fi
261+
if [[ -z "$editor" ]]; then
262+
echo 'ERROR: Cannot determine sensible editor.' >&2
263+
echo
264+
echo "Set default editor with \$VISUAL or \$EDITOR environment variables." >&2
265+
exit
266+
fi
267+
"$editor" "$chat_list_file"
268+
}
269+
246270
send-message() {
247271
printf "Sending message to '%s'... " "$3"
248272
local result
@@ -373,6 +397,9 @@ ls | list-chats)
373397
rm | remove-chat)
374398
remove-chat "${cmd_args[@]}"
375399
;;
400+
e | edit | edit-chat-list)
401+
edit-chat-list
402+
;;
376403
send)
377404
send "${cmd_args[@]}"
378405
;;

0 commit comments

Comments
 (0)