This commit is contained in:
Riley Housden 2022-06-25 00:09:01 -04:00
parent e0488cf830
commit 0f5bbd78ad
Signed by: InValidFire
GPG Key ID: 0D6208F6DF56B4D8
5 changed files with 46 additions and 7 deletions

3
.vimrc
View File

@ -12,7 +12,6 @@ if $TERM == 'tmux-256color'
let &t_8b = "\033[48;2;%lu;%lu;%lum"
endif
set termguicolors
set background=dark
syntax enable
@ -66,5 +65,7 @@ Plug 'preservim/nerdtree'
Plug 'chiel92/vim-autoformat'
Plug 'natebosch/vim-lsc'
Plug 'https://tildegit.org/sloum/gemini-vim-syntax'
Plug 'meatballs/vim-xonsh'
Plug 'davidhalter/jedi-vim'
call plug#end()

View File

@ -6,15 +6,12 @@ elif $HOSTNAME == "riley-server":
elif $HOSTNAME == "riley-desktop":
$PROMPT = '{RED} >< {RESET}| {BOLD_GREEN}{cwd_base}{RESET} ) '
$XONSH_COLOR_STYLE = 'default'
xontrib load argcomplete autovox jedi z bashisms
xontrib load argcomplete autovox jedi z bashisms jds
source "~/xsh/functions.xsh"
source "~/xsh/exceptions.xsh"
source "~/xsh/aliases.xsh"
# TODO: Fix with Arch-based distros
# import addins # my extra stuffs :p
# Windows Subsystem for Linux stuff
if in_wsl():
$GPG_TTY=$(tty) # allows gpg to work inside WSL

41
xontrib/jds.xsh Normal file
View File

@ -0,0 +1,41 @@
"""Integrates Johnny Decimal Notation into Xonsh"""
from xonsh.built_ins import XSH
HOME = p"/run/media/riley/drive"
def find_category(number: int, path, regex: str):
"""Find matching JDN folder when given notation"""
import re
folders = path.iterdir()
for folder in folders:
if not folder.is_dir():
continue
folder_category = re.match(regex, folder.name)
if folder_category is None:
continue
if len(folder_category.groups()) == 2:
if number >= int(folder_category.group(1)) and number <= int(folder_category.group(2)):
return folder
elif len(folder_category.groups()) == 1:
if number == int(folder_category.group((1))):
return folder
return path
@XSH.builtins.events.on_transform_command
def jds_preproc(cmd: str, **kw):
"""processes command strings starting with "`" to cd to matching folder."""
if cmd.startswith("`") and "." in cmd:
jdn = cmd.replace("`", "")
bucket = find_category(int(jdn.split(".")[0]), HOME, r"(^\d0)-(\d9)")
category = find_category(int(jdn.split(".")[0]), bucket, r"^(\d\d)")
folder = find_category(int(jdn.split(".")[1]), category, r"^(\d\d)")
cmd = f"cd '{folder.resolve()}'"
elif cmd.startswith("`"):
jdn = cmd.replace("`", "")
if jdn == "\n":
return f"cd '{HOME.resolve()}'"
bucket = find_category(int(jdn.split(".")[0]), HOME, r"(^\d0)-(\d9)")
category = find_category(int(jdn.split(".")[0]), bucket, r"^(\d\d)")
cmd = f"cd '{category.resolve()}'"
return cmd

View File

@ -1,4 +1,4 @@
source xsh/functions.xsh
source ~/xsh/functions.xsh
def _debug():
if $XONSH_SHOW_TRACEBACK:

View File

@ -1,4 +1,4 @@
source xsh/exceptions.xsh
source ~/xsh/exceptions.xsh
def in_wsl() -> bool:
"""Determines if the system is running inside a WSL environment."""