xonshrc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. # coding: utf-8
  2. # -*- mode: xonsh; -*-
  3. import os
  4. import shlex
  5. from shutil import which
  6. source-foreign zsh --login True --overwrite-alias "echo loading xonsh foreign shell"
  7. xontrib load readable-traceback
  8. if ${...}.get('INSIDE_EMACS', False):
  9. $TITLE = None
  10. else:
  11. $TITLE = '{current_job:{} | }{user}@{hostname}: {short_cwd} | xonsh'
  12. if $TERM == "dumb":
  13. $PS1="> "
  14. $HOME = os.path.expanduser('~')
  15. $PATH.insert(0, $HOME + '/.bin')
  16. $PATH.insert(0, $HOME + '/.local/bin')
  17. $SHELL_TYPE = 'prompt_toolkit'
  18. if os.path.exists(f'{$HOME}/.pyenv'):
  19. $PYENV_ROOT = f'{$HOME}/.pyenv'
  20. $PATH.insert(0, $PYENV_ROOT + '/bin')
  21. source-foreign zsh --overwrite-alias $(pyenv init -)
  22. source-foreign zsh --overwrite-alias $(pyenv virtualenv-init -)
  23. $BASH_COMPLETIONS.insert(0, $PYENV_ROOT + '/completions')
  24. if os.path.exists(f'{$HOME}/.emacs.d/bin'):
  25. $PATH.insert(0, $HOME + '/.emacs.d/bin')
  26. # Enable AUTO_CD
  27. $AUTO_CD = True
  28. # Default
  29. $BROWSER = "firefox"
  30. $TERM = "screen-256color"
  31. $EDITOR = '/usr/bin/emacs'
  32. # $GDK_SCALE = 2
  33. # $GDK_DPI_SCALE = 0.5
  34. # Encoding
  35. $LANG = "es_EC.UTF-8"
  36. $LC_ALL = "es_EC.UTF-8"
  37. # keep the prompt short
  38. $DYNAMIC_CWD_WIDTH = '20%'
  39. # ptk display stuff
  40. $CASE_SENSITIVE_COMPLETIONS = False
  41. $COMPLETIONS_BRACKETS = True
  42. $COMPLETIONS_CONFIRM = True
  43. # Less Stuff
  44. $PAGER = 'eless'
  45. $LESS = '-iMSx4 -FX'
  46. # Ignore Errors
  47. $XONSH_ENCODING_ERRORS = 'ignore'
  48. $XONSH_GITSTATUS_HASH = "{NO_COLOR}:"
  49. $XONSH_GITSTATUS_BRANCH = "{BOLD_PURPLE}"
  50. $XONSH_GITSTATUS_OPERATION = "{CYAN}"
  51. $XONSH_GITSTATUS_STAGED = "{RED}●"
  52. $XONSH_GITSTATUS_CONFLICTS = "{RED}×"
  53. $XONSH_GITSTATUS_CHANGED = "{BOLD_BLUE}+"
  54. $XONSH_GITSTATUS_UNTRACKED = "{NO_COLOR}…"
  55. $XONSH_GITSTATUS_CLEAN = "{BOLD_GREEN}✔"
  56. $XONSH_GITSTATUS_AHEAD = "{NO_COLOR}↑"
  57. $XONSH_GITSTATUS_BEHIND = "{NO_COLOR}↓"
  58. $SUPPRESS_BRANCH_TIMEOUT_MESSAGE = True
  59. def pyenv_prompt():
  60. pyenv_name = ""
  61. if $(pyenv version-name).replace('\n', '') != 'system':
  62. pyenv_name = $(pyenv version-name).replace('\n', '')
  63. return pyenv_name
  64. $PROMPT_FIELDS['pyenv_prompt'] = pyenv_prompt
  65. $PROMPT = "{BOLD_WHITE}{pyenv_prompt}{NO_COLOR}{BOLD_BLUE} »{NO_COLOR} "
  66. $RIGHT_PROMPT = "{gitstatus: {}} {BOLD_INTENSE_BLACK}{short_cwd}{NO_COLOR} "
  67. # Aliases (yeah... no shit, kid)
  68. def _pyclean():
  69. from os.path import Path
  70. d = Path($PWD)
  71. bflist = ["c", "o"]
  72. for b in bflist:
  73. files = d.walkfiles("*.py{}".format(b))
  74. for f in files:
  75. f.remove_p()
  76. for dir in d.walkdirs("__pycache__"):
  77. dir.removedirs_p()
  78. return True
  79. def _get_branch_name():
  80. import os
  81. from subprocess import call, STDOUT, check_output
  82. branch = ""
  83. if not call(["git", "branch"], stderr=STDOUT, stdout=open(os.devnull, 'w')) != 0:
  84. out = check_output(["git", "branch"]).decode("utf8")
  85. current = next(line for line in out.split("\n") if line.startswith("*"))
  86. branch = current.strip("*").strip()
  87. return branch, call
  88. def _git_pull_current_branch():
  89. branch, call = _get_branch_name()
  90. if branch:
  91. call(["git", "pull", "origin", branch])
  92. def _git_push_current_branch():
  93. branch, call = _get_branch_name()
  94. if branch:
  95. call(["git", "push", "origin", branch])
  96. custom = {}
  97. pairs = (
  98. ("dt", "dotdrop -c ~/.dotdrop.yml"),
  99. ("ls", "exa"),
  100. ("mkdir", "mkdir -p"),
  101. ("lookup", '/usr/bin/dict'),
  102. ("next", '/usr/bin/next'),
  103. ("ping", 'ping -4'),
  104. ("rm", "safe-rm"),
  105. ('cp', 'acp -g'),
  106. ('mv', 'amv -g'),
  107. ('pyc', _pyclean),
  108. ('pyi', 'python setup.py install'),
  109. ('pyd', 'python setup.py develop'),
  110. ('pyb', 'python setup.py build'),
  111. ('ggpull', _git_pull_current_branch),
  112. ('ggpush', _git_push_current_branch),
  113. ('ggpt', 'git pull --tags'),
  114. ('dco', 'docker-compose'),
  115. ('dcb', 'docker-compose build'),
  116. ('dce', 'docker-compose exec'),
  117. ('dcps', 'docker-compose ps'),
  118. ('dcrestart', 'docker-compose restart'),
  119. ('dcrm', 'docker-compose rm'),
  120. ('dcr', 'docker-compose run'),
  121. ('dcstop', 'docker-compose stop'),
  122. ('dcup', 'docker-compose up'),
  123. ('dcupd', 'docker-compose up -d'),
  124. ('dcdn', 'docker-compose down'),
  125. ('dcl', 'docker-compose logs'),
  126. ('dclf', 'docker-compose logs -f'),
  127. ('dcpull', 'docker-compose pull'),
  128. ('dcstart', 'docker-compose start'),
  129. )
  130. for pair in pairs:
  131. key, name = pair
  132. if callable(name):
  133. name.__xonsh__threadable = False
  134. name.__xonsh__capturable = False
  135. if callable(name) or which(shlex.split(name)[0]) is not None:
  136. custom[key] = name
  137. aliases.update(custom)
  138. del os
  139. del shlex