Files
dotfiles/xonsh/rc.xsh
2021-06-24 17:00:48 -07:00

98 lines
2.3 KiB
Plaintext

import shutil
from pathlib import Path
from typing import List
from xonsh.platform import ON_DARWIN, ON_LINUX
# Pip dependencies listed in requirements.txt
$fzf_history_binding = "c-r"
_xontribs = [
"vox",
"fzf-widgets",
"powerline_binding",
]
if _xontribs:
xontrib load @(_xontribs)
$UPDATE_OS_ENVIRON = True
$XONSH_SHOW_TRACEBACK = False
$XONSH_HISTORY_BACKEND = "sqlite"
$HISTCONTROL = "ignoredups"
$MULTILINE_PROMPT = " "
$PROMPT_REFRESH_INTERVAL = 1.0
$UPDATE_PROMPT_ON_KEYPRESS = True
aliases["-"] = "cd -"
aliases[".."] = "cd .."
aliases["..."] = "cd ../.."
$AUTO_CD = True
$MANPAGER = "less -X"
$LESS = "--ignore-case --quit-if-one-screen --QUIET --RAW-CONTROL-CHARS"
# ============
# Basics, etc…
# ============
$EDITOR = "emacsclient"
$ALTERNATE_EDITOR = "vim"
$TERMINAL = "kitty"
def ensure_path(*paths: List[str]):
for p in paths:
abs_p = str(Path(p).expanduser().absolute())
if abs_p not in $PATH:
$PATH.append(abs_p)
ensure_path("/usr/local/bin", "~/.dotfiles/bin", "~/.local/bin", "~/bin", "~/.emacs.d/bin")
config_dir = p"~/.dotfiles/xonsh"
if (config_dir / "local.xsh").exists():
source @(config_dir / "local.xsh")
aliases["ec"] = "emacsclient -n --alternate-editor=emacs"
aliases["src"] = "source ~/.xonshrc"
aliases["pubip"] = "curl icanhazip.com"
aliases["ll"] = lambda args: $[$LC_COLLATE='C' ls -lAh @(args)]
if ON_DARWIN:
$JAVA_HOME = $(/usr/libexec/java_home).strip()
if ON_LINUX:
aliases["pulsefix"] = "pulseaudio --kill; pulseaudio --start"
def _vv():
"""Finds the nearest venv going upward in the directory hierarchy and activates it."""
d = Path.cwd()
while True:
if (d / "venv").exists():
vox activate @(str(d / "venv"))
return True
if d == d.parent or (d / ".git").exists():
print("Could not find venv.")
return False
d = d.parent
aliases["vv"] = _vv
# # Hybrid Vi Mode
# set -g fish_key_bindings hybrid_bindings
# Fix prompt for Emacs TRAMP
# https://github.com/oh-my-fish/theme-bobthefish/issues/148
if $TERM == "dumb":
$PROMPT = "$ "
$RIGHT_PROMPT = None
$BOTTOM_TOOLBAR = None
# autojump equivalent
if shutil.which("zoxide"):
execx($(zoxide init xonsh --cmd j --hook prompt), 'exec', __xonsh__.ctx, filename='zoxide')