Skip to content

Instantly share code, notes, and snippets.

@angstwad
Created January 15, 2025 04:43
Show Gist options
  • Save angstwad/4195514b0c0277c16d2e7ae42853f5b4 to your computer and use it in GitHub Desktop.
Save angstwad/4195514b0c0277c16d2e7ae42853f5b4 to your computer and use it in GitHub Desktop.
Xonsh
$XONSH_SHOW_TRACEBACK = True
$PROMPT_COMMAND = 'history -a'
$HISTSIZE = 25000
$HISTCONTROL = 'ignoreboth'
$CLICOLOR = 1
$EDITOR = 'vim'
$HOMEBREW_NO_ENV_HINTS = 1
$PROJECTS = '~/projects'
$GOPATH = $PROJECTS + '/go'
print(__name__)
paths = ($GOPATH[0] + '/bin',
$HOME + '/.local/bin',
'/opt/homebrew/bin',
'/opt/homebrew/sbin',
'/Users/user/.cache/lm-studio/bin')
for path in reversed(paths):
if path not in $PATH:
$PATH.insert(0, path)
def prompt_():
$PROMPT_FIELDS['time_format'] = '%H:%M'
if __xonsh__.last is not None and __xonsh__.last.ended is True and __xonsh__.last.rtn:
p = '{BOLD_INTENSE_RED}✘-' + str(__xonsh__.last.rtn) + '{RESET} '
else:
p = '{BOLD_GREEN}✔{RESET} '
p += '{YELLOW}{cwd}{RESET} {gitstatus:[{}]}\n{localtime} {BLUE}{prompt_end}{RESET} '
return p
$PROMPT = prompt_
aliases['ll'] = "ls -lahG"
aliases['dig'] = "dig +nocmd +multiline"
aliases['grep'] = "grep --color=always"
aliases['egrep'] = "egrep --color=always"
aliases['gpf'] = 'git push --force-with-lease'
aliases['ql'] = 'qlmanage -p'
@aliases.register
def listen():
print('Getting listening processes; this may take a while...')
$[lsof -i -P | grep -i 'listen']
@aliases.register
@aliases.return_command
def _sudo(args):
proc = '/Users/durivage/.local/bin/pam_tid'
p = !(@(proc) --check)
if not p:
print('Enabling Touch ID for sudo..')
$[sudo @(proc)]
return ["sudo", *args]
@aliases.register
def _mktmpdir():
_dir = $(mktemp -d)
print(f"\nWorking in {_dir}")
print("Log out (exit, ^D) when finished to remove temp folder\n")
cd @(_dir)
xonsh -l
cd -
if !(rm -rf @(_dir)):
print("Deleted temp folder")
@aliases.register
def _update_ollama():
for line in $(ollama list).splitlines()[1:]:
pull, *_ = line.split()
print(f'\nPulling {pull}')
![ollama pull @(pull)]
@aliases.register
def _update_docker():
for line in $(docker images).splitlines()[1:]:
image, tag, *_ = line.split()
if tag == '<none>':
continue
pull = f'{image}:{tag}'
print(f'\nPulling {pull}')
![docker pull @(pull)]
print()
![docker system prune --force]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment