Giter Site home page Giter Site logo

matrix.sh's Introduction

matrix.sh

matrix.sh is a bash script to send messages to a matrix chat.

Features

  • Interactively log in to a server.
  • Select a default chat to use.
  • Send text messages.
  • Optionally enable parsing of HTML tags.
  • Directly pipe command output to the script and get it automatically wrapped in <pre> tags.
  • Send files, optionally as audio, image or video.

Installation

  • Download matrix.sh, either by using git clone or something like wget ... and put it somewhere in your path or whatever.

  • Install dependencies:

    • curl
    • jq
    • file
    • coreutils (required for du -b)

    Something like sudo apt-get install curl jq.

  • Use it to log in. See Usage.

Usage

Logging in

Use --login. The script will try to resolve delegation via the /.well-known/matrix/server path. If that doesn't work, you'll get an error message.

Your login token will be saved to the file .matrix.sh in your home folder. If it already exists, it will be overwritten. Since the contents of this file allow accessing your homeserver, you should keep it's contents secret. Therefore, it will be created with access mode 600.

$ ./matrix.sh --login
Address of the homeserver the account lives on: matrix.org
Username on the server (just the local part, so e.g. 'bob'): bob
bob's password:

Success. Access token saved to ~/.matrix.sh
You should now use ./matrix.sh -s to select a default room.

Login also sets a name for the device you're using to connect. Per default, this is <user>@<host> using matrix.sh, but you can set another name using the --identifier option:

$ ./matrix.sh --login --identifier="linux server @home"

Selecting a default room

You can select a default room which will be used if you don't provide a room_id at runtime.

It will show all joined rooms as well as rooms you are invited to. Selecting one of the latter will also accept the invitation and join that room.

$ ./matrix.sh --select-default-room
Getting Rooms...
Joined rooms:
  !GCHxYlasvdh778dsOx:matrix.org - Me and my server
  !OEassajhhkasLULVAa:matrix.org - <Unnamed>

Rooms I'm invited to:
  !2o587thjlgjHUIUHni:matrix.org - <Unnamed>

Which room do you want to use?
Enter the room_id (the thing at the beginning of the line):
!2o587thjlgjHUIUHni:matrix.org

Saved default room to ~/.matrix.sh

Without logging in

You can also use this script without logging in first. If you have an access token, you can use it like this:

$ ./matrix.sh --homeserver=https://matrix.org --token=abcdefg --room=\!2o587thjlgjHUIUHni:matrix.org ...

Sending messages

Sending a normal text message:

$ ./matrix.sh --send "Hello World"

Since --send is the default action, you can simply omit it:

$ ./matrix.sh "Hello World"

Sending a text message with markup:

$ ./matrix.sh --html "This is <strong>very important</strong>."

Piping command output:

$ echo "Hello" | ./matrix.sh -

Code formatting:

You can use --pre to send messages formatted as code. This will also escape HTML tags.

$ ls -l | ./matrix.sh --pre -

Sending files:

$ ./matrix.sh --file=upload.zip

Additionally use --audio, --image or --video to send files as audio, images or video, respectively:

$ ./matrix.sh --file=IMG1234.jpg --image

Providing a room:

You can use --room=<room_id> to provide a room_id. This supersedes the default room.

$ ./matrix.sh --room='!OEassajhhkasLULVAa:matrix.org' "Hello World"

(Note: bash doesn't like exclamation marks in double quoted strings. So we use single quotes for the room id.)

Other actions are:

  • --help shows all available commands and options.
  • --join-room joins a room. You will be asked for the room id.
  • --invite-user invites a user into the default room or the one given by --room. You will be asked for the user id.
  • --leave-room leaves a room. You will be asked which room to leave.

matrix.sh's People

Contributors

efelon avatar fabianonline avatar mgoellnitz avatar rom4nik avatar uweber avatar wioxjk avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.