# -*- python -*-
from functools import partial
from os.path import join

import requests

# prompt isn't repainting correctly
#import xontrib.prompt_vi_mode

# Basic Usability
aliases['l'] = 'ls -l'
aliases['la'] = 'ls -la'
aliases['e'] = 'emacsclient -t'
aliases['v'] = 'vim'

# Navigation
aliases['ghn'] = 'cd /wayfair/home/gehrman'

# Tmux
aliases['tms'] = 'tmux source'
aliases['tmls'] = 'tmux list-sessions'
aliases['tma'] = 'tmux attach -d'
aliases['tmat'] = 'tmux attach -d -t'
aliases['->'] = 'echo "->"'
aliases['-->'] = 'echo "+>"'
aliases['@->'] = 'echo "@->"'


# Virtualenv aliases
alias createvirtualenv='. ~/.bin/create_virtualenv.sh'
alias recreatevirtualenv='. ~/.bin/recreate_virtualenv.sh'
alias startvirtualenv='. ~/.bin/start_virtualenv.sh'
alias stopvirtualenv='deactivate' # Included for completeness... it's a silly thing to do.
alias destroyvirtualenv='. ~/.bin/destroy_virtualenv.sh'
alias listvirtualenvs='. ~/.bin/list_virtualenvs.sh'
alias annotatevirtualenv='. ~/.bin/annotate_virtualenv.sh'
alias listinstalledeggs='. ~/.bin/list_installed_eggs.sh'


# Xonsh specific functionality
aliases['xonpip'] = '/usr/local/Cellar/xonsh/0.4.7_1/libexec/bin/pip'

# Old Lisp idiom for prepending when you can only append.
# TODO: make this idempotent
$PATH.reverse()
$PATH.extend(['/Library/TeX/texbin', '/usr/local/bin', join($HOME, '.bin')])
$PATH.reverse()

# TODO: Refactor this.
$PROMPT = '{env_name:{} }{BOLD_GREEN}{user}{YELLOW}@{BOLD_BLUE}{hostname} {CYAN}{cwd}{NO_COLOR}\n({CYAN}0{NO_COLOR}) {RED}__{NO_COLOR}_/{YELLOW}\\_{NO_COLOR}_/{RED}\\_{PURPLE}p{YELLOW}~{NO_COLOR} : '
$RIGHT_PROMPT = '{curr_branch: {}}{branch_color}'
$PYTHONSTARTUP = join($HOME, '.pythonrc')

# Vi-Mode is de-rigeour
$VI_MODE = True

# Taken from xon.sh/xonshrc.html
$MULTILINE_PROMPT = '`·.,¸,.·*¯`·.,¸,.·*¯'
$XONSH_SHOW_TRACEBACK = True
$XONSH_STORE_STDOUT = True

# Vox Config
$VIRTUALENV_HOME = join($HOME, 'Dev/envs')

# Test aliasing a function
def http_request(method, protocol, url, *args):
    """Do an HTTP requst of some type.

    Args:
        url: actually a list
    """
    clean_url = protocol + url[0] if not url[0].startswith(protocol) else url[0]
    print(method(clean_url))


def my_get(input, *args):
    url = input[0]
    print(requests.get(url))
def my_head(input, *args):
    url = input[0]
    print(requests.head(url))

aliases['get->'] = lambda url, *args: http_request(requests.get, 'http', url, *args)
aliases['get~>'] = partial(http_request, method=requests.get, protocol='https')

aliases['head->'] = my_head
aliases['p->'] = 'echo "test"'
aliases['g>'] = 'echo "test"'
aliases['p>'] = 'echo "test"'
