Added -C option + added warning function and more
This commit is contained in:
parent
1d32782593
commit
f4bca1586d
1 changed files with 21 additions and 8 deletions
29
matrix-send
29
matrix-send
|
@ -17,12 +17,16 @@ conf_error () {
|
|||
exit 2
|
||||
}
|
||||
|
||||
warning () {
|
||||
printf "\033[93;1mwarning:\033[0m $1\n"
|
||||
}
|
||||
|
||||
vargrep () {
|
||||
printf "$2\n" | grep "$1" $3
|
||||
}
|
||||
|
||||
usage () {
|
||||
printf "usage: matrix-send [-t type] [-c] [-h] [-V] message room\n"
|
||||
printf "usage: matrix-send [-t type] [-C config] [-chV] message room\n"
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
@ -31,6 +35,7 @@ help () {
|
|||
matrix-send: send a message to a Matrix room
|
||||
Options:
|
||||
-t type: change default event type
|
||||
-C config: use a custom configuration file
|
||||
-c: clear cached access tokens
|
||||
-h: show this help menu
|
||||
-V: show version and program information
|
||||
|
@ -130,9 +135,6 @@ ClearCache () {
|
|||
|
||||
Send () {
|
||||
curl -s -XPOST -d "{"'"'"msgtype"'"'":"'"'"$mtype"'"'", "'"'"body"'"'":"'"'"$message"'"'"}" "https://$server/_matrix/client/r0/rooms/%21$roomid/send/m.room.message?access_token=$token"
|
||||
#cat <<EOF
|
||||
#"{"'"'"msgtype"'"'":"'"'"$mtype"'"'", "'"'"body"'"'":"'"'"$message"'"'"}" "https://$server/_matrix/client/r0/rooms/%21$roomid/send/m.room.message?access_token=$token"
|
||||
#EOF
|
||||
}
|
||||
|
||||
########################
|
||||
|
@ -140,10 +142,10 @@ Send () {
|
|||
########################
|
||||
|
||||
[ -e /usr/local/bin/curl ] || [ -e /usr/bin/curl ] || error "curl not found"
|
||||
CacheLocation "$HOME/.cache"
|
||||
|
||||
[ -z "$1" ] && usage
|
||||
while getopts :t:chV opt
|
||||
CacheLocation "$HOME/.cache"
|
||||
while getopts :t:C:chV opt
|
||||
do
|
||||
case $opt in
|
||||
t)
|
||||
|
@ -154,20 +156,31 @@ do
|
|||
else error "Type not valid (-t)"
|
||||
fi
|
||||
;;
|
||||
C)
|
||||
if vargrep "^~" "$OPTARG" -Eq
|
||||
then config="$OPTARG"
|
||||
elif vargrep "^/" "$OPTARG" -Eq
|
||||
then config="$OPTARG"
|
||||
else error "Configuration file location not valid (-C)"
|
||||
fi
|
||||
;;
|
||||
c) ClearCache ;;
|
||||
h) help ;;
|
||||
V) version ;;
|
||||
esac
|
||||
done
|
||||
unset OPTARG
|
||||
unset OPTIND
|
||||
|
||||
###############################
|
||||
#### Configuration loading ####
|
||||
###############################
|
||||
|
||||
# Load configuration
|
||||
if [ -e $HOME/.config/matrix-send.conf ];
|
||||
then . $HOME/.config/matrix-send.conf;
|
||||
if [ -e "$config" ];
|
||||
then . "$config"
|
||||
else
|
||||
warning "~/.config/matrix-send.conf doesn't exist; creating it"
|
||||
mkdir -p $HOME/.config
|
||||
touch $HOME/.config/matrix-send.conf
|
||||
fi
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue