Refactor xonsh config

This commit is contained in:
2022-01-06 16:50:56 -08:00
parent 33372e8300
commit 68d903d628
9 changed files with 96 additions and 91 deletions

11
xonsh/alias.xsh Normal file
View File

@@ -0,0 +1,11 @@
aliases["-"] = "cd -"
aliases[".."] = "cd .."
aliases["..."] = "cd ../.."
aliases["ec"] = "emacsclient -n --alternate-editor=vim"
aliases["src"] = "source ~/.xonshrc"
aliases["pubip"] = "curl icanhazip.com"
aliases["ll"] = lambda args: $[$LC_COLLATE='C' ls -lAh @(args)]

4
xonsh/java.xsh Normal file
View File

@@ -0,0 +1,4 @@
from xonsh.platform import ON_DARWIN
if ON_DARWIN:
$JAVA_HOME = $(/usr/libexec/java_home).strip()

4
xonsh/linux.xsh Normal file
View File

@@ -0,0 +1,4 @@
from xonsh.platform import ON_LINUX
if ON_LINUX:
aliases["pulsefix"] = "pulseaudio --kill; pulseaudio --start"

11
xonsh/nix.xsh Normal file
View File

@@ -0,0 +1,11 @@
from xonsh.platform import ON_DARWIN
# Nix integration
if ON_DARWIN:
nix_daemon_path = p"/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh"
if nix_daemon_path.exists():
source-bash @(nix_daemon_path)
nix_darwin_path = p"/etc/static/bashrc"
if nix_darwin_path.exists():
source-bash @(nix_darwin_path)

10
xonsh/path.xsh Normal file
View File

@@ -0,0 +1,10 @@
from pathlib import Path
from typing import List
def ensure_path(*paths: List[str]):
for p in paths:
abs_p = str(Path(p).expanduser().absolute())
if abs_p not in $PATH:
$PATH.insert(0, abs_p)
ensure_path("/usr/local/bin", "~/.dotfiles/bin", "~/.local/bin", "~/bin", "~/.emacs.d/bin")

25
xonsh/prompt.xsh Normal file
View File

@@ -0,0 +1,25 @@
# 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
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"

17
xonsh/python.xsh Normal file
View File

@@ -0,0 +1,17 @@
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

View File

@@ -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')

View File

@@ -1,4 +1,3 @@
xonsh[full]
xontrib-powerline-binding
xontrib-fzf-widgets
powerline_gitstatus
xonsh-direnv