forked from cosmic/cosmic
added the -n switch
This commit is contained in:
parent
44f322cff5
commit
2232d61988
|
@ -62,6 +62,12 @@ parse_input () {
|
|||
flag_shortlist=1
|
||||
shift
|
||||
;;
|
||||
-n)
|
||||
arg_log=0
|
||||
shift
|
||||
arg_new="$1"
|
||||
shift
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
break
|
||||
|
@ -144,6 +150,30 @@ check_log () {
|
|||
fi
|
||||
}
|
||||
|
||||
new_message () {
|
||||
ship="$1"
|
||||
post_file="/var/gopher/${ship}/${2}"
|
||||
template_file="/var/gopher/${ship}/.template"
|
||||
temp_post=$(mktemp -t "$(basename "$0").post.XXXXXXX") || die "Failed to create temporary file" 1
|
||||
if [ -f "$post_file" ]; then
|
||||
cp "$post_file" "$temp_post"
|
||||
elif [ -f "$template_file" ]; then
|
||||
cp "$template_file" "$temp_post"
|
||||
fi
|
||||
temp_post_time=$(stat -c %Y "$temp_post")
|
||||
${EDITOR:-nano} "$temp_post"
|
||||
temp_post_time_check=$(stat -c %Y "$temp_post")
|
||||
if [ "$temp_post_time" -ne "$temp_post_time_check" ] ; then
|
||||
printf "Drafted message %s (%s)\\n" "$2" "$1"
|
||||
touch "${post_file}"
|
||||
cat "${temp_post}" > "${post_file}"
|
||||
rm "${temp_post}"
|
||||
else
|
||||
printf "Aborted message.\\n"
|
||||
rm "${temp_post}"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
parse_input "$@"
|
||||
|
||||
|
@ -190,6 +220,27 @@ main() {
|
|||
unset IFS
|
||||
fi
|
||||
fi
|
||||
|
||||
# new message
|
||||
if [ ! -z "$arg_new" ]; then
|
||||
if [ "$numships" -eq 0 ]; then
|
||||
printf "No registered ships found in system.\\n"
|
||||
elif [ "$numships" -eq 1 ]; then
|
||||
if [ -z "$arg_ship" ] || [ "$ships" = "$arg_ship" ]; then
|
||||
new_message "$ships" "$arg_new"
|
||||
fi
|
||||
else
|
||||
IFS='
|
||||
'
|
||||
for f in $ships
|
||||
do
|
||||
if [ "$f" = "$arg_ship" ]; then
|
||||
new_message "$arg_ship" "$arg_new"
|
||||
fi
|
||||
done
|
||||
unset IFS
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
##############################################################################
|
||||
|
@ -207,8 +258,9 @@ flag_version=0
|
|||
flag_debug=0
|
||||
flag_shortlist=0
|
||||
|
||||
arg_options="hvds:z"
|
||||
arg_options="hvds:zn:"
|
||||
arg_log=1
|
||||
arg_ship=""
|
||||
arg_new=""
|
||||
|
||||
main "$@"
|
||||
|
|
Loading…
Reference in New Issue