Skip to content

Instantly share code, notes, and snippets.

@jnoortheen
Last active November 20, 2020 07:32
Show Gist options
  • Save jnoortheen/8b5220f200bc5c9e121a7722836bf674 to your computer and use it in GitHub Desktop.
Save jnoortheen/8b5220f200bc5c9e121a7722836bf674 to your computer and use it in GitHub Desktop.
# My Xonsh setup

My Xonsh setup

I use this following directory structure to install and use xonsh with ease. It enables adding new xontribs easily and keep the user packages in single place in a maintainable way.

My xonsh config folder - ~/.config/xonsh looks like this

~/.config/xonsh                                                                              🤖noor🖥firefist 🕰️ 12:36:51P 
 🐍xonsh $ tree -L 1 -a                                                                                                       
.
|-- .gitignore      # like in anyother Python project. This is important since I track this folder using [yadm](https://yadm.io/)
|-- .idea           # I use pycharm to edit the xonsh config files. this contains certain interpreter settings.
|-- .local          # scratch files 
|-- .venv           # the xonsh installation directory
|-- .vscode         # *.xonsh file type settings
|-- abbrevs.py      # loaded by main main rc.xsh
|-- aliases.py      # loaded by main main rc.xsh
|-- poetry.lock  
|-- poetry.toml     # configures the virtualenv location
|-- pyproject.toml  # tracks the dependencies for my xonsh setup
|-- rc.xsh          # the entry point loaded by xonsh on startup
|-- readme.md       # I track my todos here
|-- scripts         # some system scripts
|-- snippets        # some useful snippets for rememberance
|-- user_xsh        # the package that is importable from xonsh shell. this installed when running `poetry install`
|-- user_xsh.egg-info 
|-- variables.py    # environment variables
`-- xsh-src         # xonsh source code - `git clone https://github.com/jnoortheen/xonsh xsh-src`

10 directories, 9 files

Here I have posted certain files that might be interesting.

After doing a poetry install I am good to use the xonsh binary by creating a symlink

ln -s ~/.config/xonsh/.venv/bin/xonsh ~/.local/bin

$PATH already contains ~/.local/bin and I can start calling xonsh from bash like this

# excerpt from ~/.bashrc

# ...
# ############ ssh agent config ###############
eval $(keychain --eval id_ed25519)


# this should be the last point
if [[ $(ps --no-header --pid=$PPID --format=comm) != "xonsh" ]]
then
	exec xonsh
fi
{
"files.exclude": {
".cache/**": true,
"**/__pycache__/**": true,
"**/.docker": true,
"**/.venv": true,
"**/.idea": true,
"**/.jscpd": true,
"**/*.pyc": true,
"**/docs": true
},
"python.autoComplete.extraPaths": [
"~/.config/xonsh/.venv/lib/python3.8/site-packages/xonsh/__amalgam__.py",
"user_xsh"
],
"python.analysis.extraPaths": [
"user_xsh"
],
"python.formatting.provider": "black",
"restructuredtext.confPath": "",
"[xonsh]": {
"editor.formatOnSave": false
}
// "restructuredtext.confPath": ""
}
lf = "lefthook"
ll = "ls -alh"
dc = "docker-compose"
dr = "docker run --rm -ti"
drun = "docker run --rm -ti"
pm = "python manage.py"
pmm = "python manage.py migrate"
pmk = "python manage.py makemigrations"
grep = "grep --ignore-case"
# nix os
osbuild = "sudo nixos-rebuild"
oswitch = "os-build switch"
ostest = "os-build test"
cat = "bat"
time = "time -p"
xsh = "~/.config/xonsh"
xcode = "code ~/.config/xonsh"
xalias = "code ~/.config/xonsh/aliases.py"
abbr = "code ~/.config/xonsh/abbrevs.py"
cola = "git-cola 2> /dev/null &"
gl = "git log --oneline --all --graph"
gf = "git fetch --all --prune --tags"
gp = "git push --follow-tags"
gpl = "git pull"
gc = "git commit -m ! "
gca = "git commit --amend"
gcan = "git commit --amend --no-edit"
gcd = "git checkout develop"
gcdm = "git checkout develop && git merge master"
gcm = "git checkout master"
gcmd = "git checkout master && git merge develop"
sstart = "sudo systemctl start"
sstop = "sudo systemctl stop"
srestart = "sudo systemctl restart"
sstatus = "sudo systemctl status"
senable = "sudo systemctl enable"
sdisable = "sudo systemctl disable"
smask = "sudo systemctl mask"
sunmask = "sudo systemctl unmask"
sreload = "sudo systemctl daemon-reload"
sfailed = "sudo systemctl list-units --failed"
ustart = "systemctl start --user"
ustop = "systemctl stop --user"
urestart = "systemctl restart --user"
ustatus = "systemctl status --user"
uenable = "systemctl enable --user"
udisable = "systemctl disable --user"
ureload = "sudo systemctl daemon-reload --user"
pipup = "pip install --upgrade pip"
# yay = "yay --cleanafter"
fsi = "dotnet fsi"
dtest = "docker-compose -f docker-compose.yml -f docker/docker-compose.test.yml"
dprod = "docker-compose -f docker-compose.yml -f docker/docker-compose.prod.yml"
dstag = "docker-compose -f docker-compose.yml -f docker/docker-compose.stag.yml"
mem = "smem -ktP"
code = "code-insiders"
bat = "bat --terminal-width -5"
less = 'bat --paging=always --pager "less -RF"'
ls = "exa"
diff = "colordiff"
tmux = "tmux -2" # Force 256 colors
jq = "jq -C" # Force colors
rg = "rg --color always" # Force color # ripgrep
ssh = "kitty +kitten ssh"
[virtualenvs]
in-project = true
[tool.poetry]
authors = ["Noortheen Raja <jnoortheen@gmail.com>"]
description = ""
name = "user_xsh"
version = "0.1.0"
[tool.poetry.dependencies]
pygments = "^2.6.1"
python = "^3.6"
xonsh = { path = "./xsh-src", extras = ["ptk", "linux"], develop = true }
# xonsh = { version = "^0.9.18" }
xontrib-output-search = "^0.5"
xontrib-powerline2 = "^1.1.0"
tomlkit = "^0.6.0"
funcy = "^1.14"
plumbum = "^1.6.9"
# dbus-python = "^1.2.16"
distro = "^1.5.0"
# xontrib-readable-traceback = "^0.3.2"
setproctitle = "^1.1.10"
xontrib-argcomplete = "^0.0.7"
loguru = "^0.5.3"
defopt = "^6.0.1"
sniffer = "^0.4.1"
watchdog = "^0.10.3"
pyinotify = "^0.9.6"
argh = "^0.26.2"
pyte = "^0.8.0"
sh = "^1.14.0"
psutil = "^5.7.2"
xontrib-hist-navigator = "^0.5.1"
xontrib-cmd-done = "^0.2.2"
xontrib-kitty = "^0.0.2"
xontrib-back2dir = { git = "https://github.com/jnoortheen/xontrib-back2dir" }
marcel = "^0.11.9"
rich = "^9.1.0"
jedi = "^0.17.2"
pipe = { git = "https://github.com/jnoortheen/pipe" }
limeade = "^0.1.1"
[tool.poetry.dev-dependencies]
ipython = "*"
pdbpp = "*"
flake8 = "*"
pytest = "^6.0.2"
pytest-cov = "^2.10.1"
pytest-timeout = "^1.4.2"
better_exceptions = "*"
fixit = "^0.1.0"
mypy_extensions = "^0.4.3"
watchdog = "^0.10.3"
mypy = "^0.782"
black = { extras = ["d"], version = "^20.8b1" }
[build-system]
build-backend = "poetry.masonry.api"
requires = ["poetry>=0.12"]
import builtins
from pathlib import Path
from xonsh.xontribs import xontribs_load
from user_xsh.utils import update_xonsh_dict
builtins.__xonsh__.env['XONTRIB_OUTPUT_SEARCH_KEY'] = 'i'
# xontrib load output_search # https://github.com/tokenizer/xontrib-output-search
xontribs_load([
"vox",
"abbrevs",
"hist_navigator",
"pdb",
"autovox",
"jedi",
"prompt_ret_code",
# "readable-traceback",
"argcomplete",
"cmd_done",
"kitty",
"back2dir",
])
from user_xsh.fns import * # noqa # import some useful functions
from pipe import * # import pipe enabled functions
import user_xsh.evnt_hooks # noqa
from user_xsh.history import completer # noqa - import history completer
# add for github pushes
# source-zsh eval "$(ssh-agent -s)" && ssh-add ~/.ssh/id_ed25519
for file, var in [
("variables.py", builtins.__xonsh__.env),
("abbrevs.py", builtins.abbrevs),
("aliases.py", builtins.aliases),
]:
update_xonsh_dict(Path(__file__).with_name(file), var)
from user_xsh.prompt import with_color
import os
# $PYTHONBREAKPOINT="pudb.set_trace"
from user_xsh.prompt.processor import process_prompt_tokens
VC_BRANCH_TIMEOUT = 10 # default 0.1 seconds
ENABLE_ASYNC_PROMPT = True
ASYNC_PROMPT_THREAD_WORKERS = 20
VIRTUAL_ENV_DISABLE_PROMPT = False
AUTO_CD = True # change directory without cd
XONSH_SHOW_TRACEBACK = True
# AUTO_SUGGEST_IN_COMPLETIONS = True
CASE_SENSITIVE_COMPLETIONS = False
BETTER_EXCEPTIONS = 1
# While tab-completions menu is displayed,
# press <Enter> to confirm completion instead of running command.
COMPLETIONS_CONFIRM = True
COMPLETION_IN_THREAD = True
COMPLETIONS_DISPLAY = "multi"
COMPLETIONS_MENU_ROWS = 5
# The number of completions to display before the user is asked for confirmation.
COMPLETION_QUERY_LIMIT = 20
# PROMPT_REFRESH_INTERVAL = 10
# https://github.com/santagada/xontrib-powerline/blob/master/xontrib/powerline.xsh
PROMPT = "".join(
[
"{vte_new_tab_cwd}",
"{cwd}",
"{gitstatus:{}}",
"{ret_code}",
os.linesep,
"{full_env_name: 🐍{}}",
"$",
]
)
RIGHT_PROMPT = "".join(
[
with_color("long_cmd_duration", prefix="⌛"),
with_color("user", "red", bold=True, prefix="🤖"),
with_color("hostname", "#FA8072", bold=True, prefix="🖥"),
with_color("localtime", "#DAF7A6", slow_blink=True, prefix=" 🕰️ ", suffix=" "),
]
)
PROMPT_TOKENS_FORMATTER = process_prompt_tokens
# Completions display is evaluated and presented whenever a key is pressed. This avoids the need to press TAB
# having some issues with history completer. It doesn't show full line. circling long python codes become a problem.
# UPDATE_COMPLETIONS_ON_KEYPRESS = True
# MOUSE_SUPPORT = True # scroll is not working if enabled
HISTCONTROL = "erasedups"
XONSH_AUTOPAIR = True # paranthesis and brackets completion
XONSH_COLOR_STYLE = (
# 'colorful'
"native"
)
# https://xon.sh/tutorial_hist.html#sqlite-history-backend
XONSH_HISTORY_BACKEND = "sqlite"
XONSH_HISTORY_MATCH_ANYWHERE = True
XONSH_HISTORY_SIZE = (1_00_00_000, "commands")
# docker building using buildkit
COMPOSE_DOCKER_CLI_BUILD = 1
DOCKER_BUILDKIT = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment