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