dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

message (2431B)


      1 #!/usr/bin/env bash
      2 set -e
      3 #set -v
      4 
      5 keyboard-layout-switch.sh dk
      6 
      7 # server running macos
      8 host="adamsgaard.dk"
      9 user="ad"
     10 port="12344"
     11 
     12 version=1.0
     13 
     14 function show_help {
     15     echo "usage: ${0##*/} [OPTIONS] RECIPIENT [RECIPIENT2 [RECIPIENT N]]"
     16     echo "will send stdin to recipients through $user@$host"
     17     echo "OPTIONS are one or more of the following:"
     18     echo "   -p, --prompt   show interactive dmenu prompt, otherwise read stdin"
     19     echo "   -h, --help     show this message"
     20     echo "   -v, --version  show version and license information"
     21     echo "   --             do not consider any following arguments as options"
     22     echo "${0##*/} requires ssh access to the system."
     23     echo "Example with stdin:"
     24     echo "   echo 'hi' | message 'Jack Jackson'"
     25 }
     26 
     27 function show_version {
     28     echo "${0##*/} version $version"
     29     echo "Licensed under the GNU Public License, v3+"
     30     echo "written by Anders Damsgaard, anders@adamsgaard.dk"
     31     echo "https://gitlab.com/admesg/dotfiles"
     32 }
     33 
     34 function die {
     35     printf '%s\n' "$1" >&2
     36     keyboard-layout-switch.sh us
     37     exit 1
     38 }
     39 
     40 
     41 prompt=0
     42 while :; do
     43     case "$1" in
     44         -h|-\?|--help)
     45             show_help
     46             keyboard-layout-switch.sh us
     47             exit 0
     48             ;;
     49         -v|--version)
     50             show_version
     51             keyboard-layout-switch.sh us
     52             exit 0
     53             ;;
     54         -p|--prompt)
     55             prompt=1
     56             ;;
     57         --) # end all options
     58             shift
     59             break
     60             ;;
     61         -?*)
     62             die 'Error: Unknown option specified'
     63             ;;
     64         *)  # No more options
     65             break
     66     esac
     67     shift
     68 done
     69 
     70 
     71 function send_message {
     72     cmd="osascript -e 'tell application \"Messages\" to send \"$2\" to buddy \"$1\"'"
     73     ssh -q -p "$port" "$user"@"$host" -t "$cmd"
     74 }
     75 
     76 if [ "$prompt" = 1 ]; then
     77     names="Susan Louise Damsgaard Sonnesen\nAnders Damsgaard\nJesper Hannibalsen\nSimon Svendsen\nNiels Christensen\nAnne Grethe Damsgaard Christensen\nLars Damsgaard Fink"
     78     recipient=$(echo -e "${names[@]}" | dmenu -i -p "To:" || exit 1)
     79     msg="$(echo ' ' | dmenu -i -p 'Message:')"
     80     send_message "$recipient" "$msg"
     81     keyboard-layout-switch.sh us
     82     exit 0
     83 else
     84     # stdin
     85     [ $# -lt 1 ] && die 'Error: No RECIPIENT[S] specified'
     86     msg="$(cat)"
     87 fi
     88 
     89 # loop over RECIPIENT[S]
     90 for recipient in "$@"; do
     91     send_message "$recipient" "$msg"
     92 done
     93 
     94 keyboard-layout-switch.sh us