rc.xsh 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. $VI_MODE = True
  2. $AUTO_PUSHD = True
  3. $XONSH_AUTOPAIR = True
  4. # tab selection: do not execute cmd when pressing enter
  5. $COMPLETIONS_CONFIRM = True
  6. xontrib load vox z
  7. def _last_exit_status():
  8. try:
  9. exit_status = __xonsh_history__.rtns[-1]
  10. return exit_status if exit_status != 0 else None
  11. except IndexError:
  12. return None
  13. $PROMPT_FIELDS['last_exit_status'] = _last_exit_status
  14. $XONSH_STDERR_PREFIX = '{RED}'
  15. $XONSH_STDERR_POSTFIX = '{NO_COLOR}'
  16. $DYNAMIC_CWD_WIDTH = '30%'
  17. $DYNAMIC_CWD_ELISION_CHAR = '…'
  18. $PROMPT = ''.join([
  19. '{RED}{last_exit_status:[{}] }',
  20. '{BOLD_GREEN}{user}@{hostname} ',
  21. '{YELLOW}{cwd} ',
  22. '{BLUE}{prompt_end} ',
  23. '{NO_COLOR}',
  24. ])
  25. $RIGHT_PROMPT = '{gitstatus}{env_name: {}}'
  26. import datetime as dt
  27. import os
  28. import re
  29. import shutil
  30. $EDITOR = 'vim'
  31. # required by pinentry-tty when using gpg command:
  32. $GPG_TTY = $(tty)
  33. if shutil.which('gpgconf'):
  34. # required by scute
  35. $GPG_AGENT_INFO = $(gpgconf --list-dir agent-socket).rstrip() + ':0:1'
  36. if not 'SSH_CLIENT' in ${...}:
  37. # in gnupg 2.1.13 the location of agents socket changed
  38. $SSH_AUTH_SOCK = $(gpgconf --list-dir agent-ssh-socket).rstrip()
  39. # wrapper for termite required when launching termite from ranger:
  40. $TERMCMD = os.path.join(os.path.dirname(__file__), 'ranger-termite-termcmd')
  41. def dpkg_search(path_search_pattern):
  42. assert isinstance(path_search_pattern, str)
  43. return re.findall(
  44. '^(\S+): (.*)$\n',
  45. $(dpkg --search @(path_search_pattern)),
  46. flags=re.MULTILINE,
  47. )
  48. def dpkg_which(cmd):
  49. cmd_path = shutil.which(cmd)
  50. assert cmd_path, 'cmd {!r} not found'.format(cmd)
  51. matches = dpkg_search(cmd_path)
  52. assert len(matches) in [0, 1]
  53. return matches[0] if len(matches) == 1 else None
  54. def locate(*patterns, match_all=True, ignore_case=True):
  55. params = []
  56. if match_all:
  57. params.insert(0, '--all')
  58. if ignore_case:
  59. params.insert(0, '--ignore-case')
  60. return $(locate @(params) -- @(patterns)).split('\n')[:-1]
  61. def timestamp_iso():
  62. # if called without tz argument astimezone() assumes
  63. # the system local timezone for the target timezone
  64. return dt.datetime.now().astimezone().strftime('%Y%m%dT%H%M%S%z')
  65. aliases['dpkg-which'] = lambda args: str(dpkg_which(args[0]))
  66. aliases['g'] = ['git']
  67. aliases['ll'] = ['ls', '-l', '--all', '--indicator-style=slash',
  68. '--human-readable', '--time-style=long-iso', '--color=auto']
  69. # vim: filetype=python