├── readme.md └── tw /readme.md: -------------------------------------------------------------------------------- 1 | # twsh 2 | > a [twtxt](https://github.com/buckket/twtxt) client written in bash 3 | -------------------------------------------------------------------------------- /tw: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # twsh - a twtxt client written in bash 3 | # (c) 2019 by Anirudh Oppiliappan (@icyphox) 4 | # and Akshay Oppiliappan (@nerdypepper) 5 | 6 | 7 | # uses default as $HOME 8 | CONFIG_DIR="$HOME" 9 | 10 | if [[ "$OSTYPE" = "linux-gnu" ]]; then 11 | CONFIG_DIR="$HOME/.config/twsh" 12 | elif [[ "$OSTYPE" = "darwin" ]]; then 13 | CONFIG_DIR="$HOME/Library/Preferences/com.icyphox.twsh" 14 | fi 15 | 16 | CONFIG="$CONFIG_DIR/twshrc" 17 | 18 | # sourcing our config 19 | if [[ -f "$CONFIG" ]] 20 | then 21 | source "$CONFIG" 22 | if [[ "$TWTXT_FILE" == "" ]] 23 | then 24 | echo "twsh: unable to source config" 25 | exit 26 | fi 27 | fi 28 | 29 | function create_config() { 30 | mkdir -p "$CONFIG_DIR" 31 | touch "$CONFIG" 32 | twtxt_path=$(readlink -f "$1") 33 | cat << EOF > "$CONFIG" 34 | TWTXT_FILE="$twtxt_path/twtxt.txt" 35 | EOF 36 | echo "twsh: created config at $CONFIG" 37 | source "$CONFIG" 38 | } 39 | 40 | function create_twtxt() { 41 | if [[ -f "$TWTXT_FILE" ]] 42 | then 43 | read -p "twsh: $TWTXT_FILE exists, overwrite? [y/n]: " yn 44 | case $yn in 45 | [Yy]* ) >$TWTXT_FILE ;; 46 | [Nn]* ) exit ;; 47 | * ) echo "twsh: enter yes or no" 48 | esac 49 | else 50 | touch "$TWTXT_FILE" 51 | echo "twsh: created $TWTXT_FILE" 52 | fi 53 | } 54 | 55 | function tweet() { 56 | text="$1" 57 | date=$(date -Im) 58 | tweet="$date\t$text" 59 | echo -e "$tweet" >> "$TWTXT_FILE" 60 | } 61 | 62 | 63 | function help_text () { 64 | cat << EOF 65 | usage: twsh [options] 66 | -i [path] create twtxt.txt file 67 | -t [text] append tweet to twtxt.txt file 68 | -h show this help text 69 | EOF 70 | } 71 | 72 | while getopts :iht: options 73 | do 74 | case $options in 75 | i) 76 | # init 77 | create_config "$2" 78 | create_twtxt "$2" 79 | ;; 80 | h) 81 | help_text 82 | ;; 83 | t|?) 84 | # tweet 85 | tweet "$OPTARG" 86 | ;; 87 | h|*) 88 | help_text 89 | ;; 90 | esac 91 | done 92 | --------------------------------------------------------------------------------