@@ -49,6 +49,7 @@ usage() {
49
49
echo " $bin_name add|add-chat add chat to chat-list" >&2
50
50
echo " $bin_name ls|list-chats print chat-list" >&2
51
51
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
52
53
echo " $bin_name [-f|--format <format>] send [msg] [*chat ids] send message" >&2
53
54
echo " $bin_name -v|--version|version print version information" >&2
54
55
echo " $bin_name -h|--help|usage|help display this help message" >&2
@@ -243,6 +244,29 @@ remove-chat() {
243
244
sed -i " /^${chat_id/#@/ -} /d" " $chat_list_file "
244
245
}
245
246
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
+
246
270
send-message () {
247
271
printf " Sending message to '%s'... " " $3 "
248
272
local result
@@ -373,6 +397,9 @@ ls | list-chats)
373
397
rm | remove-chat)
374
398
remove-chat " ${cmd_args[@]} "
375
399
;;
400
+ e | edit | edit-chat-list)
401
+ edit-chat-list
402
+ ;;
376
403
send)
377
404
send " ${cmd_args[@]} "
378
405
;;
0 commit comments