#!/usr/bin/env python3

# http://inamidst.com/saxo/
# Created by Sean B. Palmer

import os
import subprocess

import saxo

def shell(*args):
    return str(subprocess.check_output(list(args)), "utf-8").rstrip("\r\n")

@saxo.pipe
def t(arg):
    arg = arg if arg else saxo.env("url")
    if not arg:
        return "Give me a link, a twitter ID, or a twitter name"

    commands = os.path.dirname(__file__)
    title = os.path.join(commands, "title")
    tw = os.path.join(commands, "tw")

    if arg[0] in "0123456789":
        return shell(tw, arg)
    elif "//twitter.com/" in arg:
        return shell(tw, arg)
    elif "/" in arg:
        return shell(title, arg)
    else:
        return shell(tw, arg)
