rc.xsh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. # default locale
  31. # will be used for all non-explicitly set LC_* variables
  32. $LANG = 'en_US.UTF-8'
  33. # fallback locales
  34. # GNU gettext gives preference to LANGUAGE over LC_ALL and LANG
  35. # for the purpose of message handling
  36. # https://www.gnu.org/software/gettext/manual/html_node/The-LANGUAGE-variable.html
  37. # cave: if this list contains 'de(_.*)?' at any (sic!) position
  38. # vim 7.4.1689 will switch to german
  39. $LANGUAGE = ':'.join(['en_US', 'en'])
  40. $LC_COLLATE = 'C.UTF-8'
  41. # char classification, case conversion & other char attrs
  42. $LC_CTYPE = 'de_AT.UTF-8'
  43. # $ locale currency_symbol
  44. $LC_MONETARY = 'de_AT.UTF-8'
  45. # $ locale -k LC_NUMERIC | head -n 3
  46. # decimal_point="."
  47. # thousands_sep=""
  48. # grouping=-1
  49. $LC_NUMERIC = 'C.UTF-8'
  50. # A4
  51. $LC_PAPER = 'de_AT.UTF-8'
  52. USER_BIN_PATH = os.path.join($HOME, '.local', 'bin')
  53. if os.path.isdir(USER_BIN_PATH):
  54. $PATH.insert(0, USER_BIN_PATH)
  55. $EDITOR = 'vim'
  56. # required by pinentry-tty when using gpg command:
  57. $GPG_TTY = $(tty)
  58. if shutil.which('gpgconf'):
  59. # required by scute
  60. $GPG_AGENT_INFO = $(gpgconf --list-dir agent-socket).rstrip() + ':0:1'
  61. if not 'SSH_CLIENT' in ${...}:
  62. # in gnupg 2.1.13 the location of agents socket changed
  63. $SSH_AUTH_SOCK = $(gpgconf --list-dir agent-ssh-socket).rstrip()
  64. # wrapper for termite required when launching termite from ranger:
  65. $TERMCMD = os.path.join(os.path.dirname(__file__), 'ranger-termite-termcmd')
  66. def dpkg_listfiles(pkg_name):
  67. assert isinstance(pkg_name, str)
  68. paths = $(dpkg --listfiles @(pkg_name)).split('\n')[:-1]
  69. assert len(paths) > 0, 'pkg {!r} not installed'.format(pkg_name)
  70. return paths
  71. def dpkg_search(path_search_pattern):
  72. assert isinstance(path_search_pattern, str)
  73. return re.findall(
  74. '^(\S+): (.*)$\n',
  75. $(dpkg --search @(path_search_pattern)),
  76. flags=re.MULTILINE,
  77. )
  78. def dpkg_welse(cmd):
  79. pkg_name, cmd_path = dpkg_which(cmd)
  80. return dpkg_listfiles(pkg_name)
  81. def dpkg_which(cmd):
  82. cmd_path = shutil.which(cmd)
  83. assert cmd_path, 'cmd {!r} not found'.format(cmd)
  84. matches = dpkg_search(cmd_path)
  85. assert len(matches) != 0, '{!r} not installed via dpkg'.format(cmd_path)
  86. assert len(matches) == 1
  87. return matches[0]
  88. def locate(*patterns, match_all=True, ignore_case=True):
  89. params = []
  90. if match_all:
  91. params.insert(0, '--all')
  92. if ignore_case:
  93. params.insert(0, '--ignore-case')
  94. return $(locate @(params) -- @(patterns)).split('\n')[:-1]
  95. def timestamp_now_utc():
  96. return dt.datetime.utcnow().replace(tzinfo=dt.timezone.utc)
  97. def timestamp_now_local():
  98. # if called without tz argument astimezone() assumes
  99. # the system local timezone for the target timezone
  100. return timestamp_now_utc().astimezone()
  101. def timestamp_iso_local():
  102. # if called without tz argument astimezone() assumes
  103. # the system local timezone for the target timezone
  104. return timestamp_now_local().strftime('%Y%m%dT%H%M%S%z')
  105. aliases['dpkg-welse'] = lambda args: '\n'.join(dpkg_welse(args[0]))
  106. aliases['dpkg-which'] = lambda args: '\t'.join(dpkg_which(args[0]))
  107. aliases['g'] = ['git']
  108. aliases['ll'] = ['ls', '-l', '--all', '--indicator-style=slash',
  109. '--human-readable', '--time-style=long-iso', '--color=auto']
  110. if shutil.which('startx') and $(tty).rstrip() == '/dev/tty1':
  111. startx
  112. # vim: filetype=python