Refactor xonsh config
This commit is contained in:
102
xonsh/rc.xsh
102
xonsh/rc.xsh
@@ -1,115 +1,39 @@
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
from xonsh.platform import ON_DARWIN, ON_LINUX
|
||||
|
||||
# Pip dependencies listed in requirements.txt
|
||||
_xontribs = [
|
||||
"fzf-widgets",
|
||||
"direnv",
|
||||
"vox",
|
||||
]
|
||||
|
||||
$fzf_history_binding = "c-r"
|
||||
|
||||
_xontribs = [
|
||||
"vox",
|
||||
"fzf-widgets",
|
||||
# "powerline_binding",
|
||||
]
|
||||
|
||||
if _xontribs:
|
||||
xontrib load @(_xontribs)
|
||||
|
||||
$UPDATE_OS_ENVIRON = True
|
||||
$UPDATE_OS_ENVIRON = False
|
||||
$XONSH_SHOW_TRACEBACK = False
|
||||
$XONSH_HISTORY_BACKEND = "sqlite"
|
||||
$HISTCONTROL = "ignoredups"
|
||||
$MULTILINE_PROMPT = " "
|
||||
$UPDATE_PROMPT_ON_KEYPRESS = False
|
||||
|
||||
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"
|
||||
$EDITOR = "vim"
|
||||
$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"
|
||||
xsh_modules = ["prompt", "nix", "path", "alias", "java", "linux", "python", "local"]
|
||||
|
||||
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 not ${...}.get("TERM") or $TERM == "dumb":
|
||||
$PROMPT = "$ "
|
||||
$RIGHT_PROMPT = None
|
||||
$BOTTOM_TOOLBAR = None
|
||||
else:
|
||||
$PROMPT = \
|
||||
"{bg#2E3440}{RED}{localtime} " \
|
||||
"{#5E6470}\ue0b1 {YELLOW}{user}{DEFAULT}@{GREEN}{hostname} " \
|
||||
"{#5E6470}\ue0b1 {BLUE}{short_cwd} {DEFAULT}{env_name}{RESET}{#2E3440}\ue0b0\n" \
|
||||
"{RESET}{INTENSE_GREEN}{prompt_end}{RESET} "
|
||||
|
||||
# Color style to fix unreadable greys
|
||||
from xonsh.tools import register_custom_style
|
||||
ttm_style = {
|
||||
# Put custom overrides here
|
||||
# Discover list of styles by running "xonfig colors default"
|
||||
# Discover default mappings by cross referencing
|
||||
# https://github.com/xonsh/xonsh/blob/main/xonsh/style_tools.py
|
||||
# and
|
||||
# https://github.com/pygments/pygments/blob/master/pygments/styles/native.py
|
||||
}
|
||||
register_custom_style("ttm-style", ttm_style, base="native")
|
||||
$XONSH_COLOR_STYLE = "ttm-style"
|
||||
for module in xsh_modules:
|
||||
_p = config_dir / f"{module}.xsh"
|
||||
if _p.exists():
|
||||
source @(_p)
|
||||
|
||||
# autojump equivalent
|
||||
if shutil.which("zoxide"):
|
||||
if !(which zoxide):
|
||||
execx($(zoxide init xonsh --cmd j --hook prompt), 'exec', __xonsh__.ctx, filename='zoxide')
|
||||
|
||||
Reference in New Issue
Block a user